|
@@ -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/
|
|
|
*/
|