Browse Source

prefab customMake (replaces limited filterChildren)

Nicolas Cannasse 4 years ago
parent
commit
02f9307ab1

+ 4 - 4
hrt/prefab/ContextShared.hx

@@ -15,10 +15,10 @@ class ContextShared {
 	public var editorDisplay : Bool;
 
 	/**
-		When make() is called on prefab, it will call filterChildren on
-		each child with current context and only make() it if returns true.
+		When make() is called on prefab, it will instead call customMake on
+		each child with current which can either intercept or call make() recursively.
 	 **/
-	public var filterChildren : Context -> Prefab -> Bool;
+	public var customMake : Context -> Prefab -> Void;
 
 	/**
 		If is a reference to another prefab file, this is the parent prefab.
@@ -108,7 +108,7 @@ class ContextShared {
 		sh.parent = { shared : this, prefab : prefab };
 		sh.cache = cache;
 		sh.shaderCache = shaderCache;
-		sh.filterChildren = filterChildren;
+		sh.customMake = customMake;
 		// own bakedData
 		// own refsContext
 		return sh;

+ 6 - 4
hrt/prefab/Prefab.hx

@@ -237,13 +237,15 @@ class Prefab {
 		}
 		ctx = makeInstance(ctx);
 		for( c in children )
-			if( filterChildren(ctx, c) )
-				c.make(ctx);
+			makeChildren(ctx, c);
 		return ctx;
 	}
 
-	function filterChildren( ctx : Context, p : Prefab ) {
-		return ctx.shared.filterChildren == null || ctx.shared.filterChildren(ctx, p);
+	function makeChildren( ctx : Context, p : Prefab ) {
+		if( ctx.shared.customMake == null )
+			p.make(ctx);
+		else
+			ctx.shared.customMake(ctx, p);
 	}
 
 	/**

+ 4 - 7
hrt/prefab/Reference.hx

@@ -87,8 +87,7 @@ class Reference extends Object3D {
 			ctx = super.makeInstance(ctx);
 			var prevShared = ctx.shared;
 			ctx.shared = ctx.shared.cloneRef(this, refpath.substr(1));
-			if( filterChildren(ctx, p) )
-				p.make(ctx);
+			makeChildren(ctx, p);
 			ctx.shared = prevShared;
 
 			#if editor
@@ -107,11 +106,9 @@ class Reference extends Object3D {
 		else {
 			ctx = ctx.clone(this);
 			ctx.isSceneReference = true;
-			if( filterChildren(ctx,p) ) {
-				var refCtx = p.make(ctx);
-				ctx.local3d = refCtx.local3d;
-				updateInstance(ctx);
-			}
+			var refCtx = p.make(ctx); // no customMake here
+			ctx.local3d = refCtx.local3d;
+			updateInstance(ctx);
 		}
 
 		return ctx;

+ 2 - 4
hrt/prefab/fx/Emitter.hx

@@ -1068,14 +1068,12 @@ class Emitter extends Object3D {
 	function refreshChildren(ctx: Context) {
 		// Don't make all children, which are used to setup particles
 		for( c in children ) {
-			if( !filterChildren(ctx,c) )
-				continue;
 			var shader = Std.downcast(c, hrt.prefab.Shader);
 			if( shader != null )
-				shader.make(ctx);
+				makeChildren(ctx, shader);
 			var lit = Std.downcast(c, hrt.prefab.pbr.ParticleLit);
 			if( lit != null )
-				lit.make(ctx);
+				makeChildren(ctx, lit);
 		}
 	}
 

+ 2 - 2
hrt/prefab/fx/FX.hx

@@ -401,8 +401,8 @@ class FX extends BaseFX {
 		if(root != null){
 			for( c in root.children ) {
 				var co = Std.downcast(c , Constraint);
-				if( co == null && filterChildren(ctx,c) )
-					c.make(ctx);
+				if( co == null )
+					makeChildren(ctx,c);
 			}
 		}
 		else

+ 1 - 2
hrt/prefab/fx/FX2D.hx

@@ -255,8 +255,7 @@ class FX2D extends BaseFX {
 		var root = getFXRoot(ctx, this);
 		if( root != null ) {
 			for( c in root.children )
-				if( filterChildren(ctx, c) )
-					c.make(ctx);
+				makeChildren(ctx, c);
 		} else
 			super.make(ctx);
 		#end