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

Hi there!

I’m exporting a scene from Blender that contains several objects as instances. Each instance has an animation (which also seems to be an instance). The animation involves rotation and tilting around the Z-axis. However, when I run the scene in BabylonJS, all instances move to the same position, as if they are animated as a single object.

I see the same issue in the example provided by @labris above. If I switch versions in the Playground, I can see that in version 4 it worked correctly. Currently, I’m trying to find a workaround by cloning and modifying animations before starting them, but it feels quite complicated and messy.

Is there a simpler way to make instances use their own coordinates for the animation? I’d appreciate any help!

Hey @rubaka!

It would be cool if you could move your question to a new topic and reference the current one.
Thanks!

Hello! Sure, no problem. But I would like to understand why it’s not possible to continue this topic. It seems that my question doesn’t significantly deviate from it, and this topic is not closed. I’m not arguing, I just want to understand, otherwise, I won’t remember and will continue the discussion in the old topic somewhere else. That’s just how my mind works :slight_smile:

It’s solved.

If you open a new one and we find out that you are exeperiencing a bug

you/we can move the new topic to the Bugs category easily.

I’m not arguing, leave it as is if you feel so.

In my case, I solved the problem by assigning a parent object (which I hide) to the animated instance. Now the instance starts the animation from zero along all axes, and I can move the parent element wherever I want without affecting the child’s animation and vice versa.

I hope this is not a bug, and the topic doesn’t require further attention. Happy development to everyone!

2 Likes