digi_exp527
digi_exp527

Reputation: 27

Animation of JSON model THREE.js

The JSON model was created in Blender and the animation was also made in Blender using bone. But when I try to run the animation in three.js, the rest of the scene is dislayed except the fish. I have searched for an answer but have not found anything which solves my problem.I am following the book 'Learning three.js' by Jos Dirksen. Also I am a beginner in three.js

var loader=new THREE.JSONLoader();
var mesh;
loader.load('fish_anim1.json', function (model, mat){
    mat[0] = new THREE.MeshLambertMaterial({color: 0x9ABF15, skinning: true});
    mesh = new THREE.SkinnedMesh(model, mat[0]);

    animation = new THREE.Animation(model, model.animations);

    mesh.position.set(0,5,0);
    mesh.scale.x = 3;
    mesh.scale.y = 3;
    mesh.scale.z = 4;
    mesh.rotation.y=Math.PI;
    mesh.name='fish'+fish_count;
    scene.add(mesh);

    animation.play();
});

In render loop, I add this line to update animation

THREE.AnimationHandler.update(delta);

Upvotes: 1

Views: 3822

Answers (1)

Hobbes
Hobbes

Reputation: 801

You are close, you don't pass all of the animations as the second parameter in THREE.Animation, you just pass the one animation.

animation = new THREE.Animation(mesh, model.animations[0]); // EDIT: First parameter is the SKinnedMesh not geometry.

Upvotes: 2

Related Questions