Przeglądaj źródła

New Tools.log / error / warn functions

David Catuhe 11 lat temu
rodzic
commit
ff188bfaed

+ 1 - 1
Babylon/Actions/babylon.actionManager.js

@@ -14,7 +14,7 @@
         ActionManager.prototype.registerAction = function (action) {
             if (action.trigger === ActionManager.OnEveryFrameTrigger) {
                 if (this.getScene().actionManager !== this) {
-                    console.warn("OnEveryFrameTrigger can only be used with scene.actionManager");
+                    BABYLON.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager");
                     return null;
                 }
             }

+ 1 - 1
Babylon/Actions/babylon.actionManager.ts

@@ -24,7 +24,7 @@
         public registerAction(action: Action): Action {
             if (action.trigger === ActionManager.OnEveryFrameTrigger) {
                 if (this.getScene().actionManager !== this) {
-                    console.warn("OnEveryFrameTrigger can only be used with scene.actionManager");
+                    Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager");
                     return null;
                 }
             }

+ 1 - 1
Babylon/Actions/babylon.directActions.js

@@ -58,7 +58,7 @@ var BABYLON;
             this._property = this._getProperty(this.propertyPath);
 
             if (typeof this._target[this._property] !== "number") {
-                console.warn("Warning: IncrementValueAction can only be used with number values");
+                BABYLON.Tools.Warn("Warning: IncrementValueAction can only be used with number values");
             }
         };
 

+ 1 - 1
Babylon/Actions/babylon.directActions.ts

@@ -51,7 +51,7 @@
             this._property = this._getProperty(this.propertyPath);
 
             if (typeof this._target[this._property] !== "number") {
-                console.warn("Warning: IncrementValueAction can only be used with number values");
+                Tools.Warn("Warning: IncrementValueAction can only be used with number values");
             }
         }
 

+ 1 - 1
Babylon/Actions/babylon.interpolateValueAction.js

@@ -48,7 +48,7 @@ var BABYLON;
             } else if (this.value instanceof BABYLON.Quaternion) {
                 dataType = BABYLON.Animation.ANIMATIONTYPE_QUATERNION;
             } else {
-                console.warn("InterpolateValueAction: Unsupported type (" + typeof this.value + ")");
+                BABYLON.Tools.Warn("InterpolateValueAction: Unsupported type (" + typeof this.value + ")");
                 return;
             }
 

+ 1 - 1
Babylon/Actions/babylon.interpolateValueAction.ts

@@ -39,7 +39,7 @@
             } else if (this.value instanceof Quaternion) {
                 dataType = Animation.ANIMATIONTYPE_QUATERNION;
             } else {
-                console.warn("InterpolateValueAction: Unsupported type (" + typeof this.value + ")");
+                Tools.Warn("InterpolateValueAction: Unsupported type (" + typeof this.value + ")");
                 return;
             }
 

+ 1 - 1
Babylon/Cameras/babylon.camera.js

@@ -131,7 +131,7 @@ var BABYLON;
         Camera.prototype.attachPostProcess = function (postProcess, insertAt) {
             if (typeof insertAt === "undefined") { insertAt = null; }
             if (!postProcess.isReusable() && this._postProcesses.indexOf(postProcess) > -1) {
-                console.error("You're trying to reuse a post process not defined as reusable.");
+                BABYLON.Tools.Error("You're trying to reuse a post process not defined as reusable.");
                 return 0;
             }
 

+ 1 - 1
Babylon/Cameras/babylon.camera.ts

@@ -140,7 +140,7 @@
 
         public attachPostProcess(postProcess: PostProcess, insertAt: number = null): number {
             if (!postProcess.isReusable() && this._postProcesses.indexOf(postProcess) > -1) {
-                console.error("You're trying to reuse a post process not defined as reusable.");
+                Tools.Error("You're trying to reuse a post process not defined as reusable.");
                 return 0;
             }
 

+ 1 - 1
Babylon/Culling/babylon.boundingBox.js

@@ -144,4 +144,4 @@
     })();
     BABYLON.BoundingBox = BoundingBox;
 })(BABYLON || (BABYLON = {}));
