I need to adjust the scale of the imported GLB Model to match the size of a cube in my scene. This is necessary to ensure that the model remains within the shadow casting areas and is large enough to display the shadows effectively.
I have already determined the bounding boxes of both objects:
// shadowcasting area
var sceneExtent = new THREE.BoxGeometry( 4, 4, 4 );
var cube = new THREE.Mesh( sceneExtent, material );
var sceneBounds = sceneExtent.computeBoundingBox()
and
// imported mesh
model.traverse( function ( child ) {
if ( child.isMesh ) {
child.geometry.computeBoundingBox()
meshBounds = child.geometry.boundingBox
}
} );
However, I am unsure of how to use this information to adjust the scale
of the GLTF Model
// meshBounds = child.geometry.boundingBox
// sceneBounds = sceneExtent.computeBoundingBox()
// how to resize model scale to match size of sceneBounds
model.scale.set(1,1,1)
I have tried researching solutions, but I am struggling to find a clear answer.
Is there a way for me to adjust the model scale to match the sceneBounds
based on the provided information?
UPDATE: Use .setFromObject()
to obtain the bounding box:
sceneBounds = new THREE.Box3().setFromObject( cube );
meshBounds = new THREE.Box3().setFromObject( model );