Sam
Sam

Reputation: 207

THREE.js Oriented Bounding Box

How do we find the oriented bounding box in three.js after computing convex hull?

In the following image: Green represents convex hull (I am displaying it as mesh for visualization), white is AABB.

I am aware that there are no in-built methods available in three.js. I tried OBB.js from threejs examples but that didn't work for me. The convex hull algorithm looks promising. Any pointers on what the next steps are will be very helpful.

From what I understand, I need to calculate covariance matrix of set of vertices that form the convex hull's boundary (and exclude other internal vertices). How do I get those vertices? convex_hull_visualization convex_hull_object

Upvotes: 2

Views: 1002

Answers (1)

Mugen87
Mugen87

Reputation: 31076

How do I get those vertices?

Assuming you have generated an instance of ConvexHull, you can access all vertices like so:

const faces = convexHull.faces;

for ( let i = 0; i < faces.length; i ++ ) {

    const face = faces[ i ];
    const edge = face.edge;

    // moving along a doubly-connected edge list to access all vertices

    do {

        const vertex = edge.head().point;

        console.log( vertex );

        edge = edge.next;

    } while ( edge !== face.edge );

}

Any yes, the official OBB class does not yet support the computation of the best-fit OBB.

Upvotes: 2

Related Questions