瀏覽代碼

[animgraph] Blend space 2d now correctly remap time for null anims

Clément Espeute 8 月之前
父節點
當前提交
4cc81506dc
共有 1 個文件被更改,包括 25 次插入6 次删除
  1. 25 6
      hrt/animgraph/nodes/BlendSpace2D.hx

+ 25 - 6
hrt/animgraph/nodes/BlendSpace2D.hx

@@ -125,11 +125,13 @@ class BlendSpace2D extends AnimNode {
 	override function tick(dt:Float) {
 	override function tick(dt:Float) {
 		super.tick(dt);
 		super.tick(dt);
 
 
-		for (animInfo in animInfos) {
-			// keep all the animations in sync
-			var scale = (animInfo.anim.getDuration()) / currentAnimLenght;
-			animInfo.anim.update(dt * scale);
-			@:privateAccess animInfo.anim.isSync = false;
+		if (currentAnimLenght > 0) {
+			for (animInfo in animInfos) {
+				// keep all the animations in sync
+				var scale = (animInfo.anim.getDuration()) / currentAnimLenght;
+				animInfo.anim.update(dt * scale);
+				@:privateAccess animInfo.anim.isSync = false;
+			}
 		}
 		}
 	}
 	}
 
 
@@ -194,8 +196,25 @@ class BlendSpace2D extends AnimNode {
 				throw "assert";
 				throw "assert";
 
 
 			currentAnimLenght = 0.0;
 			currentAnimLenght = 0.0;
+
+			// Compensate for null animations that don't have lenght
+			var nulls = 0;
+			var nullWeights: Float = 0;
 			for (i => pt in triangles[currentTriangle]) {
 			for (i => pt in triangles[currentTriangle]) {
-				currentAnimLenght += pt.animInfo.anim.getDuration()/pt.speed * weights[i];
+				if (pt.animInfo == null) {
+					nulls ++;
+					nullWeights += weights[i];
+				}
+			}
+
+			if (nulls < 3) {
+				nullWeights /= (3 - nulls);
+			}
+
+			for (i => pt in triangles[currentTriangle]) {
+				if(pt.animInfo != null) {
+					currentAnimLenght += pt.animInfo.anim.getDuration()/pt.speed * weights[i] + nullWeights;
+				}
 			}
 			}
 		}
 		}