UNPKG

@polygonjs/polygonjs

Version:

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

43 lines (42 loc) 1.35 kB
"use strict"; import { BufferAttribute } from "three"; import { isObject3D } from "./ObjectContent"; import { isQuadObject } from "./modules/quad/QuadCoreType"; import { InstanceAttrib } from "./Instancer"; export function bufferGeometryMaxGroupEnd(geometry) { const groups = geometry.groups; let max = -1; for (const group of groups) { const groupEnd = group.start + group.count; if (groupEnd > max) { max = groupEnd; } } return max; } export function truncateBufferGeometry(geometry, maxCount) { const attributeNames = Object.keys(geometry.attributes); for (const attributeName of attributeNames) { const attribute = geometry.getAttribute(attributeName); const originalArray = attribute.array; const itemSize = attribute.itemSize; const expectedArraySize = maxCount * itemSize; const newArray = originalArray.slice(0, expectedArraySize); geometry.setAttribute(attributeName, new BufferAttribute(new Float32Array(newArray), itemSize)); } } export function object3DHasGeometry(o) { return o.geometry != null; } export function objectContentHasGeometry(o) { if (isQuadObject(o)) { return true; } if (isObject3D(o)) { return o.geometry != null; } return false; } export function markedAsInstance(geometry) { return geometry.getAttribute(InstanceAttrib.POSITION) != null; }