p5
Version:
[](https://www.npmjs.com/package/p5)
97 lines (96 loc) • 2.42 kB
JavaScript
//#region src/webgl/p5.GeometryPart.js
/**
* @module Shape
* @submodule 3D Primitives
* @for p5
*/
function createPartState() {
return {
fill: null,
ambientColor: null,
specularColor: null,
shininess: null,
texture: null,
specularTexture: null,
ambientTexture: null,
shininessTexture: null,
normalTexture: null,
normalScale: 1,
normalMapMode: 0
};
}
function createUserVertexProperty(owner, propertyName, data, size) {
const prop = owner.userVertexProperties[propertyName] = {
name: propertyName,
dataSize: size ? size : data.length ? data.length : 1,
geometry: owner,
getName() {
return this.name;
},
getCurrentData() {
if (this.currentData === void 0) this.currentData = new Array(this.getDataSize()).fill(0);
return this.currentData;
},
getDataSize() {
return this.dataSize;
},
getSrcName() {
return this.name.concat("Src");
},
getDstName() {
return this.name.concat("Buffer");
},
getSrcArray() {
return this.geometry[this.getSrcName()];
},
setCurrentData(data) {
this.currentData = data;
},
pushCurrentData() {
this.pushDirect(this.getCurrentData());
},
pushDirect(data) {
if (data.length) this.getSrcArray().push(...data);
else this.getSrcArray().push(data);
},
resetSrcArray() {
this.geometry[this.getSrcName()] = [];
},
delete() {
delete this.geometry[this.getSrcName()];
}
};
owner[prop.getSrcName()] = [];
return owner.userVertexProperties[propertyName];
}
var GeometryPart = class {
constructor(gid, partState) {
this.gid = gid;
this.vertices = [];
this.vertexNormals = [];
this.vertexTangents = [];
this.faces = [];
this.uvs = [];
this.vertexColors = [];
this.partState = partState || createPartState();
this.dirtyFlags = {};
this.userVertexProperties = {};
}
vertexProperty(propertyName, data, size) {
let prop = this.userVertexProperties[propertyName];
if (!prop) prop = createUserVertexProperty(this, propertyName, data, size);
if (size) prop.pushDirect(data);
else {
prop.setCurrentData(data);
prop.pushCurrentData();
}
}
hasFillTransparency() {
const fill = this.partState && this.partState.fill;
if (fill && fill[3] < 1) return true;
for (let i = 3; i < this.vertexColors.length; i += 4) if (this.vertexColors[i] < 1) return true;
return false;
}
};
//#endregion
export { GeometryPart, createPartState, createUserVertexProperty };