UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

99 lines (98 loc) 2.64 kB
"use strict"; import { CoreVertex } from "../../entities/vertex/CoreVertex"; import { verticesCountFromObject } from "../../entities/vertex/CoreVertexUtils"; import { attributeNumericValues } from "../../entities/utils/Common"; import { QuadPoint } from "./QuadPoint"; import { QuadPrimitive } from "./QuadPrimitive"; const target = { attributeAdded: false, values: [] }; export class QuadVertex extends CoreVertex { constructor(object, index) { super(object, index); this._geometry = object.geometry; } setIndex(index, object) { this._index = index; if (object) { this._object = object; this._updateGeometry(); } return this; } _updateGeometry() { const geometry = this._object.geometry; if (geometry) { this._geometry = geometry; } } geometry() { return this._geometry; } static addAttribute(object, attribName, attribute) { const attributes = this.attributes(object); if (!attributes) { return; } attributes[attribName] = attribute; } static addNumericAttribute(object, attribName, size = 1, defaultValue = 0) { const verticesCount = this.entitiesCount(object); target.values = new Array(verticesCount * size); attributeNumericValues(object, verticesCountFromObject, size, defaultValue, target); const attribute = { isString: false, array: target.values, itemSize: size }; this.addAttribute(object, attribName, attribute); } static entitiesCount(object) { return object.geometry.index.length; } static attributes(object) { const geometry = object.geometry; if (!geometry) { return; } if (!geometry.userData.vertexAttributes) { geometry.userData.vertexAttributes = {}; } return geometry.userData.vertexAttributes; } position(target2) { console.warn("QuadVertex.position not implemented"); return target2; } normal(target2) { console.warn("QuadVertex.normal not implemented"); return target2; } // // // RELATED ENTITIES // // static relatedPrimitiveIds(object, vertexIndex, target2) { target2.length = 1; const index = Math.floor(vertexIndex / 4); target2[0] = index; } static relatedPointIds(object, vertexIndex, target2) { target2.length = 0; const geometry = object.geometry; if (!geometry) { return; } const indexArray = geometry.index; const indexValue = indexArray[vertexIndex]; target2[0] = indexValue; } static relatedPointClass(object) { return QuadPoint; } static relatedPrimitiveClass(object) { return QuadPrimitive; } }