2
0
Clément Espeute 1 жил өмнө
parent
commit
71c36a599f
1 өөрчлөгдсөн 23 нэмэгдсэн , 16 устгасан
  1. 23 16
      h3d/scene/Skin.hx

+ 23 - 16
h3d/scene/Skin.hx

@@ -38,28 +38,33 @@ class Joint extends Object {
 		// check if one of our parents has changed
 		// we don't have a posChanged flag since the Joint
 		// is not actualy part of the hierarchy
-		var p = parent;
-		while( p != null ) {
-			if( p.posChanged ) {
-				// save the inverse absPos that was used to build the joints absPos
-				if( skin.jointsAbsPosInv == null ) {
-					skin.jointsAbsPosInv = new h3d.Matrix();
-					skin.jointsAbsPosInv.zero();
+		if (skin.jointsAbsPosRef == null) {
+			var p : h3d.scene.Object = skin;
+			while( p != null ) {
+				if( p.posChanged ) {
+					// save the inverse absPos that was used to build the joints absPos
+					if( skin.jointsAbsPosInv == null ) {
+						skin.jointsAbsPosInv = new h3d.Matrix();
+						skin.jointsAbsPosInv.zero();
+					}
+					if( skin.jointsAbsPosInv._44 == 0 ) {
+						skin.jointsAbsPosInv.inverse3x4(p.absPos);
+					}
+					skin.jointsAbsPosRef = p;
+					this.lastFrame = -1;
+					break;
 				}
-				if( skin.jointsAbsPosInv._44 == 0 )
-					skin.jointsAbsPosInv.inverse3x4(parent.absPos);
-				parent.syncPos();
-				lastFrame = -1;
-				break;
+				p = p.parent;
 			}
-			p = p.parent;
 		}
-		if( lastFrame != skin.lastFrame ) {
+
+
+		if( lastFrame != skin.lastFrame || skin.jointsAbsPosRef != null) {
 			lastFrame = skin.lastFrame;
 			absPos.load(skin.currentAbsPose[index]);
-			if( skin.jointsAbsPosInv != null && skin.jointsAbsPosInv._44 != 0 ) {
+			if(skin.jointsAbsPosInv != null && skin.jointsAbsPosInv._44 != 0) {
 				absPos.multiply3x4(absPos, skin.jointsAbsPosInv);
-				absPos.multiply3x4(absPos, parent.absPos);
+				absPos.multiply3x4(absPos, skin.jointsAbsPosRef.getAbsPos());
 			}
 		}
 	}
@@ -74,6 +79,7 @@ class Skin extends MultiMaterial {
 	var splitPalette : Array<Array<h3d.Matrix>>;
 	var jointsUpdated : Bool;
 	var jointsAbsPosInv : h3d.Matrix;
+	var jointsAbsPosRef : h3d.scene.Object;
 	var paletteChanged : Bool;
 	var skinShader : h3d.shader.SkinBase;
 	var jointsGraphics : Graphics;
@@ -248,6 +254,7 @@ class Skin extends MultiMaterial {
 		}
 		skinShader.bonesMatrixes = currentPalette;
 		if( jointsAbsPosInv != null ) jointsAbsPosInv._44 = 0; // mark as invalid
+		if (jointsAbsPosRef != null) jointsAbsPosRef = null;
 		jointsUpdated = false;
 	}