Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

javascript - Any way to get a bounding box from a three.js Object3D?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

to get the bounding box of obj, including all of its children, and accounting for any translations, rotations, etc.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...