Browse Source

Merge pull request #387 from gwenael-hagenmuller/forEachTag

Added optional parameter to Scene::getXXXByTags functions.
David Catuhe 10 years ago
parent
commit
f2353c22bc
2 changed files with 26 additions and 18 deletions
  1. 14 9
      Babylon/babylon.scene.js
  2. 12 9
      Babylon/babylon.scene.ts

+ 14 - 9
Babylon/babylon.scene.js

@@ -1718,7 +1718,7 @@
         };
 
         // Tags
-        Scene.prototype._getByTags = function (list, tagsQuery) {
+        Scene.prototype._getByTags = function (list, tagsQuery, forEach) {
             if (tagsQuery === undefined) {
                 // returns the complete list (could be done with BABYLON.Tags.MatchesQuery but no need to have a for-loop here)
                 return list;
@@ -1726,30 +1726,35 @@
 
             var listByTags = [];
 
+            forEach = forEach || (function (item) {
+                return;
+            });
+
             for (var i in list) {
                 var item = list[i];
                 if (BABYLON.Tags.MatchesQuery(item, tagsQuery)) {
                     listByTags.push(item);
+                    forEach(item);
                 }
             }
 
             return listByTags;
         };
 
-        Scene.prototype.getMeshesByTags = function (tagsQuery) {
-            return this._getByTags(this.meshes, tagsQuery);
+        Scene.prototype.getMeshesByTags = function (tagsQuery, forEach) {
+            return this._getByTags(this.meshes, tagsQuery, forEach);
         };
 
-        Scene.prototype.getCamerasByTags = function (tagsQuery) {
-            return this._getByTags(this.cameras, tagsQuery);
+        Scene.prototype.getCamerasByTags = function (tagsQuery, forEach) {
+            return this._getByTags(this.cameras, tagsQuery, forEach);
         };
 
-        Scene.prototype.getLightsByTags = function (tagsQuery) {
-            return this._getByTags(this.lights, tagsQuery);
+        Scene.prototype.getLightsByTags = function (tagsQuery, forEach) {
+            return this._getByTags(this.lights, tagsQuery, forEach);
         };
 
-        Scene.prototype.getMaterialByTags = function (tagsQuery) {
-            return this._getByTags(this.materials, tagsQuery).concat(this._getByTags(this.multiMaterials, tagsQuery));
+        Scene.prototype.getMaterialByTags = function (tagsQuery, forEach) {
+            return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
         };
         Scene.FOGMODE_NONE = 0;
         Scene.FOGMODE_EXP = 1;

+ 12 - 9
Babylon/babylon.scene.ts

@@ -1819,7 +1819,7 @@
         }
 
         // Tags
-        private _getByTags(list: any[], tagsQuery: string): any[] {
+        private _getByTags(list: any[], tagsQuery: string, forEach?: (item: any) => void): any[] {
             if (tagsQuery === undefined) {
                 // returns the complete list (could be done with BABYLON.Tags.MatchesQuery but no need to have a for-loop here)
                 return list;
@@ -1827,30 +1827,33 @@
 
             var listByTags = [];
 
+            forEach = forEach || ((item: any) => { return; });
+
             for (var i in list) {
                 var item = list[i];
                 if (Tags.MatchesQuery(item, tagsQuery)) {
                     listByTags.push(item);
+                    forEach(item);
                 }
             }
 
             return listByTags;
         }
 
-        public getMeshesByTags(tagsQuery: string): Mesh[] {
-            return this._getByTags(this.meshes, tagsQuery);
+        public getMeshesByTags(tagsQuery: string, forEach?: (mesh: AbstractMesh) => void): Mesh[] {
+            return this._getByTags(this.meshes, tagsQuery, forEach);
         }
 
-        public getCamerasByTags(tagsQuery: string): Camera[] {
-            return this._getByTags(this.cameras, tagsQuery);
+        public getCamerasByTags(tagsQuery: string, forEach?: (camera: Camera) => void): Camera[] {
+            return this._getByTags(this.cameras, tagsQuery, forEach);
         }
 
-        public getLightsByTags(tagsQuery: string): Light[] {
-            return this._getByTags(this.lights, tagsQuery);
+        public getLightsByTags(tagsQuery: string, forEach?: (light: Light) => void): Light[] {
+            return this._getByTags(this.lights, tagsQuery, forEach);
         }
 
-        public getMaterialByTags(tagsQuery: string): Material[] {
-            return this._getByTags(this.materials, tagsQuery).concat(this._getByTags(this.multiMaterials, tagsQuery));
+        public getMaterialByTags(tagsQuery: string, forEach?: (material: Material) => void): Material[] {
+            return this._getByTags(this.materials, tagsQuery, forEach).concat(this._getByTags(this.multiMaterials, tagsQuery, forEach));
         }
     }
 }