bytev-charts-beta
Version:
基于echarts和JavaScript及ES6封装的一个可以直接调用的图表组件库,内置主题设计,简单快捷,且支持用户自定义配置; npm 安装方式: npm install bytev-charts 若启动提示还需额外install插件,则运行 npm install @babel/runtime-corejs2 即可;
371 lines (325 loc) • 14.4 kB
JavaScript
import "core-js/modules/es.array.slice.js";
import "core-js/modules/es.regexp.exec.js";
import _classCallCheck from "@babel/runtime-corejs2/helpers/classCallCheck";
import _createClass from "@babel/runtime-corejs2/helpers/createClass";
import "core-js/modules/es.function.name.js";
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.float32-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";
import "core-js/modules/es.array-buffer.constructor.js";
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof _Symbol !== "undefined" && o[_Symbol$iterator] || o["@@iterator"]; if (!it) { if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return _Array$from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
import _WeakMap from "@babel/runtime-corejs2/core-js/weak-map";
import _Map from "@babel/runtime-corejs2/core-js/map";
import _Array$from from "@babel/runtime-corejs2/core-js/array/from";
import _Symbol from "@babel/runtime-corejs2/core-js/symbol";
import _Symbol$iterator from "@babel/runtime-corejs2/core-js/symbol/iterator";
import _Array$isArray from "@babel/runtime-corejs2/core-js/array/is-array";
import WebGPUUniformsGroup from './WebGPUUniformsGroup.js';
import WebGPUSampler from './WebGPUSampler.js';
import WebGPUSampledTexture from './WebGPUSampledTexture.js';
import { Matrix4 } from '../../../../build/three.module.js';
var WebGPUBindings = /*#__PURE__*/function () {
function WebGPUBindings(device, info, properties, textures) {
_classCallCheck(this, WebGPUBindings);
this.device = device;
this.info = info;
this.properties = properties;
this.textures = textures;
this.uniformsData = new _WeakMap();
this.sharedUniformsGroups = new _Map();
this.updateMap = new _WeakMap();
this._setupSharedUniformsGroups();
}
_createClass(WebGPUBindings, [{
key: "get",
value: function get(object) {
var data = this.uniformsData.get(object);
if (data === undefined) {
var material = object.material;
var bindings; // each material defines an array of bindings (ubos, textures, samplers etc.)
if (material.isMeshBasicMaterial) {
bindings = this._getMeshBasicBindings();
} else if (material.isPointsMaterial) {
bindings = this._getPointsBasicBindings();
} else if (material.isLineBasicMaterial) {
bindings = this._getLinesBasicBindings();
} else {
console.error('THREE.WebGPURenderer: Unknwon shader type.');
} // setup (static) binding layout and (dynamic) binding group
var bindLayout = this._createBindLayout(bindings);
var bindGroup = this._createBindGroup(bindings, bindLayout);
data = {
layout: bindLayout,
group: bindGroup,
bindings: bindings
};
this.uniformsData.set(object, data);
}
return data;
}
}, {
key: "update",
value: function update(object, camera) {
var textures = this.textures;
var data = this.get(object);
var bindings = data.bindings;
var updateMap = this.updateMap;
var frame = this.info.render.frame;
var sharedUniformsGroups = this.sharedUniformsGroups;
var needsBindGroupRefresh = false; // iterate over all bindings and check if buffer updates or a new binding group is required
var _iterator = _createForOfIteratorHelper(bindings),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var binding = _step.value;
if (binding.isUniformsGroup) {
var isShared = sharedUniformsGroups.has(binding.name);
var isUpdated = updateMap.get(binding) === frame;
if (isShared && isUpdated) continue;
var array = binding.array;
var bufferGPU = binding.bufferGPU;
var needsBufferWrite = binding.update(array, object, camera);
if (needsBufferWrite === true) {
this.device.defaultQueue.writeBuffer(bufferGPU, 0, array, 0);
}
updateMap.set(binding, frame);
} else if (binding.isSampler) {
var material = object.material;
var texture = material[binding.name];
textures.updateSampler(texture);
var samplerGPU = textures.getSampler(texture);
if (binding.samplerGPU !== samplerGPU) {
binding.samplerGPU = samplerGPU;
needsBindGroupRefresh = true;
}
} else if (binding.isSampledTexture) {
var _material = object.material;
var _texture = _material[binding.name];
var forceUpdate = textures.updateTexture(_texture);
var textureGPU = textures.getTextureGPU(_texture);
if (binding.textureGPU !== textureGPU || forceUpdate === true) {
binding.textureGPU = textureGPU;
needsBindGroupRefresh = true;
}
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
if (needsBindGroupRefresh === true) {
data.group = this._createBindGroup(bindings, data.layout);
}
}
}, {
key: "dispose",
value: function dispose() {
this.uniformsData = new _WeakMap();
this.updateMap = new _WeakMap();
}
}, {
key: "_createBindLayout",
value: function _createBindLayout(bindings) {
var bindingPoint = 0;
var entries = [];
var _iterator2 = _createForOfIteratorHelper(bindings),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var binding = _step2.value;
entries.push({
binding: bindingPoint,
visibility: binding.visibility,
type: binding.type
});
bindingPoint++;
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
return this.device.createBindGroupLayout({
entries: entries
});
}
}, {
key: "_createBindGroup",
value: function _createBindGroup(bindings, layout) {
var bindingPoint = 0;
var entries = [];
var _iterator3 = _createForOfIteratorHelper(bindings),
_step3;
try {
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
var binding = _step3.value;
if (binding.isUniformsGroup) {
if (binding.bufferGPU === null) {
var byteLength = binding.getByteLength();
binding.array = new Float32Array(new ArrayBuffer(byteLength));
binding.bufferGPU = this.device.createBuffer({
size: byteLength,
usage: binding.usage
});
}
entries.push({
binding: bindingPoint,
resource: {
buffer: binding.bufferGPU
}
});
} else if (binding.isSampler) {
if (binding.samplerGPU === null) {
binding.samplerGPU = this.textures.getDefaultSampler();
}
entries.push({
binding: bindingPoint,
resource: binding.samplerGPU
});
} else if (binding.isSampledTexture) {
if (binding.textureGPU === null) {
binding.textureGPU = this.textures.getDefaultTexture();
}
entries.push({
binding: bindingPoint,
resource: binding.textureGPU.createView()
});
}
bindingPoint++;
}
} catch (err) {
_iterator3.e(err);
} finally {
_iterator3.f();
}
return this.device.createBindGroup({
layout: layout,
entries: entries
});
}
}, {
key: "_getMeshBasicBindings",
value: function _getMeshBasicBindings() {
var bindings = []; // ubos
var modelGroup = new WebGPUUniformsGroup();
modelGroup.setName('modelUniforms');
modelGroup.setUniform('modelMatrix', new Matrix4());
modelGroup.setUniform('modelViewMatrix', new Matrix4());
modelGroup.setUpdateCallback(function (array, object
/*, camera */
) {
array.set(object.matrixWorld.elements, 0);
array.set(object.modelViewMatrix.elements, 16);
return true; // @TODO: Implement caching (return false when cache hits occurs)
});
var cameraGroup = this.sharedUniformsGroups.get('cameraUniforms');
var opacityGroup = new WebGPUUniformsGroup();
opacityGroup.setName('opacityUniforms');
opacityGroup.setUniform('opacity', 1.0);
opacityGroup.visibility = GPUShaderStage.FRAGMENT;
opacityGroup.setUpdateCallback(function (array, object) {
var material = object.material;
var opacity = material.transparent ? material.opacity : 1.0;
var updated = false;
if (array[0] !== opacity) {
array[0] = opacity;
updated = true;
}
return updated;
}); // samplers
var diffuseSampler = new WebGPUSampler();
diffuseSampler.setName('map'); // textures
var diffuseTexture = new WebGPUSampledTexture();
diffuseTexture.setName('map'); //
bindings.push(modelGroup);
bindings.push(cameraGroup);
bindings.push(opacityGroup);
bindings.push(diffuseSampler);
bindings.push(diffuseTexture);
return bindings;
}
}, {
key: "_getPointsBasicBindings",
value: function _getPointsBasicBindings() {
var bindings = []; // ubos
var modelGroup = new WebGPUUniformsGroup();
modelGroup.setName('modelUniforms');
modelGroup.setUniform('modelMatrix', new Matrix4());
modelGroup.setUniform('modelViewMatrix', new Matrix4());
modelGroup.setUpdateCallback(function (array, object
/*, camera */
) {
array.set(object.matrixWorld.elements, 0);
array.set(object.modelViewMatrix.elements, 16);
return true; // @TODO: Implement caching (return false when cache hits occurs)
});
var cameraGroup = this.sharedUniformsGroups.get('cameraUniforms'); //
bindings.push(modelGroup);
bindings.push(cameraGroup);
return bindings;
}
}, {
key: "_getLinesBasicBindings",
value: function _getLinesBasicBindings() {
var bindings = []; // ubos
var modelGroup = new WebGPUUniformsGroup();
modelGroup.setName('modelUniforms');
modelGroup.setUniform('modelMatrix', new Matrix4());
modelGroup.setUniform('modelViewMatrix', new Matrix4());
modelGroup.setUpdateCallback(function (array, object
/*, camera */
) {
array.set(object.matrixWorld.elements, 0);
array.set(object.modelViewMatrix.elements, 16);
return true; // @TODO: Implement caching (return false when cache hits occurs)
});
var cameraGroup = this.sharedUniformsGroups.get('cameraUniforms'); //
bindings.push(modelGroup);
bindings.push(cameraGroup);
return bindings;
}
}, {
key: "_setupSharedUniformsGroups",
value: function _setupSharedUniformsGroups() {
var cameraGroup = new WebGPUUniformsGroup();
cameraGroup.setName('cameraUniforms');
cameraGroup.setUniform('projectionMatrix', new Matrix4());
cameraGroup.setUniform('viewMatrix', new Matrix4());
cameraGroup.setUpdateCallback(function (array, object, camera) {
array.set(camera.projectionMatrix.elements, 0);
array.set(camera.matrixWorldInverse.elements, 16);
return true; // @TODO: Implement caching (return false when cache hits occurs)
});
this.sharedUniformsGroups.set(cameraGroup.name, cameraGroup);
}
}]);
return WebGPUBindings;
}();
export default WebGPUBindings;