Reputation: 7332
Is there a build-way one-liner in three-js to add object to 'bottom' of the scene - with z = 0 corresponding to the bottom of the object (the bottom of the object's bounding box) instead of default's object centered in origin?
I know we can achieve this by adding the half of bbox's height to the position like:
const addToBottom = (scene: Three.Scene, object: Three.Object3D) => {
const bbox = new Three.Box3();
bbox.setFromObject(object);
scene.add(object)
object.position.z += (bbox.max.z - bbox.min.z) / 2
}
Upvotes: 1
Views: 675
Reputation: 17586
One-liner can be like that:
object.position.z += new THREE.Box3().setFromObject(object).getSize().z * 0.5;
Upvotes: 1