Scale object to fit inside certain bounding box three.js

北城余情 提交于 2019-12-12 21:47:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/47868151/scale-object-to-fit-inside-certain-bounding-box-three-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!