movePOV after setDirection not working as expected?

I’m trying to execute a simple translation and then movement of a box:

Step 1: Move the box to a desired absolute position (I use set setAbsolutePosition)
Step 2: Point the box so that it is pointing in the same direction as a normal vector of an adjacent mesh. Let’s use BABYLON.Axis.X for sake of simplicity. (I use setDirection)
Step 3: Move the box again slightly in the “forward” direction from where its pointing. (I use movePOV) illustrates what i’m trying to do.

You can see that the box actually moves backwards and not forwards. What am I doing wrong?

mesh.definedFacingForward = false;

did the trick

1 Like

Actually @sebavan and @Evgeni_Popov while this does the trick with the cube - it didn’t work for my GLTF Mesh.

@Evgeni_Popov hinted this in this post mesh.calcMovePOV() not working as expected that one has to know what the front for the mesh is.

POV movement really pertains to how the mesh being defined in an external program like blender. In order for a Mesh to move in terms of the mesh’s own “Point of View”, that being in terms of its current position and rotation, you need to know what is the “front” of the mesh.

Inside blender my front looksat -Y axis as seen in this screenshot

Here are my GLB export settings in blender. Notice the “+Y Up” is checked

After importing the GLB in Babylon, the front of my mesh looksat the +Z axis.

MovePOV amountUp actually doesnt work as expected even with definedFacingForward=false as it moves the mesh forward and not Up. Any idea how I can make the GLB work just like non-glb cube in the above playground

Have you tried setting scene.useRightHandedSystem = true? glb files have a different coordinate system than Babylon, so some special transformations must take place when loading a file. scene.useRightHandedSystem = true disables these transformations.

Setting scene.useRightHandedSystem = true gives the same behavior. The mesh gets moved forward instead of up.

You wouldn’t happen to have a PG with your mesh import? Or with a dummy from blender to reproduce?

here you go @mawa

Step 1 works as expected,

But Step 2 doesn’t: The face doesn’t point to +X axis. Making me think I can’t use setDirection as is and have to do some math to ensure that the axes of the GLB are lined up with BABYLON’s axis. Scene scene.useRightHandedSystem has other side effects that I’d like to avoid. So I’m thinking I’ll have to write a separate setDirection function for this mesh instead of calling the setdirection on the Mesh class. Any idea on who to get the Delta between the worldcoordinate system and the meshes’ coordinate system?

Step 3 has probably the same problem - there needs to be some translation of the coordinate systems done. I’d like it to be standard with BABYLON’s left handed system.

I think you should get rid of the rotation of the “baked_mesh” as it adds additional complexity.

I could get it work by updating the mesh orientation and baking the result into the vertices:

Did you try unparent it from this root node created from the blender import and parent it to a new (abstractMesh or transformNode)? I’m not 100% sure but I believe this could do the trick.