Get mesh bounding box position and size in 2d screen coordinates

Hey folks, I was working on our website and discovered a slight improvement to this method. The bounding box works in most cases, but if the bounding box is at an angle, the screen coordinates may be offset.

Instead of working with the bounding box, it is possible to observe the individual vertexes of the mesh and project them onto the 2D plane like so:

const meshVertexPositions = mesh.getVerticesData(VertexBuffer.PositionKind)
let meshCoordinates: Vector3[] = []
for (let i = 0; i < meshVertexPositions.length; i+=3) {
    meshCoordinates.push(
        new Vector3(
            meshVertexPositions[i],
            meshVertexPositions[i+1],
            meshVertexPositions[i+2]
        )
    )
}

You can then use the coordinates with the method above. Of course, this method can be less performant as the number of vertices can be quite large. I hope this helps someone in the future. :slight_smile: