cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
28 lines (27 loc) • 831 B
JavaScript
import { Vector3 } from "../../../build/three.module.mjs";
function reduceVertices(object, func, initialValue) {
let value = initialValue;
const vertex = new Vector3();
object.updateWorldMatrix(true, true);
object.traverseVisible((child) => {
const { geometry } = child;
if (geometry !== void 0) {
const { position } = geometry.attributes;
if (position !== void 0) {
for (let i = 0, l = position.count; i < l; i++) {
if (child.isMesh) {
child.getVertexPosition(i, vertex);
} else {
vertex.fromBufferAttribute(position, i);
}
if (!child.isSkinnedMesh) {
vertex.applyMatrix4(child.matrixWorld);
}
value = func(value, vertex);
}
}
}
});
return value;
}
export { reduceVertices };