UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

32 lines (23 loc) 924 B
import { BufferAttribute } from "three"; import { UintArrayForCount } from "../../../../core/collection/array/typed/uint_array_for_count.js"; /** * * @param {THREE.BufferGeometry} geometry * @return {THREE.BufferGeometry} */ export function makeGeometryIndexed(geometry) { let index_attribute = geometry.getIndex(); if (index_attribute === null || index_attribute === undefined) { const position_attribute = geometry.getAttribute('position'); // non-indexed geometry, build index const size = position_attribute.count; const UintArrayConstructor = UintArrayForCount(size); const array = new UintArrayConstructor(size); for (let i = 0; i < size; i++) { array[i] = i; } index_attribute = new BufferAttribute(array, 1, false); geometry.setIndex(index_attribute); } return geometry; }