How to find topright, topleft, bottomleft, bottomright from a mesh given its normal

I’d like to write a function for any arbitrary plane mesh at any orientation in the scene, given the mesh normal: I’d like to get the Vector3 representing the topright, topleft, bottomleft, bottomright of the mesh. The mesh will mostly be a flat plane.

I’m not sure how to do that. For a mesh looking at -Z axis, its easy to do, you just get the hierarchyboundingvectors.min and hierarchyboundingvectors.max and use a combination of x,y,z of each of these to get topright, topleft, bottomleft, bottomright.

But what if the plane’s normal is pointing to +y or anyother arbitrary direction. Can someone offer ideas on how that can be achieved?

Is this the same as transforming local coordinates to world coordinates?

See this PG: https://playground.babylonjs.com/#X3C6VN#1

Assume you know the original local coordinate of each corner (e.g. localPosition). You can apply the following transformation to the world coordinate every time you update you moved, scaled, or rotated the mesh. You can trigger a mouse click to update in the above PG.

const matrix = mesh.computeWorldMatrix(true);
const localPosition = new BABYLON.Vector3(0, 0.5, ,0);
const globalPosition = BABYLON.Vector3.TransformCoordinates(localPosition, matrix);
1 Like