-//# sourceMappingURL=babylon.BoundingBox.js.map
+//# sourceMappingURL=babylon.boundingBox.js.map

+ 4 - 4
Babylon/Materials/babylon.effect.js

@@ -153,10 +153,10 @@
                     }
                     this._prepareEffect(vertexSourceCode, fragmentSourceCode, attributesNames, defines, optionalDefines, true);
                 } else {
-                    console.error("Unable to compile effect: " + this.name);
-                    console.error("Defines: " + defines);
-                    console.error("Optional defines: " + optionalDefines);
-                    console.error("Error: " + e.message);
+                    BABYLON.Tools.Error("Unable to compile effect: " + this.name);
+                    BABYLON.Tools.Error("Defines: " + defines);
+                    BABYLON.Tools.Error("Optional defines: " + optionalDefines);
+                    BABYLON.Tools.Error("Error: " + e.message);
                     this._compilationError = e.message;
 
                     if (this.onError) {

+ 4 - 4
Babylon/Materials/babylon.effect.ts

@@ -167,10 +167,10 @@
                     }
                     this._prepareEffect(vertexSourceCode, fragmentSourceCode, attributesNames, defines, optionalDefines, true);
                 } else {
-                    console.error("Unable to compile effect: " + this.name);
-                    console.error("Defines: " + defines);
-                    console.error("Optional defines: " + optionalDefines);
-                    console.error("Error: " + e.message);
+                    Tools.Error("Unable to compile effect: " + this.name);
+                    Tools.Error("Defines: " + defines);
+                    Tools.Error("Optional defines: " + optionalDefines);
+                    Tools.Error("Error: " + e.message);
                     this._compilationError = e.message;
 
                     if (this.onError) {

+ 10 - 13
Babylon/Mesh/babylon.geometry.js

@@ -146,7 +146,7 @@ var BABYLON;
                     result.push(kind);
                 }
             } else {
-                for (var kind in this._vertexBuffers) {
+                for (kind in this._vertexBuffers) {
                     result.push(kind);
                 }
             }
@@ -225,7 +225,6 @@ var BABYLON;
             }
 
             var meshes = this._meshes;
-            var numOfMeshes = meshes.length + 1;
 
             // must be done before setting vertexBuffers because of mesh._createGlobalSubMesh()
             mesh._geometry = this;
