Procházet zdrojové kódy

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

Deltakosh před 11 roky
rodič
revize
f0861b59b6

+ 135 - 0
Babylon/Tools/babylon.andOrNotEvaluator.js

@@ -0,0 +1,135 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.AndOrNotEvaluator = BABYLON.AndOrNotEvaluator || {};
+
+    BABYLON.AndOrNotEvaluator.Eval = function (query, evaluateCallback) {
+        if (!query.match(/\([^\(\)]*\)/g)) {
+            query = BABYLON.AndOrNotEvaluator._HandleParenthesisContent(query, evaluateCallback);
+        }
+        else {
+            query = query.replace(/\([^\(\)]*\)/g, function (r) {
+                // remove parenthesis
+                r = r.slice(1, r.length - 1);
+                return BABYLON.AndOrNotEvaluator._HandleParenthesisContent(r, evaluateCallback);
+            });
+        }
+
+        if (query === "true") {
+            return true;
+        }
+
+        if (query === "false") {
+            return false;
+        }
+
+        return BABYLON.AndOrNotEvaluator.Eval(query, evaluateCallback);
+    };
+
+    BABYLON.AndOrNotEvaluator._HandleParenthesisContent = function (parenthesisContent, evaluateCallback) {
+        evaluateCallback = evaluateCallback || function (r) {
+            /*switch(r)
+            {
+                case "true":
+                    return true;
+                case "false":
+                case "0":
+                case "":
+                case "undefined":
+                case "null":
+                default:
+                    return false;
+            }*/
+            return r === "true" ? true : false;
+        };
+
+        var result;
+        var or = parenthesisContent.split("||");
+
+        for (var i in or) {
+            var ori = BABYLON.AndOrNotEvaluator._SimplifyNegation(or[i].trim());
+            var and = ori.split("&&");
+
+            if (and.length > 1) {
+                for (var j = 0; j < and.length; ++j) {
+                    var andj = BABYLON.AndOrNotEvaluator._SimplifyNegation(and[j].trim());
+                    if (andj !== "true" && andj !== "false") {
+                        if (andj[0] === "!") {
+                            result = andj.substring(1);
+                            if (evaluateCallback) {
+                                result = evaluateCallback(result);
+                            }
+                            result = !result;
+                        }
+                        else {
+                            result = andj;
+                            if (evaluateCallback) {
+                                result = evaluateCallback(result);
+                            }
+                        }
+                    }
+                    else {
+                        result = andj === "true" ? true : false;
+                    }
+                    if (!result) { // no need to continue since 'false && ... && ...' will always return false
+                        ori = "false";
+                        break;
+                    }
+                }
+            }
+
+            if (result || ori === "true") { // no need to continue since 'true || ... || ...' will always return true
+                result = true;
+                break;
+            }
+
+            // result equals false (or undefined)
+
+            if (ori !== "true" && ori !== "false") {
+                if (ori[0] === "!") {
+                    result = ori.substring(1);
+                    if (evaluateCallback) {
+                        result = evaluateCallback(result);
+                    }
+                    result = !result;
+                }
+                else {
+                    result = ori;
+                    if (evaluateCallback) {
+                        result = evaluateCallback(result);
+                    }
+                }
+            }
+            else {
+                result = ori === "true" ? true : false;
+            }
+        }
+
+        // the whole parenthesis scope is replaced by 'true' or 'false'
+        return result ? "true" : "false";
+    };
+
+    BABYLON.AndOrNotEvaluator._SimplifyNegation = function (booleanString) {
+        booleanString = booleanString.replace(/^[\s!]+/, function (r) {
+            // remove whitespaces
+            r = r.replace(/[\s]/g, function (r) {
+                return "";
+            });
+            return r.length % 2 ? "!" : "";
+        });
+
+        booleanString = booleanString.trim();
+
+        if (booleanString === "!true") {
+            booleanString = "false";
+        }
+        else if (booleanString === "!false") {
+            booleanString = "true";
+        }
+
+        return booleanString;
+    };
+
+})();

+ 97 - 0
Babylon/Tools/babylon.tags.js

