Three.js: wrong BoundingBox after scaling a geometry

泪湿孤枕 提交于 2019-12-23 21:36:50

问题


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);

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()));

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?


回答1:


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.

three.js. r.60



来源:https://stackoverflow.com/questions/18461480/three-js-wrong-boundingbox-after-scaling-a-geometry

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