UNPKG

@polygonjs/polygonjs

Version:

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

137 lines (136 loc) 4.12 kB
"use strict"; import { arrayCompact, arrayPushItems } from "../../../ArrayUtils"; import { CoreString } from "../../../String"; import { AttribType } from "../../Constant"; import { corePointClassFactory, corePointInstanceFactory } from "../../CoreObjectFactory"; const _indices = []; const _tmpPoints = []; export function pointsFromCoreGroup(coreGroup, target) { return pointsFromObjects(coreGroup.allObjects(), target); } export function pointsFromCoreObjects(coreObjects, target) { target.length = 0; for (const coreObject of coreObjects) { pointsFromObject(coreObject.object(), _tmpPoints); arrayPushItems(_tmpPoints, target); } return target; } export function pointsFromObjects(objects, target) { target.length = 0; for (const object of objects) { pointsFromObject(object, _tmpPoints); arrayPushItems(_tmpPoints, target); } return target; } export function pointsAttribNamesFromCoreGroup(coreGroup) { const firstObject = coreGroup.allObjects()[0]; if (firstObject) { return pointAttributeNames(firstObject); } else { return []; } } export function pointAttribSizesFromCoreGroup(coreGroup) { const firstObject = coreGroup.allObjects()[0]; if (firstObject) { return pointAttributeSizes(firstObject); } else { return {}; } } export function pointAttribTypesFromCoreGroup(coreGroup) { const firstObject = coreGroup.allObjects()[0]; if (firstObject) { return pointAttributeTypes(firstObject); } else { return {}; } } export function pointsCountFromObject(object) { const pointClass = corePointClassFactory(object); return pointClass.entitiesCount(object); } export function pointsFromObject(object, target) { const pointClass = corePointClassFactory(object); const pointsCount = pointClass.entitiesCount(object); target.length = pointsCount; for (let i = 0; i < pointsCount; i++) { target[i] = corePointInstanceFactory(object, i); } return target; } export function pointsFromObjectFromGroup(object, group, target) { if (group) { CoreString.indices(group, _indices); const points = pointsFromObject(object, _tmpPoints); const compactPoints = []; const selectedPoints = arrayCompact( _indices.map((i) => points[i]), compactPoints ); target.length = 0; arrayPushItems(selectedPoints, target); } else { pointsFromObject(object, target); } } export function hasPointAttribute(object, attribName) { const pointClass = corePointClassFactory(object); const attributes = pointClass.attributes(object); if (!attributes) { return false; } return attribName in attributes; } export function pointAttributeNames(object) { const pointClass = corePointClassFactory(object); const attributes = pointClass.attributes(object); if (!attributes) { return []; } return Object.keys(attributes); } export function pointAttributeSize(object, attribName) { const pointClass = corePointClassFactory(object); const attributes = pointClass.attributes(object); if (!attributes) { return 0; } return attributes[attribName].itemSize; } export function pointAttributeSizes(object) { const pointClass = corePointClassFactory(object); const attributes = pointClass.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 pointAttributeType(object, attribName) { const pointClass = corePointClassFactory(object); const attributes = pointClass.attributes(object); if (!attributes) { return AttribType.NUMERIC; } return pointClass.attribType(object, attribName); } export function pointAttributeTypes(object) { const pointClass = corePointClassFactory(object); const attributes = pointClass.attributes(object); if (!attributes) { return {}; } const attribNames = Object.keys(attributes); const h = {}; for (const attribName of attribNames) { h[attribName] = pointClass.attribType(object, attribName); } return h; }