Explorar el Código

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 hace 12 años
padre
commit
7c44c5df32
Se han modificado 1 ficheros con 20 adiciones y 8 borrados
  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
+
 	}
 
 };