@@ -270,6 +269,7 @@ var BABYLON;
         };
 
         Geometry.prototype.load = function (scene, onLoaded) {
+            var _this = this;
             if (this.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADING) {
                 return;
             }
@@ -284,21 +284,18 @@ var BABYLON;
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
 
             scene._addPendingData(this);
-
-            var that = this;
-
             BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
-                that._delayLoadingFunction(JSON.parse(data), that);
+                _this._delayLoadingFunction(JSON.parse(data), _this);
 
-                that.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
-                that._delayInfo = [];
+                _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
+                _this._delayInfo = [];
 
-                scene._removePendingData(that);
+                scene._removePendingData(_this);
 
-                var meshes = that._meshes;
+                var meshes = _this._meshes;
                 var numOfMeshes = meshes.length;
                 for (var index = 0; index < numOfMeshes; index++) {
-                    that._applyToMesh(meshes[index]);
+                    _this._applyToMesh(meshes[index]);
                 }
 
                 if (onLoaded) {
@@ -365,7 +362,7 @@ var BABYLON;
             geometry.delayLoadingFile = this.delayLoadingFile;
             geometry._delayLoadingFunction = this._delayLoadingFunction;
 
-            for (var kind in this._delayInfo) {
+            for (kind in this._delayInfo) {
                 geometry._delayInfo = geometry._delayInfo || [];
                 geometry._delayInfo.push(kind);
             }
@@ -434,7 +431,7 @@ var BABYLON;
                     if (!this._beingRegenerated) {
                         return;
                     }
-                    return _super.prototype.setAllVerticesData.call(this, vertexData, false);
+                    _super.prototype.setAllVerticesData.call(this, vertexData, false);
                 };
 
                 _Primitive.prototype.setVerticesData = function (data, kind, updatable) {

+ 14 - 18
Babylon/Mesh/babylon.geometry.ts

@@ -155,7 +155,7 @@
                     result.push(kind);
                 }
             } else {
-                for (var kind in this._vertexBuffers) {
+                for (kind in this._vertexBuffers) {
                     result.push(kind);
                 }
             }
@@ -234,7 +234,6 @@
             }
 
             var meshes = this._meshes;
-            var numOfMeshes = meshes.length + 1;
 
             // must be done before setting vertexBuffers because of mesh._createGlobalSubMesh()
             mesh._geometry = this;
@@ -295,27 +294,24 @@
             this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADING;
 
             scene._addPendingData(this);
+            BABYLON.Tools.LoadFile(this.delayLoadingFile, data => {
+                this._delayLoadingFunction(JSON.parse(data), this);
 
-            var that = this;
+                this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
+                this._delayInfo = [];
 
-            BABYLON.Tools.LoadFile(this.delayLoadingFile, function (data) {
-                that._delayLoadingFunction(JSON.parse(data), that);
+                scene._removePendingData(this);
 
-                that.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
-                that._delayInfo = [];
-
-                scene._removePendingData(that);
-
-                var meshes = that._meshes;
+                var meshes = this._meshes;
                 var numOfMeshes = meshes.length;
                 for (var index = 0; index < numOfMeshes; index++) {
-                    that._applyToMesh(meshes[index]);
+                    this._applyToMesh(meshes[index]);
                 }
 
                 if (onLoaded) {
                     onLoaded();
                 }
-            }, function () { }, scene.database);
+            }, () => { }, scene.database);
         }
 
         public dispose(): void {
@@ -375,7 +371,7 @@
             geometry.delayLoadingFile = this.delayLoadingFile;
             geometry._delayLoadingFunction = this._delayLoadingFunction;
 
-            for (var kind in this._delayInfo) {
+            for (kind in this._delayInfo) {
                 geometry._delayInfo = geometry._delayInfo || [];
                 geometry._delayInfo.push(kind);
             }
@@ -401,7 +397,7 @@
         // from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
         // be aware Math.random() could cause collisions
         public static RandomId(): string {
-            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
+            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
                 var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
                 return v.toString(16);
             });
@@ -442,14 +438,14 @@
             }
 
             // overrides
-            public setAllVerticesData(vertexData: VertexData, updatable?: boolean) {
+            public setAllVerticesData(vertexData: VertexData, updatable?: boolean): void {
                 if (!this._beingRegenerated) {
                     return;
                 }
-                return super.setAllVerticesData(vertexData, false);
+                super.setAllVerticesData(vertexData, false);
             }
 
-            public setVerticesData(data: number[], kind: string, updatable?: boolean) {
+            public setVerticesData(data: number[], kind: string, updatable?: boolean): void {
                 if (!this._beingRegenerated) {
                     return;
                 }

+ 18 - 18
Babylon/Tools/babylon.database.js

@@ -42,7 +42,7 @@ var BABYLON = BABYLON || {};
 
     BABYLON.Database.prototype.checkManifestFile = function () {
         function noManifestFile() {
-            console.log("Valid manifest file not found. Scene & textures will be loaded directly from the web server.");
+            BABYLON.Tools.Log("Valid manifest file not found. Scene & textures will be loaded directly from the web server.");
             that.enableSceneOffline = false;
             that.enableTexturesOffline = false;
         };
@@ -81,7 +81,7 @@ var BABYLON = BABYLON || {};
             xhr.send();
         }
         catch (ex) {
-            console.log("Error on XHR send request.");
+            BABYLON.Tools.Error("Error on XHR send request.");
         }
     };
 
@@ -112,7 +112,7 @@ var BABYLON = BABYLON || {};
 
                 // executes when a version change transaction cannot complete due to other active transactions
                 request.onblocked = function (event) {
-                    console.log("IDB request blocked. Please reload the page.");
+                    BABYLON.Tools.Error("IDB request blocked. Please reload the page.");
                     handleError();
                 };
 
@@ -131,7 +131,7 @@ var BABYLON = BABYLON || {};
                         var texturesStore = that.db.createObjectStore("textures", { keyPath: "textureUrl" });
                     }
                     catch (ex) {
-                        console.log("Error while creating object stores. Exception: " + ex.message);
+                        BABYLON.Tools.Error("Error while creating object stores. Exception: " + ex.message);
                         handleError();
                     }
                 };
