|
@@ -131,39 +131,49 @@ var BABYLON;
|
|
|
}
|
|
|
return false;
|
|
|
};
|
|
|
- Node.prototype._getDescendants = function (list, results, directDecendantsOnly) {
|
|
|
+ /**
|
|
|
+ * Evaluate a list of nodes and determine if they should be considered as descendants considering the given criterias
|
|
|
+ * @param {BABYLON.Node[]} list the input array of nodes to evaluate
|
|
|
+ * @param {BABYLON.Node[]} results the result array containing the nodes matching the given criterias
|
|
|
+ * @param {boolean} directDecendantsOnly if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered.
|
|
|
+ * @param predicate: an optional predicate that will be called on every evaluated children, the predicate must return true for a given child to be part of the result, otherwise it will be ignored.
|
|
|
+ */
|
|
|
+ Node.prototype._getDescendants = function (list, results, directDecendantsOnly, predicate) {
|
|
|
if (directDecendantsOnly === void 0) { directDecendantsOnly = false; }
|
|
|
for (var index = 0; index < list.length; index++) {
|
|
|
var item = list[index];
|
|
|
- if ((directDecendantsOnly && item.parent === this) || (!directDecendantsOnly && item.isDescendantOf(this))) {
|
|
|
+ if (((directDecendantsOnly && item.parent === this) || (!directDecendantsOnly && item.isDescendantOf(this))) && (predicate == null || predicate(item))) {
|
|
|
results.push(item);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
/**
|
|
|
* Will return all nodes that have this node as parent.
|
|
|
+ * @param {boolean} directDecendantsOnly if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered.
|
|
|
+ * @param predicate: an optional predicate that will be called on every evaluated children, the predicate must return true for a given child to be part of the result, otherwise it will be ignored.
|
|
|
* @return {BABYLON.Node[]} all children nodes of all types.
|
|
|
*/
|
|
|
- Node.prototype.getDescendants = function (directDecendantsOnly) {
|
|
|
+ Node.prototype.getDescendants = function (directDecendantsOnly, predicate) {
|
|
|
var results = [];
|
|
|
- this._getDescendants(this._scene.meshes, results, directDecendantsOnly);
|
|
|
- this._getDescendants(this._scene.lights, results, directDecendantsOnly);
|
|
|
- this._getDescendants(this._scene.cameras, results, directDecendantsOnly);
|
|
|
+ this._getDescendants(this._scene.meshes, results, directDecendantsOnly, predicate);
|
|
|
+ this._getDescendants(this._scene.lights, results, directDecendantsOnly, predicate);
|
|
|
+ this._getDescendants(this._scene.cameras, results, directDecendantsOnly, predicate);
|
|
|
return results;
|
|
|
};
|
|
|
/**
|
|
|
+ * @param predicate: an optional predicate that will be called on every evaluated children, the predicate must return true for a given child to be part of the result, otherwise it will be ignored.
|
|
|
* @Deprecated, legacy support.
|
|
|
* use getDecendants instead.
|
|
|
*/
|
|
|
- Node.prototype.getChildren = function () {
|
|
|
- return this.getDescendants(true);
|
|
|
+ Node.prototype.getChildren = function (predicate) {
|
|
|
+ return this.getDescendants(true, predicate);
|
|
|
};
|
|
|
/**
|
|
|
* Get all child-meshes of this node.
|
|
|
*/
|
|
|
- Node.prototype.getChildMeshes = function (directDecendantsOnly) {
|
|
|
+ Node.prototype.getChildMeshes = function (directDecendantsOnly, predicate) {
|
|
|
var results = [];
|
|
|
- this._getDescendants(this._scene.meshes, results, directDecendantsOnly);
|
|
|
+ this._getDescendants(this._scene.meshes, results, directDecendantsOnly, predicate);
|
|
|
return results;
|
|
|
};
|
|
|
Node.prototype._setReady = function (state) {
|
|
@@ -250,6 +260,6 @@ var BABYLON;
|
|
|
BABYLON.serialize()
|
|
|
], Node.prototype, "state", void 0);
|
|
|
return Node;
|
|
|
- })();
|
|
|
+ }());
|
|
|
BABYLON.Node = Node;
|
|
|
})(BABYLON || (BABYLON = {}));
|