Prechádzať zdrojové kódy

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 12 rokov pred
rodič
commit
7c44c5df32
1 zmenil súbory, kde vykonal 20 pridanie a 8 odobranie
  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
+
 	}
 
 };