@@ -0,0 +1,97 @@
+"use strict";
+
+var BABYLON = BABYLON || {};
+
+(function () {
+    BABYLON.Tags = BABYLON.Tags || {};
+
+    BABYLON.Tags.EnableFor = function (obj) {
+        obj._tags = obj._tags || {};
+
+        obj.hasTags = function () {
+            return BABYLON.Tags.HasTags(obj);
+        };
+
+        obj.addTags = function (tagsString) {
+            return BABYLON.Tags.AddTagsTo(obj, tagsString);
+        };
+
+        obj.removeTags = function (tagsString) {
+            return BABYLON.Tags.RemoveTagsFrom(obj, tagsString);
+        };
+
+        obj.matchesTagsQuery = function (tagsQuery) {
+            return BABYLON.Tags.MatchesQuery(obj, tagsQuery);
+        };
+    };
+
+    BABYLON.Tags.DisableFor = function (obj) {
+        delete obj._tags;
+        delete obj.hasTags;
+        delete obj.addTags;
+        delete obj.removeTags;
+        delete obj.matchesTagsQuery;
+    };
+
+    BABYLON.Tags.HasTags = function (obj) {
+        if (!obj._tags) {
+            return false;
+        }
+        return !BABYLON.Tools.IsEmpty(obj._tags);
+    };
+
+    // the tags 'true' and 'false' are reserved and cannot be used as tags
+    // a tag cannot start with '||', '&&', and '!'
+    // it cannot contain whitespaces
+    BABYLON.Tags.AddTagsTo = function (obj, tagsString) {
+        var tags = tagsString.split(" ");
+        for (var t in tags) {
+            BABYLON.Tags._AddTagTo(obj, tags[t]);
+        }
+    };
+
+    BABYLON.Tags._AddTagTo = function (obj, tag) {
+        tag = tag.trim();
+
+        if (tag === "" || tag === "true" || tag === "false") {
+            return;
+        }
+
+        if (tag.match(/[\s]/) || tag.match(/^([!]|([|]|[&]){2})/)) {
+            return;
+        }
+
+        BABYLON.Tags.EnableFor(obj);
+        obj._tags[tag] = true;
+    };
+
+    BABYLON.Tags.RemoveTagsFrom = function (obj, tagsString) {
+        if (!BABYLON.Tags.HasTags(obj)) {
+            return;
+        }
+        var tags = tagsString.split(" ");
+        for (var t in tags) {
+            BABYLON.Tags._RemoveTagFrom(obj, tags[t]);
+        }
+    };
+    
+
+    BABYLON.Tags._RemoveTagFrom = function (obj, tag) {
+        delete obj._tags[tag];
+    };
+
+    BABYLON.Tags.MatchesQuery = function (obj, tagsQuery) {
+        if (tagsQuery === undefined) {
+            return true;
+        }
+
+        if (tagsQuery === "") {
+            return BABYLON.Tags.HasTags(obj);
+        }
+
+        return BABYLON.AndOrNotEvaluator.Eval(tagsQuery, function (r) {
+            return BABYLON.Tags.HasTags(obj) && obj._tags[r];
+        });
+    };
+
+})();

+ 7 - 0
Babylon/Tools/babylon.tools.js

@@ -342,6 +342,13 @@ var BABYLON = BABYLON || {};
         }
     };
 
+    BABYLON.Tools.IsEmpty = function (obj) {
+        for (var i in obj) {
+            return false;
+        }
+        return true;
+    };
+
     // FPS
     var fpsRange = 60;
     var previousFramesDuration = [];

+ 21 - 0
Babylon/babylon.scene.js

@@ -1083,6 +1083,27 @@ var BABYLON = BABYLON || {};
         }
     };
 
+    // Tags
+    BABYLON.Scene.prototype.getMeshesByTags = function (tagsQuery) {
+        var meshes = this.meshes;
+
+        if (tagsQuery === undefined) { 
+            // returns all meshes (could be done with BABYLON.Tags.MatchesQuery but no need to have a for-loop here)
+            return meshes;
+        }
+
+        var meshesByTags = [];
+
+        for (var i in meshes) {
+            var mesh = meshes[i];
+            if (BABYLON.Tags.MatchesQuery(mesh, tagsQuery)) {
+                meshesByTags.push(mesh);
+            }
+        }
+
+        return meshesByTags;
+    };
+
     // Statics
     BABYLON.Scene.FOGMODE_NONE = 0;
     BABYLON.Scene.FOGMODE_EXP = 1;

+ 2 - 0
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/babylonJS.xml

@@ -76,6 +76,8 @@
   <script src="Babylon/babylon.engine.js"></script>
   <script src="Babylon/Math/babylon.axis.js"></script>
   <script src="Babylon/Math/babylon.math.js"></script>
+  <script src="Babylon/Tools/babylon.tags.js"></script>
+  <script src="Babylon/Tools/babylon.andOrNotEvaluator.js"></script>
   <script src="Babylon/Tools/babylon.tools.js"></script>
   <script src="Babylon/babylon.node.js"></script>
 </files>

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 2 - 2
Tools/BuildOurOwnBabylonJS/BuildOurOwnBabylonJS/ourOwnBabylon.js