@@ -195,12 +195,12 @@ var BABYLON = BABYLON || {};
                 texture = event.target.result;
             };
             getRequest.onerror = function (event) {
-                console.log("Error loading texture " + url + " from DB.");
+                BABYLON.Tools.Error("Error loading texture " + url + " from DB.");
                 image.src = url;
             };
         }
         else {
-            console.log("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");
+            BABYLON.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");
             image.src = url;
         }
     };
@@ -283,7 +283,7 @@ var BABYLON = BABYLON || {};
                 }, false);
 
                 xhr.addEventListener("error", function (event) {
-                    console.log("Error in XHR request in BABYLON.Database.");
+                    BABYLON.Tools.Error("Error in XHR request in BABYLON.Database.");
                     image.src = url;
                 }, false);
 
@@ -294,7 +294,7 @@ var BABYLON = BABYLON || {};
             }
         }
         else {
-            console.log("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");
+            BABYLON.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");
             image.src = url;
         }
     };
@@ -344,17 +344,17 @@ var BABYLON = BABYLON || {};
                     version = event.target.result;
                 };
                 getRequest.onerror = function (event) {
-                    console.log("Error loading version for scene " + url + " from DB.");
+                    BABYLON.Tools.Error("Error loading version for scene " + url + " from DB.");
                     callback(-1);
                 };
             }
             catch (ex) {
-                console.log("Error while accessing 'versions' object store (READ OP). Exception: " + ex.message);
+                BABYLON.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: " + ex.message);
                 callback(-1);
             }
         }
         else {
-            console.log("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");
+            BABYLON.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");
             callback(-1);
         }
     };
@@ -390,11 +390,11 @@ var BABYLON = BABYLON || {};
                 addRequest.onsuccess = function (event) {
                 };
                 addRequest.onerror = function (event) {
-                    console.log("Error in DB add version request in BABYLON.Database.");
+                    BABYLON.Tools.Error("Error in DB add version request in BABYLON.Database.");
                 };
             }
             catch (ex) {
-                console.log("Error while accessing 'versions' object store (WRITE OP). Exception: " + ex.message);
+                BABYLON.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: " + ex.message);
                 callback(-1);
             }
         }
@@ -452,12 +452,12 @@ var BABYLON = BABYLON || {};
                 scene = event.target.result;
             };
             getRequest.onerror = function (event) {
-                console.log("Error loading scene " + url + " from DB.");
+                BABYLON.Tools.Error("Error loading scene " + url + " from DB.");
                 notInDBCallback();
             };
         }
         else {
-            console.log("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");
+            BABYLON.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");
             callback();
         }
     };
@@ -507,7 +507,7 @@ var BABYLON = BABYLON || {};
                             addRequest.onsuccess = function (event) {
                             };
                             addRequest.onerror = function (event) {
-                                console.log("Error in DB add scene request in BABYLON.Database.");
+                                BABYLON.Tools.Error("Error in DB add scene request in BABYLON.Database.");
                             };
                         }
                         catch (ex) {
@@ -524,14 +524,14 @@ var BABYLON = BABYLON || {};
             }, false);
 
             xhr.addEventListener("error", function (event) {
-                console.log("error on XHR request.");
+                BABYLON.Tools.Error("error on XHR request.");
                 callback();
             }, false);
 
             xhr.send();
         }
         else {
-            console.log("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");
+            BABYLON.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");
             callback();
         }
     };

+ 1 - 1
Babylon/Tools/babylon.filesInput.js

@@ -119,7 +119,7 @@ var BABYLON = BABYLON || {};
                 });
             }
             else {
-                console.log("Please provide a valid .babylon file.");
+                BABYLON.Tools.Error("Please provide a valid .babylon file.");
             }
         }
     };

+ 2 - 2
Babylon/Tools/babylon.tools.dds.js

