Three.js:缩放几何体后错误的 BoundingBox [英] Three.js: wrong BoundingBox after scaling a geometry

查看:113
本文介绍了Three.js:缩放几何体后错误的 BoundingBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的场景中,我有一个简单的立方体:

In my scene I have a simple cube:

var test = new THREE.Mesh(new THREE.CubeGeometry(10,10,10), new THREE.MeshBasicMaterial());
scene.add(test);

这个立方体通过THREE.TransformControls 被用户遍历/缩放.我需要的是这些交互后立方体的边界框.所以我在做

This cube is getting traversed/scaled through the user with THREE.TransformControls. What I need is the boundingbox of the cube after these interactions. So I'm doing

test.geometry.computeBoundingBox();
var bb = test.geometry.boundingBox;
bb.translate(test.localToWorld( new THREE.Vector3()));

但我总是得到一个错误的边界框!翻译计算正确,但不是比例.boundingbox 的宽度和高度总是 10 ...

But I always get a wrong boundingbox! The translation is computed correct, but not the scale. The width and heigth of the boundingbox is always 10 ...

这是错误还是功能?如何获得立方体的正确边界框?

Is this a bug or feature? How do I get the correct boundingbox of my cube?

推荐答案

您可以像这样计算对象(包括其子对象)的世界轴对齐边界框:

You can compute the world-axis-aligned bounding box of an object (including its children) like so:

var box = new THREE.Box3();
box.setFromObject( object );

查看源代码,了解它在做什么.

Have a look at the source code so you understand what it is doing.

三个.js.r.60

这篇关于Three.js:缩放几何体后错误的 BoundingBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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