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
[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.
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…
Ι 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.
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 !
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.
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.