UNPKG

lingo3d

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

39 lines 1.39 kB
import { Box3, SkinnedMesh, Vector3 } from "three"; import { box3, vector3 } from "../display/utils/reusables"; import computeOnceWithData from "./utils/computeOnceWithData"; const _box = new Box3(); const expandByObject = (object) => { object.updateMatrixWorld(); const { geometry } = object; if (geometry) { if (object instanceof SkinnedMesh) { const position = geometry.attributes.position; for (let i = 0, il = position.count; i < il; i++) { vector3.fromBufferAttribute(position, i); object.boneTransform(i, vector3); object.localToWorld(vector3); box3.expandByPoint(vector3); } } else { if (geometry.boundingBox === null) geometry.computeBoundingBox(); _box.copy(geometry.boundingBox); _box.applyMatrix4(object.matrixWorld); box3.union(_box); } } const children = object.children; for (let i = 0, l = children.length; i < l; i++) expandByObject(children[i]); }; export const measure = computeOnceWithData((_, data) => { const size = new Vector3(); const center = new Vector3(); box3.makeEmpty(); expandByObject(data.target); box3.getSize(size); box3.getCenter(center); return [size, center]; }); //# sourceMappingURL=measure.js.map