Need `Box3.setFromObject` to return an AABB in local space of specified object.
See original GitHub issueWhen I use Box3.setFromObject
to compute the bounding box of the an Object3D
, I was expecting it to return the AABB in local coordinates aligned to the local frame within the specified object, but instead it returns an AABB in world coordinates. I was wondering if would be good to add an option to this function to allow either local or world AABB to be returned?
I made a wrapper function that implements this option by temporarily setting the local matrix to the inverse of the worldMatrix of its parent object, but it seems like a messy and inefficient solution.
public getBounds(coords: CoordinateSystem): Box3 {
this._object3D.updateMatrix();
let oldMatrix = this._object3D.matrix;
let oldMatrixAutoUpdate = this._object3D.matrixAutoUpdate;
if (coords === CoordinateSystem.LOCAL) {
this.updateMatrixWorld();
let m = new Matrix4();
if (this.getParent() !== null)
{
m.getInverse(this._object3D.parent.matrixWorld, false);
}
this._object3D.matrix = m;
// to prevent matrix being reassigned
this._object3D.matrixAutoUpdate = false;
this.updateMatrixWorld();
}
var bounds = new Box3();
bounds.setFromObject(this._object3D);
if (coords === CoordinateSystem.LOCAL) {
this._object3D.matrix = oldMatrix;
this._object3D.matrixAutoUpdate = oldMatrixAutoUpdate;
this.updateMatrixWorld();
}
return bounds;
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:22 (4 by maintainers)
Top Results From Across the Web
setFromObject to align with the object, not the world - Questions
Need `Box3.setFromObject` to return an AABB in local space of specified object. ... When I use Box3.setFromObject to compute the bounding box of ......
Read more >three.js box3 of a imported sphere - javascript - Stack Overflow
var box = new THREE.Box3().setFromObject(obj);. With this i can compute boxes for my objects and i can merge them together if i want....
Read more >Bounding volume collision detection with THREE.js
This article shows how to implement collision detection between bounding boxes and spheres using the Three.js library.
Read more >Three.Js Obb Implementation - ADocLib
getCenter target is now required' ; target new Vector3;. } return ... box new Need Box3.setFromObject to return an AABB in local space...
Read more >Bounding volume - Wikipedia
In computer graphics and computational geometry, a bounding volume for a set of objects is a closed volume that completely contains the union...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Some time ago i’ve planned to develop an Oriented Bounding Box class for
three.js
. Most algorithms calculate in the first step the convex hull of the considered geometry. The good thing is that we already have aQuickHull
implementation that calculates the convex hull with good time complexity (average-case O(nlogn)).In the next step you can use a method that is called rotating calipers to compute the oriented minimum bounding box for the given convex hull. Once the OBB is computed, you can use the SAT algorithm for fast collision detection. This would be a proper solution for even more complex requirements.
The API could look like this:
Although there are more efficient algorithms for OBB creation (like this one), the mentioned technique should be feasible to implement. And yeah, i know
three.js
is not a library for computational geometry but it’s always handy to have these algorithms around 😇 . At least in theexamples
directory.If somebody wants to try an OBB implementation, i would definitely support this 😊 .
Yes, that’s correct. In effect, what I want is to be able to get the bounding box of a subtree of my hierarchy. i.e. the bounding box of all the contained geometry aligned within the coordinate space of the root of the subtree. Perhaps I’m thinking about this wrong, but it seemed like something a lot of people might want, for example to show a box around the bounds of the subtree, where the box is aligned to the orientation of the selected node.