فهرست منبع

Merge pull request #1345 from nockawa/master

Canvas2D minor fix + Geometry.RandomId() moved to Tools
David Catuhe 9 سال پیش
والد
کامیت
7da11f895d
4فایلهای تغییر یافته به همراه29 افزوده شده و 24 حذف شده
  1. 7 7
      src/Canvas2d/babylon.prim2dBase.ts
  2. 3 11
      src/Canvas2d/babylon.smartPropertyPrim.ts
  3. 7 6
      src/Mesh/babylon.geometry.ts
  4. 12 0
      src/Tools/babylon.tools.ts

+ 7 - 7
src/Canvas2d/babylon.prim2dBase.ts

@@ -1725,7 +1725,7 @@
                 return;
             }
             this._position = value;
-            this.markAsDirty("actualPosition");
+            this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, value);
         }
 
         /**
@@ -1752,8 +1752,8 @@
             }
 
             this._position.x = value;
-            this.markAsDirty("position");
-            this.markAsDirty("actualPosition");
+            this._triggerPropertyChanged(Prim2DBase.positionProperty, value);
+            this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, value);
         }
 
         /**
@@ -1780,8 +1780,8 @@
             }
 
             this._position.y = value;
-            this.markAsDirty("position");
-            this.markAsDirty("actualPosition");
+            this._triggerPropertyChanged(Prim2DBase.positionProperty, value);
+            this._triggerPropertyChanged(Prim2DBase.actualPositionProperty, value);
         }
 
         private static boundinbBoxReentrency = false;
@@ -1842,7 +1842,7 @@
             }
 
             this.size.width = value;
-            this.markAsDirty("size");
+            this._triggerPropertyChanged(Prim2DBase.sizeProperty, value);
             this._positioningDirty();
         }
 
@@ -1868,7 +1868,7 @@
             }
 
             this.size.height = value;
-            this.markAsDirty("size");
+            this._triggerPropertyChanged(Prim2DBase.sizeProperty, value);
             this._positioningDirty();
         }
 

+ 3 - 11
src/Canvas2d/babylon.smartPropertyPrim.ts

@@ -316,25 +316,16 @@
             return false;
         }
 
-        private static propChangedInfo = new PropertyChangedInfo();
-
-        public markAsDirty(propertyName: string) {
+        protected _triggerPropertyChanged(propInfo: Prim2DPropInfo, newValue: any) {
             if (this.isDisposed) {
                 return;
             }
 
-            let i = propertyName.indexOf(".");
-            if (i !== -1) {
-                propertyName = propertyName.substr(0, i);
-            }
-
-            var propInfo = this.propDic.get(propertyName);
             if (!propInfo) {
                 return;
             }
 
-            var newValue = this[propertyName];
-            this._handlePropChanged(undefined, newValue, propertyName, propInfo, propInfo.typeLevelCompare);
+            this._handlePropChanged(undefined, newValue, propInfo.name, propInfo, propInfo.typeLevelCompare);
         }
 
         protected _boundingBoxDirty() {
@@ -361,6 +352,7 @@
             }
         }
 
+        private static propChangedInfo = new PropertyChangedInfo();
         private _handlePropChanged<T>(curValue: T, newValue: T, propName: string, propInfo: Prim2DPropInfo, typeLevelCompare: boolean) {
             // If the property change also dirty the boundingInfo, update the boundingInfo dirty flags
             if (propInfo.dirtyBoundingInfo) {

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

@@ -632,13 +632,14 @@
             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 {
-            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 {

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

@@ -750,6 +750,18 @@
             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
         private static _NoneLogLevel = 0;
         private static _MessageLogLevel = 1;