Skip to content

Commit

Permalink
Update three-model.js
Browse files Browse the repository at this point in the history
It was necessary to make sure each material has "skinning" set to true. I also added the ability to morphTargets to true for some future Morph animations on SkinnedMeshes (needs some thought there, so I didn't add any additional code, but the above materials will allow custom scripts to later be added by someone using this library to create and play morph animations until we have a proper solution)....

This will solve c-frame#87, as well as c-frame#86
  • Loading branch information
msj121 authored Sep 14, 2016
1 parent a5aeed1 commit 0c45541
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/loaders/three-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ module.exports = {
loader.load(data.src, this.load.bind(this));
} else if (data.loader === 'json') {
loader = new THREE.JSONLoader();
loader.load(data.src, function (geometry /*, materials */) {
var mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({
vertexColors: THREE.FaceColors,
morphTargets: !!(geometry.morphTargets || []).length,
morphNormals: !!(geometry.morphNormals || []).length,
skinning: !!(geometry.skinIndices || []).length
}));
this.load(mesh);
loader.load(data.src, function (geometry, materials ) {
if (materials[0] instanceof THREE.MeshLambertMaterial){
var mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({
vertexColors: THREE.FaceColors,
morphTargets: !!(geometry.morphTargets || []).length,
morphNormals: !!(geometry.morphNormals || []).length,
skinning: !!(geometry.skinIndices || []).length
}));
this.load(mesh);
} else {
for ( var i = 0; i < materials.length; i ++ ) {
materials[i].skinning = true;
materials[i].morphTargets = true;
}
this.load(new THREE.SkinnedMesh( geometry, new THREE.MultiMaterial( materials ) ));
}
}.bind(this));
} else {
throw new Error('[three-model] Invalid mode "%s".', data.mode);
Expand Down

0 comments on commit 0c45541

Please sign in to comment.