UNPKG

@polygonjs/polygonjs

Version:

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

29 lines (28 loc) 1.29 kB
"use strict"; import { BufferGeometry, Float32BufferAttribute } from "three"; import { ObjectType } from "../../../Constant"; import { BaseSopOperation } from "../../../../../engine/operations/sop/_Base"; import { tetSortPoints } from "../utils/tetSortPoints"; import { Attribute } from "../../../Attribute"; export function tetToPoints(tetGeometry, tesselationParams) { const { points } = tetGeometry; const newGeometry = new BufferGeometry(); const pointIndexById = /* @__PURE__ */ new Map(); tetSortPoints(tetGeometry, pointIndexById); const positions = new Array(tetGeometry.pointsCount() * 1 * 3); const ids = new Array(tetGeometry.pointsCount() * 1); const indices = new Array(tetGeometry.pointsCount() * 1); points.forEach((point) => { const pointIndex = pointIndexById.get(point.id); if (pointIndex == null) { throw "pointIndex is null"; } point.position.toArray(positions, pointIndex * 3); ids[pointIndex] = pointIndex; indices[pointIndex] = pointIndex; }); newGeometry.setAttribute(Attribute.POSITION, new Float32BufferAttribute(positions, 3)); newGeometry.setAttribute(Attribute.ID, new Float32BufferAttribute(ids, 1)); newGeometry.setIndex(indices); return BaseSopOperation.createObject(newGeometry, ObjectType.POINTS); }