Most performant way to get absolute world position of highest and lowest vertex in a rotated mesh?

I was using parentNode.getHierarchyBoundingVectors() to get the min and max bounding vectors, but I realised that my meshes (and thereby their bounding boxes) are arbitrarily rotated, so I’m getting the min and max of all the rotated bounding boxes and not the absolute world min and max vertex, which is what I really want.

What’s the most performant way to find say the highest and lowest vertex in a rotated mesh after transformations have been applied (i.e. absolute world coords), preferably without have to iterate over every and run calculations on every point?

I’ve been trying mesh.getBoundingInfo().boundingBox.minimumWorld but it’s returning exactly the same values as mesh.getBoundingInfo().boundingBox.minimum in my React Native environment with rotated meshes containing arbitrary points.

Likewise with mesh.getBoundingInfo().boundingBox.vectorsWorld and mesh.getBoundingInfo().boundingBox.vectors - they’re producing the same results.

Force mesh.computeWorldMatrix(true); gave me different results but still not what I was expecting. I guess I need to experiment some more.

mesh.bakeCurrentTransformIntoVertices() will make mesh position and rotation zero and scaling one.

All of your vertex related stuff including bounding info will then be in world coordinates.

I think that’s what you want.

Cheers!

Flex

4 Likes

Thanks @flex, I had discovered and tried this but 1) I need to retain the separate mesh transform, and 2) cloning and baking the mesh seems like an expensive operation just to get highest and lowest vertices. But I can use the code in mesh.bakeCurrentTransformIntoVertices() to get the values I want i.e.

let temp = new Array<number>();
let index: number;
for (index = 0; index < data.length; index += 3) {
  Vector3.TransformCoordinates(Vector3.FromArray(data, index), transform).toArray(temp, index);
}

Still, I thought mesh.getBoundingInfo().boundingBox.minimumWorld and maximumWorld would give me the same info in a more performant way, but I must be misunderstanding its purpose as it’s not providing the expected results.

3 Likes

Facing similar issue with no rotation, was expecting Minimum World X to return 4 instead of 1 in this Playground thingie I created. Check the in browser console.

Thanks for the solution :slight_smile:

Since the sphere’s position (or rotation or scaling) was changed, its world matrix needs to be recomputed to get the expected result. :slight_smile:

2 Likes

Thanks!