Bake on glb model is doing weird things

I’m trying to build a tool that helps user to “align” a 3d scanned object with the origin of the coordinate system, since I need that for some downstream processing. But when I bake the GizmoManager transform weird things happen. Does anyone know the magic incantation I need to perform on my transform Matrix to make it something that is correctly applicable to my glb vertices? And is this a bug?


  1. use the gizmo to move the model closer to the origin of the x,y,z axes, and rotate it to align with those axes.
  2. then click the green “bake” button in the top left of the screen.

Actual: model jumps to random wrong location.
Expected: the model should not move when transform is baked.

See Babylon.js Playground

Well by Jove, I think I got it, the hard way, wondering if there’s an easier way…


You should put your pivot node as as child of the __root__ node that is created by the gltf loader to handle left/right handedness. Also, your meshes have an initial matrix which is not the identity (they have a rotation around the x axis), so baking using only the pivot matrix won’t produce the expected result as the x rotation will be applied afterward. So, you should:

  • bake the current transformation of the meshes just after loading time to reset their local matrix
  • make the pivot node a child of the __root__ node


1 Like

Cool, thanks for your help, your solution is tantalizingly close, but sometimes, depending on order of operations, usually after translate/rotate combinations, the bake button doesn’t stick (meaning if you click the bake button multiple times without doing any gizmo manipulations the model moves by an increment each time)…

Repro steps:

  1. Move model in + Z axis closer to the origin
  2. Bake
  3. Rotate around Y axis clockwise (green) to align with X axis
  4. Bake
  5. Rotate clockwise around Z axis (blue) to be horizontal with X axis
  6. Bake
  7. Bake
  8. Bake
  9. Bake
    The model just keeps on rotating clockwise about Z axis like this:

I tried your steps but could not reproduce…

Yeah, it only happens sometimes…

Still no luck…

Try to add container.computeWorldMatrix(true); at the end of bakeTransform, as it seems the bug occurs when the world matrix of the pivot is not ok.

nope I added that and still happens, are you using version 5.0.0 ?

Yes, I’m testing your PG in the Playground in 5.0.

Maybe others are able to reproduce the problem?