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:
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âŚ
Hi,
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.
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 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.