Ver Fonte

Fix SkinnedMesh so that it can be used with BufferGeometry

THREE.SkinnedMesh previously assumed its geometry was an instance of THREE.Geometry while normalizing skinning weights
crobi há 12 anos atrás
pai
commit
7c44c5df32
1 ficheiros alterados com 20 adições e 8 exclusões
  1. 20 8
      src/objects/SkinnedMesh.js

+ 20 - 8
src/objects/SkinnedMesh.js

@@ -216,24 +216,36 @@ 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.multiplyScalar( scale );
+
+			} else {
+
+				sw.set( 1 ); // this will be normalized by the shader anyway
 
-			sw.set( 1 ); // this will be normalized by the shader anyway
+			}
 
 		}
 
+	} else {
+
+		// skinning weights assumed to be normalized for THREE.BufferGeometry
+
 	}
 
 };