有什么方法可以从three.js Object3D 中获取边界框? [英] Any way to get a bounding box from a three.js Object3D?
问题描述
我正在使用 Three.js 和 OBJLoader.js 加载 OBJ 文件.这将返回一个 Three.Object3D 对象,它具有您对 3D 模型的期望(位置向量、向上向量...)
I'm loading an OBJ file using Three.js and OBJLoader.js. This returns a Three.Object3D object, which has what you'd expect from a 3D model (position vector, up vector...)
我不知道如何获得它的边界框——这可能吗?
What I can't figure out is how to get a bounding box for it-- is this possible?
推荐答案
您不需要遍历对象的所有子项;库中有一个方法可以做到这一点:THREE.Box3#setFromObject
: 查看文档.例如,您可以这样做:
You don't need to iterate over all children of the object; there's a method in the library to do this: THREE.Box3#setFromObject
: see the docs. For example, you can do:
var bbox = new THREE.Box3().setFromObject(obj);
获取obj
的边界框,包括它的所有子元素,并考虑任何平移、旋转等.
to get the bounding box of obj
, including all of its children, and accounting for any translations, rotations, etc.
请注意,BoundingBox
助手旨在在场景中绘制边界框,而不仅仅是计算某个对象的边界框.
Note that the BoundingBox
helper is intended to draw a bounding box in the scene, not for just calculating the bounding box of some object.
这篇关于有什么方法可以从three.js Object3D 中获取边界框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!