Baking Transformations Help

Hello All,

I really just dont understand why calling this.self.secondaryWeapon.gunMesh.bakeCurrentTransformIntoVertices(); is affecting my this.self.primaryWeapon.gunMesh orientation. Basically the services just return imported .gltf files containing the meshes and child data. The gunMesh is being set to the root transform node…but the main code is below:

I know for a fact that the “bug” is coming from calling bakeCurrentTransformIntoVertices() twice. If I call it just once for the primary weapon (m4) then the orientation is as expected and everything works for the primary weapon.

However when I try to orient the secondary weapon (mp5) by doing the exact same method the secondary weapon looks as expected but then the primary weapon gets turned out of place as seen below:

Any help would be appreciated. I asked about this before but I was unable to solve the issue. If this code just worked as expected (being able to call bakeCurrentTransformIntoVertices() on separate meshes without affecting other meshes) then I would be set. Because everything would be working great.

Either I have a completely wrong assumption of what bakeCurrentTransformIntoVertices() is doing or I think there is a bug with it.

To my knowledge bakeCurrentTransformIntoVertices() allows you to manipulate a mesh (rotation, scaling, position) however you want…and then you call this method to reset the vertices data so that your manipulation to the mesh is basically the new “starting point” (0, 0, 0) of the mesh.

Yes, but in the process the current mesh transformation is reset: translation=(0,0,0), scaling=(1,1,1) and rotation=(0,0,0). If this mesh has children, it may impact them (I think there’s a flag you can pass to bakeCurrentTransformIntoVertices to avoid that): you should check that your meshes don’t have child to make sure it’s not your problem.

When loading a gltf, the root mesh should never be modified, as it is a special node setup by the system to deal with scene handedness: make sure your gun and weapons really point to meshes. Use the inspector to check that:
You should point to items with a cube icon only.

So this is the structure of the m4 (the mp5 is similar):

And this is my code for import:

 async importGunMesh(scene: Scene): Promise<Mesh> {

        this.gunMesh = (await SceneLoader.ImportMeshAsync('', this.gunMeshURL, '', scene)).meshes[0] as Mesh; = + '-Mesh'; =;

        return this.gunMesh;


So should I create a Mesh and then point node3 and node4 to it? Or make that Mesh the parent of these two?


I have tried changing my code to:

async importGunMesh(scene: Scene): Promise<Mesh> {

    let meshes = (await SceneLoader.ImportMeshAsync('', this.gunMeshURL, '', scene)).meshes as Mesh[];

    let children = meshes[0].getChildMeshes();

    this.gunMesh = new Mesh(;

    for (let i = 0; i < children.length; i++) children[i].setParent(this.gunMesh);

    return this.gunMesh;


and the scene structure now looks like:

but now I cant even manipulate any properties on the mp5. Any updates I make dont affect the mp5. And still if I call bakeCurrentTransformIntoVertices() twice (once for each mesh) it messes up the orientation of the primary weapon

If you want to be able to handle node3 and node4 as a single entity, create a TransformNode T, set node3 and node4 as children of T and set T as child of b6270...gles. Then you should call bakeCurrentTransformIntoVertices on node3 and node4. Finally, set T.parent = null to make T a root element and not inherit (as well as its children) the transformations from m4 / RootNode (gltf ...)\ …

Note that you can also use Mesh.MergeMeshes to merge node3 and node4 into the same mesh if you don’t want to create the T transform node (do it after having called bakeCurrentTransformIntoVertices on the two meshes!). You can also delete the transform nodes m4 / RootNode (gltf ...)\ … as they are not needed anymore.

Note however that if you have skeletal animations on these objects they probably won’t work anymore, as animated bones are using matrices that were setup for a specific initial configuration of your meshes that is not the same anymore.

Are you cloning some meshes? Cloned meshes are using the same geometry, so if you are modifying the geometry of one mesh (by calling bakeCurrentTransformIntoVertices), it will modify the geometry of the clones.

Ok thanks! :slight_smile: Ill try that out as well. For now I went back to using basic cubes for my weapons so that I can work on game logic and try to figure out all of this importing stuff out separately. Ill try to implement what you stated above though to see how it affects everything.