Explorar el Código

DynamicBones: manage huge dt

lviguier hace 6 meses
padre
commit
75906ff36f
Se han modificado 2 ficheros con 9 adiciones y 1 borrados
  1. 1 0
      h3d/anim/Skin.hx
  2. 8 1
      h3d/scene/Skin.hx

+ 1 - 0
h3d/anim/Skin.hx

@@ -40,6 +40,7 @@ class Joint {
 
 class DynamicJoint extends Joint {
 	public static var SLEEP_THRESHOLD : Float = 0.0001;
+	public static var MAX_THRESHOLD : Float = 1 * 10e5;
 
 	// Global parameters
 	public var globalForce : Vector = new Vector(0.0, 0.0, 0.0);

+ 8 - 1
h3d/scene/Skin.hx

@@ -181,8 +181,15 @@ class DynamicJointData extends JointData {
 
 		// Damping (inertia attenuation)
 		jData.speed *= 1.0 - j.damping;
+
 		if (jData.speed.lengthSq() > DynamicJoint.SLEEP_THRESHOLD)
-			newWorldPos.load(newWorldPos + jData.speed * hxd.Timer.dt);
+			newWorldPos.load(newWorldPos + jData.speed * hxd.Math.clamp(hxd.Timer.dt, 0, hxd.Timer.maxDeltaTime));
+
+		if (jData.speed.lengthSq() > DynamicJoint.MAX_THRESHOLD) {
+			newWorldPos.load(jData.currentAbsPose.getPosition());
+			absPos.load(jData.currentAbsPose);
+			jData.speed.set(0, 0, 0);
+		}
 
 		// Stiffness (shape keeper)
 		Skin.TMP_MAT.multiply(relPos, skin.jointsData[j.parent.index].currentAbsPose);