Browse Source

Merge remote-tracking branch 'remotes/apendua/anima' into newskin

alteredq 13 years ago
parent
commit
4080d9b85c
2 changed files with 25 additions and 3 deletions
  1. 6 0
      src/core/Vector4.js
  2. 19 3
      src/objects/SkinnedMesh.js

+ 6 - 0
src/core/Vector4.js

@@ -142,6 +142,12 @@ THREE.Vector4.prototype = {
 		return Math.sqrt( this.lengthSq() );
 
 	},
+	
+	lengthManhattan: function () {
+
+		return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
+
+	},
 
 	normalize: function () {
 

+ 19 - 3
src/objects/SkinnedMesh.js

@@ -218,8 +218,24 @@ THREE.SkinnedMesh.prototype.updateMatrixWorld = function ( force ) {
 THREE.SkinnedMesh.prototype.pose = function() {
 
 	this.updateMatrixWorld( true );
-	
-	// TODO: decide if we need to normalize weights here; for now it's
-	//  done automatically by shader (as a byproduct of using vec4 arithmetic)
+		
+	for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
 
+		// normalize weights
+
+		var sw = this.geometry.skinWeights[ i ];
+		
+		var scale = 1.0 / sw.lengthManhattan();
+		
+		if ( scale != Infinity ) {
+		
+			sw.multiplyScalar( scale );
+			
+		} else {
+		
+			sw.set( 1 ); // this will be normalized by the shader anyway
+			
+		}
+	}
 };
+