@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
29 lines (28 loc) • 1.12 kB
JavaScript
;
import { BufferGeometry, Float32BufferAttribute, Vector3 } from "three";
import { ObjectType } from "../../../Constant";
import { BaseSopOperation } from "../../../../../engine/operations/sop/_Base";
import { tetCircumCenter } from "../utils/tetCenter";
const _center = new Vector3();
const _p = new Vector3();
export function tetToCenter(tetGeometry, tesselationParams) {
const { tetrahedrons } = tetGeometry;
const newGeometry = new BufferGeometry();
const positions = new Array(tetGeometry.tetsCount() * 1 * 3);
const indices = new Array(tetGeometry.tetsCount() * 1);
let positionsCount = 0;
let indicesCount = 0;
let indexCount = 0;
tetrahedrons.forEach((tet) => {
tetCircumCenter(tetGeometry, tet.id, _center);
indices[indicesCount] = indexCount;
_p.copy(_center);
_p.toArray(positions, positionsCount);
positionsCount += 3;
indicesCount += 1;
indexCount += 1;
});
newGeometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
newGeometry.setIndex(indices);
return BaseSopOperation.createObject(newGeometry, ObjectType.POINTS);
}