Meshes don't lookAt(camera.position) correctly after exported to glb?

Skull.babylon file open in the sandbox :

Same skull model after it’s been exported to glb and reopened in the sandbox:

It seems like the axis are a bit changed. Is this expected behavior ?

I tried to fix the axis orientation in blender to match the original’s orientation and all that

All this hussle because I want to use Blender as my level design tool and then do everything via code after importing the glb scenes exported by it. The thing is after the glb scene is exported, the lookAt function on the skull meshes doesn’t work well and it seems their orientation is all messed up as I tried to fixed it by using the yaw,roll etc values but nothing came out of it.

Any general tips for blender level design process ? I’m losing my mind a bit cause even when I managed to fix the axis thing the meshes still can’t lookAt correctly at my camera/player. I want to standardize the way all meshes are orientated in the scene so I won’t face any more problems :triumph:

[UPDATE] Are all the problems regarding orientation/lookAt because of the skull object changed to use a transformNode as its root ?

I actually had to change scene.getMeshByName("skull) to scene.getTransformNodeByName("skull) to make everything import correctly after the porting to blender.

Ok that makes sense. gltf is (unfortunately for us) right handed. So we need to add a parent to the actual gltf node to convert it back to left handed

1 Like

How can I do this ? With Blender ?

no :0 I just tell you why you have a root transform node in bjs :slight_smile: I’m not a Blender user.

Blender (or any DCC tools) will generate a correct gltf. When babylon.js will load it, it will add a root node as you already found out :slight_smile:

Haha okay okay but why is the way the gltf exported skull model rotates wrong when using lookAt(camera.position) ?

because the object is for right handed and not left handed hence why you need to use the root node and not the child

In case relevant: I ran into similar problems with my imported GLB. LookAt had the mesh flipped around and I couldn’t correct the rotation and also use LookAt. Found that I could only adjust rotation using a quaternion.

Ended up using a customized LookAt function so that I could get everything oriented correctly.

  lookatposition(lAt, myMesh){ // lAt = vector3(xyz) of target position to look at
    if (lAt){
      this.pitchAdjustment = 1.6; //use to orient pitch 
    	lAt = lAt.subtract(myMesh.position);
      var rotationFactor = -Math.atan2(lAt.z, lAt.x) - Math.PI/2;
      //imported GLB only works with quaternion, also needs pitch adjustment to stand upright
      var yprQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(rotationFactor, this.pitchAdjustment, 0);
      myMesh.rotationQuaternion = yprQuaternion;
    }
  }

ps. I copied most of this function from somewhere on the forum…

1 Like

image

Ι actually the root node named skull is what I’m using except if you mean the actual root node that is parent of every object in the scene. Though that doesn’t mean right to me cause everything is gonna get rotated.

Maybe I misunderstand what you are looking for

This is where a playground can save everyone a lot of time :wink:

1 Like

Sigh I tried your code, didn’t work same behaviour as before I think I encounter a weird problem in my project though, it seems the meshes spin when I press the W(forward) key for some reason and not the left right.

Maybe there is something stupid with my coordinate system or transformations, don’t know anymore.

Really glad you provided a good piece of code. Will have it in mind !

Yeah I’m gonna setup one right now.

https://www.babylonjs-playground.com/#U8MEB0#89

Playground Link.

I took the Skull.babylon file, got it into the sandbox. I exported into glb format. I import this into blender to be a part of my scene and I export it again as a single object from my scene(which is irrelevant for now as we are talking about the skull mesh’s behavior) and this last exported one from blender is the one you see in the playground.

The crate behaves correctly with the lookAt(camera.position) always facing the camera.

The skull not so correctly.

Hope it’s clear now I feel so bad about not providing a playground before sorry. Hope something can be done about this situation.

Also said blender exported model in the sandbox

See, with a playground it took me 5 minutes :wink:
https://www.babylonjs-playground.com/#U8MEB0#90

The lookAt function let you define additional rotations for meshes that are not correctly oriented initially

Also note the call to setParent(null) so you don’t have to worry about hierarchy

1 Like

So it was the

setParent(null)

The funny thing is that you have replied to a recent thread of mine about the yaw and roll attributes of the lookAt() method. I tried them but I didn’t know about setPrent(null).

Thought can’t really understand how it’s necessary and why it corrects the situation.

I can’t really thank you enough cause I was stuck for so long porting the level design process to Blender and now creating the level,positioning meshes and many other things gonna be so easier.

Man you prove to be more awesome everytime.

Bless you.

No worries! My goal is to make sure everyone is unblocked :wink:

1 Like