Applying defaults to imported mesh

i have a glb that i’m importing to babylonjs scene and that works fine

but issue is that mesh has a scaling and rotation set on its root node
for example: inspector shows rotation.x = 1

which means if i try to set rotation on any of the child nodes, it’s going to be relative to root - and in this case, that pretty much means its going to apply on the wrong axis:

for example, if later in the code i set this for a child mesh:

mesh.rotation = new Vector3(0, Math.PI, 0);

it’s going to flip it upside-down instead of front-to-back.

how can i “apply” rotation settings from the root node as-is on import and move forward as they were zeroed from that point onwards?

i though of editing in blender to “apply” rotations, but that is a whole another problem as GLTF2Export in babylonjs produces file with corrupt meshes (i can export to .babylon without issues, but i cannot import that into blender) (i will provided a PG reproduction for this gltf export issue separately)

Hi vladmandic,

Correct me if I’m wrong, but what I think you’re going for is that you want to be able to manipulate the transforms of child nodes within an imported transform hierarchy using logic based on Babylon’s conventions for axes (where Y is “up”, for example) as opposed to logic specific to the imported transforms. If that’s what you’re looking to do, one thing to try might be to move those child transform hierarchies to be under a TransformNode of your own, which has whatever parameters you want, using setParent to keep your child hierarchy from moving. For example, if you had the hierarchy

  -> A
    -> B

and you wanted to be able to manipulate A in order to rotate/translate B, you could create a new TransformNode A2, set that transform’s position to be A’s absolute position, then call B.setParent(A2). A2 would then have A’s world-space position and no rotation, and you’d manipulate A2 to move B instead of manipulating A.

If you want to keep the same hierarchy, you can also achieve this result by starting from the root and “cascading” down the hierarchy, applying parent’s world matrices as you go, but I think that’s likely to be much more complicated than just moving the parts of the hierarchy you care about under custom nodes. Hope this helps, and best of luck!

1 Like

@syntheticmagus yup, that’s exactly what i’m going for. wish there was “apply”, just like there is in blender that applies all transforms and settings get zeroed out from that point onwards. but since that doesn’t seem to exist, your solution of separate root node for transforms makes sense.