After importing a model into my Three.js scene, I encountered an issue where the bones can be moved and rotated successfully, but the model's geometry does not follow these bone movements.
For importing the JSON file and adding it to the scene, here is the code that I used:
/*load JSON file*/
// instantiate a loader
var loader = new THREE.JSONLoader();
loader.load( 'https://cdn.rawgit.com/wpdildine/wpdildine.github.com/master/models/cylinder.json', addModel );
var helpset;
var scaleVal = 3;
function addModel( geometry, materials ){
materials.skinning = true;
var cs = scaleVal * Math.random();
mesh = new THREE.SkinnedMesh( geometry, new THREE.MeshFaceMaterial(materials) );
scene.add(mesh);
helpset = new THREE.SkeletonHelper(mesh);
scene.add(helpset);
}
The imported JSON files already include weights, so I assumed there was no need for me to manually add them. However, could there be an issue with binding the skeleton to the mesh?
Here is a link to view my code - https://jsfiddle.net/joeob61k/1/ (New link with scripts, thanks @Mr. Polywhirl)
In the GUI controls, you can observe that 'Bone_2' moves one of the bones but not the mesh.
EDIT: In attempting to access the bones of the mesh within the render() function, I employed the following line of code,
mesh.skeleton.bones[2].rotation = 0.1;
This resulted in the error message: 'Cannot read property 'skeleton' of undefined(…)', where 'undefined' represents the mesh variable. Is there a different method to access the bones of a SkinnedMesh that I should be using?