diff --git a/build/three.js b/build/three.js index 84c2c19a66655b5bc733ea94c5964ed6628a59b0..79f93301cfd3f6bcc19828325368d8eee97dbda3 100644 --- a/build/three.js +++ b/build/three.js @@ -13553,119 +13553,140 @@ THREE.SkinnedMesh.prototype.addBone = function( bone ) { }; -THREE.SkinnedMesh.prototype.updateMatrixWorld = function ( force ) { +THREE.SkinnedMesh.prototype.updateMatrixWorld = function () { - this.matrixAutoUpdate && this.updateMatrix(); + var offsetMatrix = new THREE.Matrix4(); - // update matrixWorld + return function ( force ) { - if ( this.matrixWorldNeedsUpdate || force ) { + this.matrixAutoUpdate && this.updateMatrix(); - if ( this.parent ) { + // update matrixWorld - this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); + if ( this.matrixWorldNeedsUpdate || force ) { - } else { + if ( this.parent ) { - this.matrixWorld.copy( this.matrix ); + this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); - } + } else { - this.matrixWorldNeedsUpdate = false; + this.matrixWorld.copy( this.matrix ); - force = true; + } - } + this.matrixWorldNeedsUpdate = false; - // update children + force = true; - for ( var i = 0, l = this.children.length; i < l; i ++ ) { + } - var child = this.children[ i ]; + // update children - if ( child instanceof THREE.Bone ) { + for ( var i = 0, l = this.children.length; i < l; i ++ ) { - child.update( this.identityMatrix, false ); + var child = this.children[ i ]; - } else { + if ( child instanceof THREE.Bone ) { + + child.update( this.identityMatrix, false ); + + } else { - child.updateMatrixWorld( true ); + child.updateMatrixWorld( true ); + + } } - } + // make a snapshot of the bones' rest position - // make a snapshot of the bones' rest position + if ( this.boneInverses == undefined ) { - if ( this.boneInverses == undefined ) { + this.boneInverses = []; - this.boneInverses = []; + for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) { - for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) { + var inverse = new THREE.Matrix4(); - var inverse = new THREE.Matrix4(); + inverse.getInverse( this.bones[ b ].skinMatrix ); - inverse.getInverse( this.bones[ b ].skinMatrix ); + this.boneInverses.push( inverse ); - this.boneInverses.push( inverse ); + } } - } - - // flatten bone matrices to array + // flatten bone matrices to array - for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) { + for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) { - // compute the offset between the current and the original transform; + // compute the offset between the current and the original transform; - //TODO: we could get rid of this multiplication step if the skinMatrix - // was already representing the offset; however, this requires some - // major changes to the animation system + // TODO: we could get rid of this multiplication step if the skinMatrix + // was already representing the offset; however, this requires some + // major changes to the animation system - THREE.SkinnedMesh.offsetMatrix.multiplyMatrices( this.bones[ b ].skinMatrix, this.boneInverses[ b ] ); + offsetMatrix.multiplyMatrices( this.bones[ b ].skinMatrix, this.boneInverses[ b ] ); + offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 ); - THREE.SkinnedMesh.offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 ); + } - } + if ( this.useVertexTexture ) { - if ( this.useVertexTexture ) { + this.boneTexture.needsUpdate = true; - this.boneTexture.needsUpdate = true; + } - } + }; -}; +}(); THREE.SkinnedMesh.prototype.pose = function () { this.updateMatrixWorld( true ); - for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) { + this.normalizeSkinWeights(); - // normalize weights +}; - var sw = this.geometry.skinWeights[ i ]; +THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () { - var scale = 1.0 / sw.lengthManhattan(); + if ( this.geometry instanceof THREE.Geometry ) { - if ( scale !== Infinity ) { + for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) { - sw.multiplyScalar( scale ); + var sw = this.geometry.skinWeights[ i ]; - } else { + var scale = 1.0 / sw.lengthManhattan(); + + if ( scale !== Infinity ) { - sw.set( 1 ); // this will be normalized by the shader anyway + sw.multiplyScalar( scale ); + + } else { + + sw.set( 1 ); // this will be normalized by the shader anyway + + } } + } else { + + // skinning weights assumed to be normalized for THREE.BufferGeometry + } }; THREE.SkinnedMesh.prototype.clone = function ( object ) { - if ( object === undefined ) object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture ); + if ( object === undefined ) { + + object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture ); + + } THREE.Mesh.prototype.clone.call( this, object ); @@ -13673,8 +13694,6 @@ THREE.SkinnedMesh.prototype.clone = function ( object ) { }; -THREE.SkinnedMesh.offsetMatrix = new THREE.Matrix4(); - /** * @author alteredq / http://alteredqualia.com/ */ diff --git a/build/three.min.js b/build/three.min.js index ddfbe6538c43414cd6bfd5d98264dd9c3f9380a4..5319d83434482a3d1f2fe9a8f995dc962916c328 100644 --- a/build/three.min.js +++ b/build/three.min.js @@ -274,9 +274,9 @@ THREE.Mesh.prototype.updateMorphTargets=function(){if(0g.end&&(g.end=e);b||(b=h)}}a.firstAnimation=b}; THREE.MorphAnimMesh.prototype.setAnimationLabel=function(a,b,c){this.geometry.animations||(this.geometry.animations={});this.geometry.animations[a]={start:b,end:c}};THREE.MorphAnimMesh.prototype.playAnimation=function(a,b){var c=this.geometry.animations[a];c?(this.setFrameRange(c.start,c.end),this.duration=1E3*((c.end-c.start)/b),this.time=0):console.warn("animation["+a+"] undefined")}; diff --git a/src/objects/SkinnedMesh.js b/src/objects/SkinnedMesh.js index 243c9abf57b713771941889a7d5d84b9486f7cdc..04377789c1efdbc0259dce6c796aa5b523ae5181 100644 --- a/src/objects/SkinnedMesh.js +++ b/src/objects/SkinnedMesh.js @@ -128,89 +128,94 @@ THREE.SkinnedMesh.prototype.addBone = function( bone ) { }; -THREE.SkinnedMesh.prototype.updateMatrixWorld = function ( force ) { +THREE.SkinnedMesh.prototype.updateMatrixWorld = function () { - this.matrixAutoUpdate && this.updateMatrix(); + var offsetMatrix = new THREE.Matrix4(); - // update matrixWorld + return function ( force ) { - if ( this.matrixWorldNeedsUpdate || force ) { + this.matrixAutoUpdate && this.updateMatrix(); - if ( this.parent ) { + // update matrixWorld - this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); + if ( this.matrixWorldNeedsUpdate || force ) { - } else { + if ( this.parent ) { - this.matrixWorld.copy( this.matrix ); + this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); - } + } else { - this.matrixWorldNeedsUpdate = false; + this.matrixWorld.copy( this.matrix ); - force = true; + } - } + this.matrixWorldNeedsUpdate = false; - // update children + force = true; - for ( var i = 0, l = this.children.length; i < l; i ++ ) { + } - var child = this.children[ i ]; + // update children - if ( child instanceof THREE.Bone ) { + for ( var i = 0, l = this.children.length; i < l; i ++ ) { - child.update( this.identityMatrix, false ); + var child = this.children[ i ]; - } else { + if ( child instanceof THREE.Bone ) { - child.updateMatrixWorld( true ); + child.update( this.identityMatrix, false ); + + } else { + + child.updateMatrixWorld( true ); + + } } - } + // make a snapshot of the bones' rest position - // make a snapshot of the bones' rest position + if ( this.boneInverses == undefined ) { - if ( this.boneInverses == undefined ) { + this.boneInverses = []; - this.boneInverses = []; + for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) { - for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) { + var inverse = new THREE.Matrix4(); - var inverse = new THREE.Matrix4(); + inverse.getInverse( this.bones[ b ].skinMatrix ); - inverse.getInverse( this.bones[ b ].skinMatrix ); + this.boneInverses.push( inverse ); - this.boneInverses.push( inverse ); + } } - } - - // flatten bone matrices to array + // flatten bone matrices to array - for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) { + for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) { - // compute the offset between the current and the original transform; + // compute the offset between the current and the original transform; - //TODO: we could get rid of this multiplication step if the skinMatrix - // was already representing the offset; however, this requires some - // major changes to the animation system + // TODO: we could get rid of this multiplication step if the skinMatrix + // was already representing the offset; however, this requires some + // major changes to the animation system - THREE.SkinnedMesh.offsetMatrix.multiplyMatrices( this.bones[ b ].skinMatrix, this.boneInverses[ b ] ); + offsetMatrix.multiplyMatrices( this.bones[ b ].skinMatrix, this.boneInverses[ b ] ); + offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 ); - THREE.SkinnedMesh.offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 ); + } - } + if ( this.useVertexTexture ) { - if ( this.useVertexTexture ) { + this.boneTexture.needsUpdate = true; - this.boneTexture.needsUpdate = true; + } - } + }; -}; +}(); THREE.SkinnedMesh.prototype.pose = function () { @@ -222,7 +227,7 @@ THREE.SkinnedMesh.prototype.pose = function () { THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () { - if (this.geometry instanceof THREE.Geometry) { + if ( this.geometry instanceof THREE.Geometry ) { for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) { @@ -252,12 +257,14 @@ THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () { THREE.SkinnedMesh.prototype.clone = function ( object ) { - if ( object === undefined ) object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture ); + if ( object === undefined ) { + + object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture ); + + } THREE.Mesh.prototype.clone.call( this, object ); return object; }; - -THREE.SkinnedMesh.offsetMatrix = new THREE.Matrix4();