Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

THREE.JS how to move the bones of a SkinnedMesh?

I'm working on a 3D project using THREE.JS and I want to animate a simple minecraft like character.

To do so, I exported one from Blender (with bones) and I render it with THREE.JS using the SkinnedMesh class.

I tried everything to make the arm of the mesh to move but I can't figure out how to do it. I tried changing rotation, position, matrix and also setting all flag to true (like matrixWorldNeedsUpdate but the arm did not move).

Here is a sample code:

var meshBody = new THREE.SkinnedMesh( geometry, materialTexture );

...

animate = function(){
    meshBody.bones[3].rotation.z += 0.1     
    meshBody.bones[3].matrixAutoUpdate = true;
    meshBody.bones[3].matrixWorldNeedsUpdate = true;
}
like image 383
user2026247 Avatar asked Feb 26 '13 17:02

user2026247


1 Answers

While constructing your mesh, make sure the skinning property of your material is set to true, e.g.:

mesh = new THREE.SkinnedMesh (geometry, 
          new THREE.MeshBasicMaterial ({color: 0xaaaa00, skinning: true})
     );
like image 193
Mohamed A. Maksoud Avatar answered Oct 16 '22 17:10

Mohamed A. Maksoud