How to start a specific animation?

Having some problem with starting an animation. My Code:

var loader = new THREE.GLTFLoader();
loader.load( gallery[current], handle_load );
let car;


function handle_load( gltf ) {

     car = gltf.scene;
     car.material = new THREE.MeshPhongMaterial({flatShading:false});
     car.position.y = 2.9;
     car.position.z = 0.2;
     car.scale.set(1.9,1.9,1.9);
     car.castShadow = true;
     car.receiveShadow = true;

     car.traverse( function ( child ) {

          if ( child.isMesh ) {

               child.castShadow = true;
               child.receiveShadow = true;

          }

     } );

     scene.add( car );

     animate();

}

the second hour I try to activate the animation constantly something goes wrong.
When i m load this model in three.js editor, everything is fine, everything works.
Name animation in editor is JUMP

There’s no animation code here, tho - you need to use AnimationMixer and parse action clips from gltf (like here.)

that’s what I did. Didn’t help much mixer

@Lighty Please invest a little bit more time in providing a good initial post. E.g. give it a descriptive title and format your code properly. I’ll change it this time for you but keep in mind that low effort posts are normally flagged and deleted.

2 Likes

Your code has: (1) no mixer; (2) no animations. The example source code shows exactly, step by step what to do and how to load animations - did you look at it? :man_shrugging:

updated. the hare still does not want to dance ((

  1. object.animations is an array, you have to loop through it to create action clips (even if there’s only one animation, it is still going to be an array of 1 element.)
  2. You must call mixer.update(deltaTime) in your animate() function to update the animation every frame (you can use Clock.getDelta to get the value of deltaTime for each frame - or just go the easy way and use something small, ex. 0.01 or 1.0 / 60.0)