cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
74 lines (73 loc) • 2.6 kB
JavaScript
import Geometry from "../../../../claygl/src/Geometry.mjs";
import "../../../../echarts/lib/echarts.mjs";
import dynamicConvertMixin from "./dynamicConvertMixin.mjs";
import glmatrix from "../../../../claygl/src/glmatrix/index.mjs";
import { defaults } from "../../../../zrender/lib/core/util.mjs";
var vec3 = glmatrix.vec3;
var QuadsGeometry = Geometry.extend(
function() {
return {
segmentScale: 1,
useNativeLine: true,
attributes: {
position: new Geometry.Attribute("position", "float", 3, "POSITION"),
normal: new Geometry.Attribute("normal", "float", 3, "NORMAL"),
color: new Geometry.Attribute("color", "float", 4, "COLOR")
}
};
},
{
resetOffset: function() {
this._vertexOffset = 0;
this._faceOffset = 0;
},
setQuadCount: function(nQuad) {
var attributes = this.attributes;
var vertexCount = this.getQuadVertexCount() * nQuad;
var triangleCount = this.getQuadTriangleCount() * nQuad;
if (this.vertexCount !== vertexCount) {
attributes.position.init(vertexCount);
attributes.normal.init(vertexCount);
attributes.color.init(vertexCount);
}
if (this.triangleCount !== triangleCount) {
this.indices = vertexCount > 65535 ? new Uint32Array(triangleCount * 3) : new Uint16Array(triangleCount * 3);
}
},
getQuadVertexCount: function() {
return 4;
},
getQuadTriangleCount: function() {
return 2;
},
addQuad: function() {
var a = vec3.create();
var b = vec3.create();
var normal = vec3.create();
var indices = [0, 3, 1, 3, 2, 1];
return function(coords, color) {
var positionAttr = this.attributes.position;
var normalAttr = this.attributes.normal;
var colorAttr = this.attributes.color;
vec3.sub(a, coords[1], coords[0]);
vec3.sub(b, coords[2], coords[1]);
vec3.cross(normal, a, b);
vec3.normalize(normal, normal);
for (var i = 0; i < 4; i++) {
positionAttr.set(this._vertexOffset + i, coords[i]);
colorAttr.set(this._vertexOffset + i, color);
normalAttr.set(this._vertexOffset + i, normal);
}
var idx = this._faceOffset * 3;
for (var i = 0; i < 6; i++) {
this.indices[idx + i] = indices[i] + this._vertexOffset;
}
this._vertexOffset += 4;
this._faceOffset += 2;
};
}()
}
);
defaults(QuadsGeometry.prototype, dynamicConvertMixin);
var QuadsGeometry$1 = QuadsGeometry;
export { QuadsGeometry$1 as default };