Browse Source

FX: fix issues caused by culling cutting-off sync() from children, especially problematic for Skin children which need at least one sync() before draw()

trethaller 4 years ago
parent
commit
1e986d84e4
1 changed files with 16 additions and 11 deletions
  1. 16 11
      hrt/prefab/fx/FX.hx

+ 16 - 11
hrt/prefab/fx/FX.hx

@@ -16,6 +16,8 @@ class FXAnimation extends h3d.scene.Object {
 	var totalTime : Float = 0.0;
 	public var duration : Float;
 	public var additionLoopDuration : Float = 0.0;
+
+	public var enableCulling = true;
 	public var cullingRadius : Float;
 	public var cullingDistance = defaultCullingDistance;
 
@@ -34,6 +36,7 @@ class FXAnimation extends h3d.scene.Object {
 
 	var startLoop : Float = -1.0;
 	var endLoop : Float;
+	var syncedOnce = false;
 
 	public function new(?parent) {
 		super(parent);
@@ -90,21 +93,23 @@ class FXAnimation extends h3d.scene.Object {
 		var changed = posChanged;
 		if( changed ) calcAbsPos();
 
-		culled = true;
-
-		var pos = getAbsPos().getPosition();
-		tmpSphere.load(pos.x, pos.y, pos.z, cullingRadius);
-		if(!ctx.camera.frustum.hasSphere(tmpSphere))
-			return;
-
-		if(cullingDistance > 0) {
-			var distSq = ctx.camera.pos.distanceSq(pos);
-			if(distSq > cullingDistance * cullingDistance)
+		if(enableCulling && !syncedOnce) {
+			culled = true;
+			var pos = getAbsPos().getPosition();
+			tmpSphere.load(pos.x, pos.y, pos.z, cullingRadius);
+			if(!ctx.camera.frustum.hasSphere(tmpSphere))
 				return;
+
+			if(cullingDistance > 0) {
+				var distSq = ctx.camera.pos.distanceSq(pos);
+				if(distSq > cullingDistance * cullingDistance)
+					return;
+			}
+			culled = false;
 		}
 
-		culled = false;
 		super.syncRec(ctx);
+		syncedOnce = true;
 	}
 
 	override function sync( ctx : h3d.scene.RenderContext ) {