diff --git a/hrt/prefab/Material.hx b/hrt/prefab/Material.hx index 880ca457..7b02b5ae 100644 --- a/hrt/prefab/Material.hx +++ b/hrt/prefab/Material.hx @@ -20,8 +20,6 @@ class Material extends Prefab { @:s public var refMatLib : String; @:s public var overrides : Array = []; - public var filterObj : h3d.scene.Object -> Bool; - #if editor var previewSphere : h3d.scene.Object; var gradientFollower : GradientFollower; @@ -65,7 +63,7 @@ class Material extends Prefab { return r; } - public function getMaterials(local3d: h3d.scene.Object = null, includePreviewMats : Bool = false) { + public function getMaterials(local3d: h3d.scene.Object = null, includePreviewMats : Bool = false, filterObj : (obj : h3d.scene.Object) -> Bool = null) { if (local3d == null) local3d = findFirstLocal3d(); var mats = []; diff --git a/hrt/prefab/MaterialSelector.hx b/hrt/prefab/MaterialSelector.hx index 95087a86..1dfc8999 100644 --- a/hrt/prefab/MaterialSelector.hx +++ b/hrt/prefab/MaterialSelector.hx @@ -15,9 +15,8 @@ class MaterialSelector extends hrt.prefab.Prefab { passName : "all", }]; @:s public var blendModesSelected : Array = []; - public var filterObj : h3d.scene.Object -> Bool; - public function getPasses(local3d: h3d.scene.Object = null) : Array { + public function getPasses(local3d: h3d.scene.Object = null, filterObj : (obj : h3d.scene.Object) -> Bool = null) : Array { if (local3d == null) local3d = findFirstLocal3d(); var mats = []; diff --git a/hrt/prefab/Shader.hx b/hrt/prefab/Shader.hx index 257a6b85..f9749ab7 100644 --- a/hrt/prefab/Shader.hx +++ b/hrt/prefab/Shader.hx @@ -14,7 +14,6 @@ class Shader extends Prefab { @:s var recursiveApply = true; public var shader : hxsl.Shader; - public var filterObj : h3d.scene.Object -> Bool; function new(parent, sh: ContextShared) { super(parent, sh); @@ -100,31 +99,23 @@ class Shader extends Prefab { return targetMaterial == null || targetMaterial == mat.name; } - function iterMaterials(callb) { + function iterMaterials(callb, filterObj : (obj : h3d.scene.Object) -> Bool = null) { if (parent == null) return; var parent = parent; if( Std.isOfType(parent, Material) ) { var material : Material = cast parent; - var prevFilterObj = material.filterObj; - if ( filterObj != null ) - material.filterObj = filterObj; - for( m in material.getMaterials(true) ) + for( m in material.getMaterials(true, filterObj) ) callb(null, m); - material.filterObj = prevFilterObj; } else if ( Std.isOfType(parent, MaterialSelector) ) { var materialSelector = cast(parent, MaterialSelector); - var prevFilterObj = materialSelector.filterObj; - if ( filterObj != null ) - materialSelector.filterObj = filterObj; var passSelect = h3d.mat.MaterialSetup.current.createMaterial(); - for ( p in materialSelector.getPasses() ) { + for ( p in materialSelector.getPasses(null, filterObj) ) { passSelect.name = p.all ? "" : PASS_SELECT; @:privateAccess passSelect.passes = p.pass; callb(null, passSelect); } - materialSelector.filterObj = prevFilterObj; } else { var objs = []; function pushUnique(obj : h3d.scene.Object ) { @@ -156,13 +147,12 @@ class Shader extends Prefab { override function dispose() { if( shared.current3d != null ) iterMaterials(function(obj,mat) if(checkMaterial(mat)) removeShader(obj, mat, shader)); - filterObj = null; super.dispose(); } - public function apply3d() { + public function apply3d(filterObj : (obj : h3d.scene.Object) -> Bool = null) { if( shared.current3d != null ) - iterMaterials(function(obj,mat) if(checkMaterial(mat)) applyShader(obj, mat, shader)); + iterMaterials(function(obj,mat) if(checkMaterial(mat)) applyShader(obj, mat, shader), filterObj); } override function makeInstance() { diff --git a/hrt/prefab/fx/ShaderTarget.hx b/hrt/prefab/fx/ShaderTarget.hx index 7ee8b360..8b280e0d 100644 --- a/hrt/prefab/fx/ShaderTarget.hx +++ b/hrt/prefab/fx/ShaderTarget.hx @@ -6,15 +6,30 @@ class ShaderTargetObj extends h3d.scene.Object { public var shadersRoot : hrt.prefab.Object3D; public function apply(fx : hrt.prefab.fx.FX) { + function reparentChildren(obj : hrt.prefab.Object3D) { + var i = obj.children.length; + while ( i-- > 0 ) { + var c = obj.children[i]; + if ( Std.isOfType(c, Shader) || Std.isOfType(c, Material) || Std.isOfType(c, MaterialSelector) ) + c.parent = shadersRoot; + } + } + + var children = shadersRoot.children.copy(); + shadersRoot.children = []; + for (c in children) { + if (Std.isOfType(c, Object3D)) + reparentChildren(cast c); + } + var fxAnim : hrt.prefab.fx.FX.FXAnimation = cast fx.local3d; shadersRoot.local3d = parent; for ( s in shadersRoot.findAll(Shader) ) { - s.filterObj = o -> return o != fxAnim; if (s.shader == null) { s.makeShader(); @:privateAccess s.updateInstance(); } - s.apply3d(); + s.apply3d((o) -> return o != fxAnim); } if (fxAnim == null)