Get information from BoxHelper

Hello,
In order to get an accurate boundingBox of an object with rotation, I was trying to do something similar to this fiddle: https://jsfiddle.net/5k3semnz/3/ (based on 3d - Accurate bounding box of an object - Stack Overflow), where the boxHelper of the red cube is updated depending on the matrix from the object.

Since that this updated boxHelper has exactly the vertices of the object (not AABB), I would like to get the position of the vertices of this boxHelper in order to calculate accurate collision, etc.
Is this possible?

I’m concerned that I can find this kind of information in .Box3().setFromObject(OBJ), but I tried to rotate its matrix to get the info updated at the rotation of the object and I can’t do It.

Thanks for your time! :grinning:

An instance of BoxHelper is technically a specific instance of LineSegments. That means like a normal line object it has a geometry which can be accessed over the object reference. And of course it has a position attribute with the respective vertex data which you can extract and transform to world space.

Thanks for your reply Mugen,

I get the vertices by

function getBoxHelperVertices(boxHelper) {
    var points = [];
    for(var i = 0; i < 8; ++i) {
        var x = boxHelper.geometry.attributes.position.getX(i)
        var y = boxHelper.geometry.attributes.position.getY(i)
        var z = boxHelper.geometry.attributes.position.getZ(i)
        points.push({x: x, y:y, z: z})
    }
    return points;
}

But how can I transform them into world space in this case?

Thanks!

You have to represent the vertices as instances of Vector3 (and not as plain objects). You can then use Vector3.applyMatrix4() and apply the world matrix of the helper.

It worked like a charm, thank you so much! :grinning:

1 Like