Browse Source

fix getObjects returning parent objects for prefab.Shaders, causing shaders to be applied twice

trethaller 4 years ago
parent
commit
cf19e3ae71
1 changed files with 20 additions and 9 deletions
  1. 20 9
      hrt/prefab/ContextShared.hx

+ 20 - 9
hrt/prefab/ContextShared.hx

@@ -269,16 +269,29 @@ class ContextShared {
 		return out;
 		return out;
 	}
 	}
 
 
-	public function getObjects<T:h3d.scene.Object>( p : Prefab, c: Class<T> ) : Array<T> {
+	public function getSelfObject( p : Prefab ) : h3d.scene.Object {
 		var ctx = contexts.get(p);
 		var ctx = contexts.get(p);
-		if( ctx == null )
-			return [];
-		var root = ctx.local3d;
+		if(ctx == null) return null;
+
+		var parentCtx = p.parent != null ? contexts.get(p.parent) : null;
+		if(parentCtx != null && ctx.local3d == parentCtx.local3d)
+			return null;
+
+		return ctx.local3d;
+	}
+
+	public function getObjects<T:h3d.scene.Object>( p : Prefab, c: Class<T> ) : Array<T> {
+		var root = getSelfObject(p);
+		if(root == null) return [];
 		var childObjs = getChildrenRoots(root, p, []);
 		var childObjs = getChildrenRoots(root, p, []);
 		var ret = [];
 		var ret = [];
 		function rec(o : h3d.scene.Object) {
 		function rec(o : h3d.scene.Object) {
 			var m = Std.downcast(o, c);
 			var m = Std.downcast(o, c);
-			if(m != null) ret.push(m);
+			if(m != null) {
+				if(ret.contains(m))
+					throw "?!";
+				ret.push(m);
+			}
 			for( child in o )
 			for( child in o )
 				if( childObjs.indexOf(child) < 0 )
 				if( childObjs.indexOf(child) < 0 )
 					rec(child);
 					rec(child);
@@ -288,10 +301,8 @@ class ContextShared {
 	}
 	}
 
 
 	public function getMaterials( p : Prefab ) {
 	public function getMaterials( p : Prefab ) {
-		var ctx = contexts.get(p);
-		if( ctx == null )
-			return [];
-		var root = ctx.local3d;
+		var root = getSelfObject(p);
+		if(root == null) return [];
 		var childObjs = getChildrenRoots(root, p, []);
 		var childObjs = getChildrenRoots(root, p, []);
 		var ret = [];
 		var ret = [];
 		function rec(o : h3d.scene.Object) {
 		function rec(o : h3d.scene.Object) {