Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale object to fit inside certain bounding box three.js

Tags:

three.js

In my project i am loading different kinds of model dynamically. How to scale the loaded object so that it fits completely inside a certain bounding box?

To clarify the situation, i do not want the loaded object to fit in my FOV. I already have a house loaded in my scene. I want the new loaded object to fit inside my house.

like image 325
Md. Mahmudur Rahman Avatar asked Sep 18 '25 04:09

Md. Mahmudur Rahman


1 Answers

Since you do have the bounding box of the house (call it boxH) and the bounding box of the object (call it boxO), take the ratios of the bounding box sizes

var sizeH = boxH.getSize(); // get the size of the bounding box of the house
var sizeO = boxO.getSize(); // get the size of the bounding box of the obj

var ratio = sizeH.divide( sizeO ); // get the ratio of the sizes

Now scale() your object by the inverse maximum value in the ratio variable.

like image 73
gaitat Avatar answered Sep 23 '25 09:09

gaitat