缩放对象以适合特定边界框 Three.js [英] Scale object to fit inside certain bounding box three.js

查看:28
本文介绍了缩放对象以适合特定边界框 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?

为了澄清这种情况,我不希望加载的对象适合我的 FOV.我的场景中已经加载了一座房子.我希望新加载的对象适合我的房子.

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.

推荐答案

既然你有房子的边界框(称之为 boxH)和物体的边界框(称之为 boxO),那么取边界框大小

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

现在 scale() 你的对象通过 ratio 变量中的倒数最大值.

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

这篇关于缩放对象以适合特定边界框 Three.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