@@ -63,12 +63,12 @@
                 var header = new Int32Array(arrayBuffer, 0, headerLengthInt), fourCC, blockBytes, internalFormat, width, height, dataLength, dataOffset, byteArray, mipmapCount, i;
 
                 if (header[off_magic] != DDS_MAGIC) {
-                    console.error("Invalid magic number in DDS header");
+                    BABYLON.Tools.Error("Invalid magic number in DDS header");
                     return;
                 }
 
                 if ((header[off_pfFlags] & DDPF_FOURCC) !== DDPF_FOURCC) {
-                    console.error("Unsupported format, must contain a FourCC code");
+                    BABYLON.Tools.Error("Unsupported format, must contain a FourCC code");
                     return;
                 }
 

+ 2 - 2
Babylon/Tools/babylon.tools.dds.ts

@@ -91,12 +91,12 @@
                 byteArray, mipmapCount, i;
 
             if (header[off_magic] != DDS_MAGIC) {
-                console.error("Invalid magic number in DDS header");
+                Tools.Error("Invalid magic number in DDS header");
                 return;
             }
 
             if ((header[off_pfFlags] & DDPF_FOURCC) !== DDPF_FOURCC) {
-                console.error("Unsupported format, must contain a FourCC code");
+                Tools.Error("Unsupported format, must contain a FourCC code");
                 return;
             }
 

+ 24 - 2
Babylon/Tools/babylon.tools.js

@@ -172,7 +172,7 @@
                         }
                         img.src = blobURL;
                     } catch (e) {
-                        console.log("Error while trying to load texture: " + textureName);
+                        Tools.Log("Error while trying to load texture: " + textureName);
                         img.src = null;
                     }
                 }
@@ -370,7 +370,7 @@
                 height = size;
                 width = size;
             } else {
-                console.error("Invalid 'size' parameter !");
+                Tools.Error("Invalid 'size' parameter !");
                 return;
             }
 
@@ -439,6 +439,28 @@
             texture.render();
             texture.dispose();
         };
+
+        // Logs
+        Tools._FormatMessage = function (message) {
+            var padStr = function (i) {
+                return (i < 10) ? "0" + i : "" + i;
+            };
+
+            var date = new Date();
+            return "BJS - [" + padStr(date.getHours()) + ":" + padStr(date.getMinutes()) + ":" + padStr(date.getSeconds()) + "]:" + message;
+        };
+
+        Tools.Log = function (message) {
+            console.log(Tools._FormatMessage(message));
+        };
+
+        Tools.Warn = function (message) {
+            console.warn(Tools._FormatMessage(message));
+        };
+
+        Tools.Error = function (message) {
+            console.error(Tools._FormatMessage(message));
+        };
         Tools.BaseUrl = "";
         return Tools;
     })();

+ 22 - 2
Babylon/Tools/babylon.tools.ts

@@ -191,7 +191,7 @@
                         img.src = blobURL;
                     }
                     catch (e) {
-                        console.log("Error while trying to load texture: " + textureName);
+                        Tools.Log("Error while trying to load texture: " + textureName);
                         img.src = null;
                     }
                 }
@@ -399,7 +399,7 @@
                 width = size;
             }
             else {
-                console.error("Invalid 'size' parameter !");
+                Tools.Error("Invalid 'size' parameter !");
                 return;
             }
 
@@ -472,5 +472,25 @@
             texture.render();
             texture.dispose();
         }
+
+        // Logs
+        private static _FormatMessage(message: string): string {
+            var padStr = i => (i < 10) ? "0" + i : "" + i;
+
+            var date = new Date();
+            return "BJS - [" + padStr(date.getHours()) + ":" + padStr(date.getMinutes()) +  ":" + padStr(date.getSeconds()) + "]:" + message;
+        }
+
+        public static Log(message: string): void {
+            console.log(Tools._FormatMessage(message));
+        }
+
+        public static Warn(message: string): void {
+            console.warn(Tools._FormatMessage(message));
+        }
+
+        public static Error(message: string): void {
+            console.error(Tools._FormatMessage(message));
+        }
     }
 } 

Plik diff jest za duży
+ 13 - 13
babylon.1.12-beta.js