Browse Source

Adding optional filters to ContextShared.hx and Object3D.hx getObjects functions.

clementlandrin 9 tháng trước cách đây
mục cha
commit
bf4a6d09e3

+ 3 - 1
hrt/prefab/ContextShared.hx

@@ -218,12 +218,14 @@ class ContextShared {
 		}
 		}
 	}
 	}
 
 
-	public function getObjects<T:h3d.scene.Object>( p : Prefab, c: Class<T> ) : Array<T> {
+	public function getObjects<T:h3d.scene.Object>( p : Prefab, c: Class<T>, ?filter : h3d.scene.Object -> Bool ) : Array<T> {
 		var root = p.to(Object3D)?.local3d;
 		var root = p.to(Object3D)?.local3d;
 		if(root == null) return [];
 		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) {
+			if ( filter != null && !filter(o) )
+				return;
 			var m = Std.downcast(o, c);
 			var m = Std.downcast(o, c);
 			if(m != null) {
 			if(m != null) {
 				if(ret.contains(m))
 				if(ret.contains(m))

+ 3 - 1
hrt/prefab/Object3D.hx

@@ -205,12 +205,14 @@ class Object3D extends Prefab {
 		Returns the list of all h3d.scene.Object created by this prefab (but not
 		Returns the list of all h3d.scene.Object created by this prefab (but not
 		the ones created by its children)
 		the ones created by its children)
 	**/
 	**/
-	public function getObjects<T:h3d.scene.Object>(c: Class<T> ) : Array<T> {
+	public function getObjects<T:h3d.scene.Object>(c: Class<T>, filter : h3d.scene.Object -> Bool ) : Array<T> {
 		var root = Object3D.getLocal3d(this);
 		var root = Object3D.getLocal3d(this);
 		if(root == null) return [];
 		if(root == null) return [];
 		var childObjs = Prefab.getChildrenRoots(root, this, []);
 		var childObjs = Prefab.getChildrenRoots(root, this, []);
 		var ret = [];
 		var ret = [];
 		function rec(o : h3d.scene.Object) {
 		function rec(o : h3d.scene.Object) {
+			if ( filter != null && !filter(o) )
+				return;
 			var m = Std.downcast(o, c);
 			var m = Std.downcast(o, c);
 			if(m != null) {
 			if(m != null) {
 				ret.push(m);
 				ret.push(m);