瀏覽代碼

fixed getChildrenRoots

ncannasse 7 年之前
父節點
當前提交
57829da381
共有 1 個文件被更改,包括 18 次插入4 次删除
  1. 18 4
      hxd/prefab/ContextShared.hx

+ 18 - 4
hxd/prefab/ContextShared.hx

@@ -131,8 +131,21 @@ class ContextShared {
 		}
 	}
 
+	function getChildrenRoots( base : h3d.scene.Object, p : Prefab, out : Array<h3d.scene.Object> ) {
+		for( c in p.children ) {
+			var ctx = contexts.get(c);
+			if( ctx == null ) continue;
+			if( ctx.local3d == base )
+				getChildRoots(base, c, out);
+			else
+				out.push(ctx.local3d);
+		}
+		return out;
+	}
+
 	public function getObjects<T:h3d.scene.Object>( p : Prefab, c: Class<T> ) : Array<T> {
-		var childObjs = [for(c in p.children) { var ctx = contexts.get(c); if( ctx != null ) ctx.local3d; }];
+		var root = contexts.get(p).local3d;
+		var childObjs = getChildrenRoots(root, p, []);
 		var ret = [];
 		function rec(o : h3d.scene.Object) {
 			var m = Std.instance(o, c);
@@ -141,12 +154,13 @@ class ContextShared {
 				if( childObjs.indexOf(child) < 0 )
 					rec(child);
 		}
-		rec(contexts.get(p).local3d);
+		rec(root);
 		return ret;
 	}
 
 	public function getMaterials( p : Prefab ) {
-		var childObjs = [for(c in p.children) { var ctx = contexts.get(c); if( ctx != null ) ctx.local3d; }];
+		var root = contexts.get(p).local3d;
+		var childObjs = getChildrenRoots(root, p, []);
 		var ret = [];
 		function rec(o : h3d.scene.Object) {
 			if( o.isMesh() ) {
@@ -163,7 +177,7 @@ class ContextShared {
 				if( childObjs.indexOf(child) < 0 )
 					rec(child);
 		}
-		rec(contexts.get(p).local3d);
+		rec(root);
 		return ret;
 	}