2
0
Эх сурвалжийг харах

[fx] Loop refresh in editor, disabled auto loop detection

Clément Espeute 1 сар өмнө
parent
commit
7750c0ee5f

+ 5 - 1
hide/view/FXEditor.hx

@@ -753,6 +753,10 @@ class FXEditor extends hide.view.FileView {
 			afterPan(false);
 			data.refreshObjectAnims();
 			rebuildAnimPanel();
+			var fx3d = Std.downcast((cast data : hrt.prefab.Prefab).findFirstLocal3d(), hrt.prefab.fx.FX.FXAnimation);
+			if (fx3d != null) {
+				fx3d.initLoop();
+			}
 		}
 
 		if (pname == "parameters") {
@@ -1759,7 +1763,7 @@ class FXEditor extends hide.view.FileView {
 				var localDt = scene.speed * dt;
 				var nextTime = currentTime + localDt;
 				if (nextTime > fx.duration) {
-					if (!fx.loop) {
+					if (!fx.loop || fx.playState == End) {
 						nextTime = 0;
 						localDt = 0;
 						hasJumped = true;

+ 18 - 1
hrt/prefab/fx/Event.hx

@@ -35,7 +35,17 @@ class Event extends hrt.prefab.Prefab implements IEvent {
 	}
 
 	function set_time(v) {
-		return time = v;
+		time = v;
+		#if editor
+		if (this.name.toLowerCase() == "loop" || this.name.toLowerCase() == "end") {
+			var fx3d = Std.downcast(getRoot().findFirstLocal3d(), hrt.prefab.fx.FX.FXAnimation);
+			if (fx3d != null) {
+				fx3d.initLoop();
+			}
+		}
+		#end
+
+		return time;
 	}
 
 	public function getDuration() {
@@ -133,6 +143,13 @@ class Event extends hrt.prefab.Prefab implements IEvent {
 
 	public function setDuration(duration: Float) {
 		this.duration = duration;
+
+		if (this.name.toLowerCase() == "loop") {
+			var fx3d = Std.downcast(getRoot().findFirstLocal3d(), hrt.prefab.fx.FX.FXAnimation);
+			if (fx3d != null) {
+				fx3d.initLoop();
+			}
+		}
 	};
 
 	#end

+ 8 - 5
hrt/prefab/fx/FX.hx

@@ -22,6 +22,7 @@ class FXAnimation extends h3d.scene.Object {
 	public var loop : Bool = false;
 	public var loopStart: Float = -1;
 	public var loopEnd: Float = -1;
+	public var hasLoopPoints(default, null): Bool = false;
 	public var duration : Float;
 
 		/** Enable automatic culling based on `cullingRadius` and `cullingDistance`. Will override `culled` on every sync. **/
@@ -45,7 +46,7 @@ class FXAnimation extends h3d.scene.Object {
 	var random : hxd.Rand;
 	var randSeed : Int;
 	var firstSync = true;
-	var playState : FXPlayState = End;
+	public var playState : FXPlayState = End;
 	var stopTime : Float = -1;
 
 	public function new(?parent) {
@@ -105,15 +106,16 @@ class FXAnimation extends h3d.scene.Object {
 	}
 
 	public function initLoop() {
-		loopStart = 0.0;
+		loopStart = 0;
 		loopEnd = duration;
+		hasLoopPoints = false;
 
 		if (events == null)
 			return;
 
 		for (event in events) {
-			if (event.evt.getEventPrefab().getRoot().findFirstLocal3d() != this)
-				continue;
+			//if (event.evt.getEventPrefab().getRoot().findFirstLocal3d() != this)
+			//	continue;
 			var nameLower = event.evt.name.toLowerCase();
 			if (nameLower == "loop") {
 				loopStart = event.evt.time;
@@ -121,10 +123,11 @@ class FXAnimation extends h3d.scene.Object {
 				if (duration > 0) {
 					loopEnd = loopStart + duration;
 				}
-				loop = true;
+				hasLoopPoints = true;
 			}
 			if (nameLower == "end") {
 				loopEnd = event.evt.time;
+				hasLoopPoints = true;
 			}
 		}
 	}