Instances with animation

Hi,
I tried to import a mesh with animations and created instance for it using below reference. But, the main mesh only animating, the instance mesh is not animating. How to solve this?
https://playground.babylonjs.com/#ZZVZUN#1

In Chrome I see both models animated -

2 Likes

Thanks For your reply @labris . I couldn’t see this models in my browser(Chrome). In my browser ,there is the plane only.
Any other references for import meshes and instancing that with animations.

It’s working on my mobile phone as well. Chrome.

1 Like

yes, In mobile, it is working fine. But why not on desktop.

1 Like

Oh. It is just because of the firewall settings. Now only I am seeing the error in my console.
And I am using this same script in my project as well, I am sharing script below. In that, the model is loaded. the instances also created . But the animation happens only on the actual mesh. not on instances.

BABYLON.SceneLoader.ImportMesh(
    '',
    'assets/models/',
    'Hotspot Light.glb',
    scene2,
    function (meshes, particleSystems, skeletons, animationGroups) {
      animationGroups[0].start(true);
      animationGroups[1].start(true);
      animationGroups[2].start(true);
      let inst = createInst(meshes[0],1,0.05, -1,animationGroups);
      let inst2 = createInst(meshes[0],1,0.05, -1.4,animationGroups);
      let inst3 = createInst(meshes[0],0.5,0.05, -1.45,animationGroups);
      let inst4 = createInst(meshes[0],0.85,0.05, -1.8,animationGroups);
      let inst5 = createInst(meshes[0],-0.22,0.3, -0.5,animationGroups);
      meshes.forEach((mesh) => {
        if (mesh.material) {
          mesh.actionManager = action_manager_mesh;    
          assign_material_scene2(mesh);         
        }
      });
    }
  );

  function createInst(mesh:any, x:any, y:any,z:any,animations:any){
    let instRoot = new BABYLON.TransformNode("instRoot", scene2);
    for (let i = 0; i < mesh.getChildren().length; i++) {
        let bodyPart = new BABYLON.TransformNode("bodyPart", scene2);
        bodyPart.parent = instRoot;
        bodyPart.position = mesh.getChildren()[i].position;

        for (let j = 0; j < mesh.getChildren()[i].getChildren().length; j++) {

            let bodyPartInst = mesh.getChildren()[i].getChildren()[j].createInstance("bodyPartInst");
            bodyPartInst.actionManager = action_manager_mesh;
            if(i>0) bodyPart.animations.push(mesh.getChildren()[i].animations[j]);
            bodyPartInst.parent = bodyPart;
        }
        if(i>0){
          scene2.beginAnimation(bodyPart, 0, 100, true);            
        } 
    }
    instRoot.scaling = new BABYLON.Vector3(0.01,0.01,0.01);
    instRoot.position.x += x;
    instRoot.position.z += z;
    instRoot.position.y+=y;
    return instRoot;
  }

Try to search for ‘instances animation’ on the forum. It yields in 50+ results. I bet you will find a solution. If not, come back. :sunglasses:

2 Likes

Do you see animations in these examples - https://playground.babylonjs.com/#AJA5J6#77 and https://playground.babylonjs.com/#AJA5J6#80 ?

1 Like

Thanks for your references @labris . I tried with the second one https://playground.babylonjs.com/#AJA5J6#80 .

But it throws an error while calling createInstance() . I have given below the error message.

Property ‘createInstance’ does not exist on type ‘AbstractMesh’.

Which browser do you use? Also, make sure that PG is latest version.
I have no problems with this PG - https://playground.babylonjs.com/#AJA5J6#80 - in Chrome latest.
They all are running :slight_smile:

Oh. Sorry @labris . I didn’t mean the issue is in playground, I am facing the issue while using this code in my project. That is actually an angular project. So I am writing this within the .ts

And this is completely true, there is no such property - Babylon.js docs
So it seems you need to import { Mesh } which has such property - Babylon.js docs

1 Like

Hi @jayakannan just checkin in, do you have any more questions? :slightly_smiling_face:

1 Like

No @carolhmj . I am not having related to this now.

1 Like