瀏覽代碼

Move Geometry.RandomId() to Tools and keep the former as a shortcut for legacy reasons.

nockawa 9 年之前
父節點
當前提交
56dda55892
共有 2 個文件被更改,包括 19 次插入6 次删除
  1. 7 6
      src/Mesh/babylon.geometry.ts
  2. 12 0
      src/Tools/babylon.tools.ts

+ 7 - 6
src/Mesh/babylon.geometry.ts

@@ -632,13 +632,14 @@
             return geometry.copy(id);
             return geometry.copy(id);
         }
         }
 
 
-        // from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
-        // be aware Math.random() could cause collisions
+        /**
+         * You should now use Tools.RandomId(), this method is still here for legacy reasons.
+         * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
+         * Be aware Math.random() could cause collisions, but:
+         * "All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide"
+         */
         public static RandomId(): string {
         public static RandomId(): string {
-            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);
-            });
+            return Tools.RandomId();
         }
         }
 
 
         public static ImportGeometry(parsedGeometry: any, mesh: Mesh): void {
         public static ImportGeometry(parsedGeometry: any, mesh: Mesh): void {

+ 12 - 0
src/Tools/babylon.tools.ts

@@ -750,6 +750,18 @@
             return false;
             return false;
         }
         }
 
 
+        /**
+         * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
+         * Be aware Math.random() could cause collisions, but:
+         * "All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide"
+         */
+        public static RandomId(): string {
+            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);
+            });
+        }
+
         // Logs
         // Logs
         private static _NoneLogLevel = 0;
         private static _NoneLogLevel = 0;
         private static _MessageLogLevel = 1;
         private static _MessageLogLevel = 1;