Mesh rotation normal reverse

PG:

I hope that when the model is rotated, it will rotate according to the axis and change the angle, rather than directly inverting it.

Scaling by 1 instead of -1 line 32 will prevent the flipping:


Click on the red circle and release it, the panel will become straight
A new problem has occurred, please fix it again

You should not modify the quaternion of the planeMesh:

A few more spins will cause problems

I would recompute the plane normal by using the normal from any vertex of the plane mesh and simply transforms it according to the plane mesh transformation:

if d=3

PG:

planeMesh position not fit model

add slider to control panel position ,move slider position error

In this case, I would get 3 points of the mesh plane (using mesh.getVerticesData("position")), transform them with the mesh world matrix and use these 3 transformed points to recalculate the plane equation, which will give you the normal and the d factor => look for “plane equation from 3 points” in a search engine in case you don’t know how to do it.

I don’t quite understand. Can you make a PG for me?
Thanks!

Unfortunately I don’t have much time to spend on it, as my plate is quite full these days.

You should try to make a PG with my indications above and ask for help when you are blocked.

Some more advices:

  • const positions = mesh.getVerticesData("position"); const p1 = new BABYLON.Vector3(positions[0*3 + 0], positions[0*3 + 1], positions[0*3 + 2]) will get you the first point. To get two other points, change 0*3 to 1*3 for the second one, and to 2*3 for the third
  • use BABYLON.Vector3.TransformCoordinates to transform these points to world space by using mesh.getWorldMatrix() for the matrix
  • given these 3 points, calculate the plane equation which gives you the a,b,c and d coefficients of this plane: (a,b,c) is the normal and d the distance to the origin
1 Like

For rotating the mesh with gizmos, the rotation of mesh was changed so the plane can be calcaulated from points of mesh in world space, but when changing the d of plane, the planeMesh can be far away from the box being clipped, any idea on this?

You should translate the plane mesh in the “direction of the box” (so, in the direction of the Z axis) and not in the direction of the plane normal.