UNPKG

@polygonjs/polygonjs

Version:

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

104 lines (103 loc) 3.09 kB
"use strict"; import { arrayPushItems } from "../../../ArrayUtils"; import { stringToIndices } from "../../../String"; import { AttribType } from "../../Constant"; import { coreVertexClassFactory, coreVertexInstanceFactory } from "../../CoreObjectFactory"; const _indices = []; const _tmpVertices = []; export function vertices(coreGroup, target) { const allObjects = coreGroup.allObjects(); target.length = 0; for (const object of allObjects) { verticesFromObject(object, _tmpVertices); arrayPushItems(_tmpVertices, target); } return target; } export function vertexAttribNamesFromCoreGroup(coreGroup) { const firstObject = coreGroup.allObjects()[0]; if (firstObject) { return vertexAttributeNames(firstObject); } else { return []; } } export function vertexAttribSizesFromCoreGroup(coreGroup) { const firstObject = coreGroup.allObjects()[0]; if (firstObject) { return vertexAttributeSizes(firstObject); } else { return {}; } } export function vertexAttribTypesFromCoreGroup(coreGroup) { const firstObject = coreGroup.allObjects()[0]; if (firstObject) { return vertexAttributeTypes(firstObject); } else { return {}; } } export function verticesCountFromObject(object) { const vertexClass = coreVertexClassFactory(object); return vertexClass.entitiesCount(object); } export function verticesFromObject(object, target) { const vertexClass = coreVertexClassFactory(object); const verticesCount = vertexClass.entitiesCount(object); target.length = verticesCount; for (let i = 0; i < verticesCount; i++) { target[i] = coreVertexInstanceFactory(object, i); } return target; } export function verticesFromObjectFromGroup(object, group, target) { if (group) { target.length = 0; stringToIndices(group, _indices); verticesFromObject(object, _tmpVertices); for (const index of _indices) { const vertex = _tmpVertices[index]; if (vertex) { target.push(vertex); } } return target; } else { return verticesFromObject(object, target); } } export function vertexAttributeNames(object) { const vertexClass = coreVertexClassFactory(object); const attributes = vertexClass.attributes(object); if (!attributes) { return []; } return Object.keys(attributes); } export function vertexAttributeSizes(object) { const vertexClass = coreVertexClassFactory(object); const attributes = vertexClass.attributes(object); if (!attributes) { return {}; } const attribNames = Object.keys(attributes); const h = {}; for (const attribName of attribNames) { h[attribName] = attributes[attribName].itemSize; } return h; } export function vertexAttributeTypes(object) { const vertexClass = coreVertexClassFactory(object); const attributes = vertexClass.attributes(object); if (!attributes) { return {}; } const attribNames = Object.keys(attributes); const h = {}; for (const attribName of attribNames) { h[attribName] = attributes[attribName].isString == true ? AttribType.STRING : AttribType.NUMERIC; } return h; }