UNPKG

bytev-charts

Version:

基于echarts和JavaScript及ES6封装的一个可以直接调用的图表组件库,内置主题设计,简单快捷,且支持用户自定义配置; npm 安装方式: npm install bytev-charts 若启动提示还需额外install插件,则运行 npm install @babel/runtime-corejs2 即可;

225 lines (181 loc) 7.65 kB
import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.array-buffer.slice.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.typed-array.uint8-array.js"; import "core-js/modules/es.typed-array.copy-within.js"; import "core-js/modules/es.typed-array.every.js"; import "core-js/modules/es.typed-array.fill.js"; import "core-js/modules/es.typed-array.filter.js"; import "core-js/modules/es.typed-array.find.js"; import "core-js/modules/es.typed-array.find-index.js"; import "core-js/modules/es.typed-array.for-each.js"; import "core-js/modules/es.typed-array.includes.js"; import "core-js/modules/es.typed-array.index-of.js"; import "core-js/modules/es.typed-array.iterator.js"; import "core-js/modules/es.typed-array.join.js"; import "core-js/modules/es.typed-array.last-index-of.js"; import "core-js/modules/es.typed-array.map.js"; import "core-js/modules/es.typed-array.reduce.js"; import "core-js/modules/es.typed-array.reduce-right.js"; import "core-js/modules/es.typed-array.reverse.js"; import "core-js/modules/es.typed-array.set.js"; import "core-js/modules/es.typed-array.slice.js"; import "core-js/modules/es.typed-array.some.js"; import "core-js/modules/es.typed-array.sort.js"; import "core-js/modules/es.typed-array.subarray.js"; import "core-js/modules/es.typed-array.to-locale-string.js"; import "core-js/modules/es.typed-array.to-string.js"; console.warn("THREE.LightProbeGenerator: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation."); THREE.LightProbeGenerator = { // https://www.ppsloan.org/publications/StupidSH36.pdf fromCubeTexture: function fromCubeTexture(cubeTexture) { var norm, lengthSq, weight, totalWeight = 0; var coord = new THREE.Vector3(); var dir = new THREE.Vector3(); var color = new THREE.Color(); var shBasis = [0, 0, 0, 0, 0, 0, 0, 0, 0]; var sh = new THREE.SphericalHarmonics3(); var shCoefficients = sh.coefficients; for (var faceIndex = 0; faceIndex < 6; faceIndex++) { var image = cubeTexture.image[faceIndex]; var width = image.width; var height = image.height; var canvas = document.createElement('canvas'); canvas.width = width; canvas.height = height; var context = canvas.getContext('2d'); context.drawImage(image, 0, 0, width, height); var imageData = context.getImageData(0, 0, width, height); var data = imageData.data; var imageWidth = imageData.width; // assumed to be square var pixelSize = 2 / imageWidth; for (var i = 0, il = data.length; i < il; i += 4) { // RGBA assumed // pixel color color.setRGB(data[i] / 255, data[i + 1] / 255, data[i + 2] / 255); // convert to linear color space convertColorToLinear(color, cubeTexture.encoding); // pixel coordinate on unit cube var pixelIndex = i / 4; var col = -1 + (pixelIndex % imageWidth + 0.5) * pixelSize; var row = 1 - (Math.floor(pixelIndex / imageWidth) + 0.5) * pixelSize; switch (faceIndex) { case 0: coord.set(-1, row, -col); break; case 1: coord.set(1, row, col); break; case 2: coord.set(-col, 1, -row); break; case 3: coord.set(-col, -1, row); break; case 4: coord.set(-col, row, 1); break; case 5: coord.set(col, row, -1); break; } // weight assigned to this pixel lengthSq = coord.lengthSq(); weight = 4 / (Math.sqrt(lengthSq) * lengthSq); totalWeight += weight; // direction vector to this pixel dir.copy(coord).normalize(); // evaluate SH basis functions in direction dir THREE.SphericalHarmonics3.getBasisAt(dir, shBasis); // accummuulate for (var j = 0; j < 9; j++) { shCoefficients[j].x += shBasis[j] * color.r * weight; shCoefficients[j].y += shBasis[j] * color.g * weight; shCoefficients[j].z += shBasis[j] * color.b * weight; } } } // normalize norm = 4 * Math.PI / totalWeight; for (var j = 0; j < 9; j++) { shCoefficients[j].x *= norm; shCoefficients[j].y *= norm; shCoefficients[j].z *= norm; } return new THREE.LightProbe(sh); }, fromCubeRenderTarget: function fromCubeRenderTarget(renderer, cubeRenderTarget) { // The renderTarget must be set to RGBA in order to make readRenderTargetPixels works var norm, lengthSq, weight, totalWeight = 0; var coord = new THREE.Vector3(); var dir = new THREE.Vector3(); var color = new THREE.Color(); var shBasis = [0, 0, 0, 0, 0, 0, 0, 0, 0]; var sh = new THREE.SphericalHarmonics3(); var shCoefficients = sh.coefficients; for (var faceIndex = 0; faceIndex < 6; faceIndex++) { var imageWidth = cubeRenderTarget.width; // assumed to be square var data = new Uint8Array(imageWidth * imageWidth * 4); renderer.readRenderTargetPixels(cubeRenderTarget, 0, 0, imageWidth, imageWidth, data, faceIndex); var pixelSize = 2 / imageWidth; for (var i = 0, il = data.length; i < il; i += 4) { // RGBA assumed // pixel color color.setRGB(data[i] / 255, data[i + 1] / 255, data[i + 2] / 255); // convert to linear color space convertColorToLinear(color, cubeRenderTarget.texture.encoding); // pixel coordinate on unit cube var pixelIndex = i / 4; var col = -1 + (pixelIndex % imageWidth + 0.5) * pixelSize; var row = 1 - (Math.floor(pixelIndex / imageWidth) + 0.5) * pixelSize; switch (faceIndex) { case 0: coord.set(1, row, -col); break; case 1: coord.set(-1, row, col); break; case 2: coord.set(col, 1, -row); break; case 3: coord.set(col, -1, row); break; case 4: coord.set(col, row, 1); break; case 5: coord.set(-col, row, -1); break; } // weight assigned to this pixel lengthSq = coord.lengthSq(); weight = 4 / (Math.sqrt(lengthSq) * lengthSq); totalWeight += weight; // direction vector to this pixel dir.copy(coord).normalize(); // evaluate SH basis functions in direction dir THREE.SphericalHarmonics3.getBasisAt(dir, shBasis); // accummuulate for (var j = 0; j < 9; j++) { shCoefficients[j].x += shBasis[j] * color.r * weight; shCoefficients[j].y += shBasis[j] * color.g * weight; shCoefficients[j].z += shBasis[j] * color.b * weight; } } } // normalize norm = 4 * Math.PI / totalWeight; for (var j = 0; j < 9; j++) { shCoefficients[j].x *= norm; shCoefficients[j].y *= norm; shCoefficients[j].z *= norm; } return new THREE.LightProbe(sh); } }; var convertColorToLinear = function convertColorToLinear(color, encoding) { switch (encoding) { case THREE.sRGBEncoding: color.convertSRGBToLinear(); break; case THREE.LinearEncoding: break; default: console.warn('WARNING: LightProbeGenerator convertColorToLinear() encountered an unsupported encoding.'); break; } return color; };