setParent(null) versus parent = null of model to remove mirroring / inverse scaling?

When I import a GLB model from blender it seems to import fine but when I set the parent to null using mesh.parent = null it shows it as mirrored. If instead I use mesh.setParent(null) then it works as expected.

For example the following glb file (from this blend file). When it is initially loaded into my scene it (correctly) looks like this:

If I then run the following code:

const door = scene.getMeshByName("door_frame")!.clone("door", null)!
door.parent = null

root_mesh.setEnabled(false) // disable the root which will hide all meshes of the imported model

I see the following; where the door is clearly a mirror image:


If instead of door.parent = null I call door.setParent(null) then it does not incorrectly mirror the model.


Is this an error / setting I can choose when I export the model from blender? Is this some other error? This page mentions there can be rotation issues because rotationQuaternion is already set. Can there also be some kind of negative scaling issue we could add to the docs or is this something similar / something else?

Ok so I just realised the “correct” imported model shows there is some pretty funky rotation and scaling applied to the root:


I assume once I get rid of this and have it import correctly then the other problems will go away too. So I now assume this is a problem with my blend file…

Yes, that should solve your issue.
Note that there has been some work done to ‘automagically’ handle left handed vs right handed imports from blender.
Also note that it’s actually not an error that there is both ‘parent’ and ‘setParent’. As you have already found out with setting the parent to null using both methods, ‘setParent’ actually really ‘sets’ a NEW parent. Where parent (even when null) will keep with the original rotation and scaling inheritated from your mesh/parent node, setParent(null) zeros the values and sets a new parent.

1 Like

Those are fully normal and expected as handedness convention are different in Babylon and Gltf.

So at import time Babylon creates a root node with special values to “flip” things.

1 Like

Thanks @mawa , thanks @sebavan. That makes more sense now. I was confused as I also had an off by one “error” where I had to shift the mesh to position 1,0,0 to get it to be were I thought 0,0,0 should be. But now I realised that if in blender, instead of putting the origin at the smallest x of the model, I put it at the largest x, then when I export it as a glb/gltf, then it works as expected. E.g. so instead of having the origin here:

I now build the meshes with their origin here:

I could easily just be getting confused by something else going on but that seems to be what I need to do now to get it to work as expected. I don’t know if that makes sense. I don’t know if that’s what other people do? And I don’t know what the right approach for z and y axes is at the moment but I will post back if it needs to be anything over than building your model from the minimum z and y.