瀏覽代碼

Updated for unknown type.

Temechon 8 年之前
父節點
當前提交
c4b7bd4242

File diff suppressed because it is too large
+ 2 - 2
dist/preview release/inspector/babylon.inspector.bundle.js


+ 29 - 0
dist/preview release/inspector/babylon.inspector.d.ts

@@ -46,58 +46,77 @@ declare module INSPECTOR {
 declare module INSPECTOR {
     const PROPERTIES: {
         format: (obj: any) => any;
+        'type_not_defined': {
+            properties: any[];
+            format: () => string;
+        };
         'Vector2': {
+            type: typeof BABYLON.Vector2;
             properties: string[];
             format: (vec: BABYLON.Vector2) => string;
         };
         'Vector3': {
+            type: typeof BABYLON.Vector3;
             properties: string[];
             format: (vec: BABYLON.Vector3) => string;
         };
         'Color3': {
+            type: typeof BABYLON.Color3;
             properties: string[];
             format: (color: BABYLON.Color3) => string;
         };
         'Quaternion': {
+            type: typeof BABYLON.Quaternion;
             properties: string[];
         };
         'Size': {
+            type: typeof BABYLON.Size;
             properties: string[];
             format: (size: BABYLON.Size) => string;
         };
         'Texture': {
+            type: typeof BABYLON.Texture;
             properties: string[];
         };
         'ArcRotateCamera': {
             properties: string[];
         };
         'Scene': {
+            type: typeof BABYLON.Scene;
             properties: string[];
         };
         'Mesh': {
+            type: typeof BABYLON.Mesh;
             properties: string[];
             format: (m: BABYLON.Mesh) => string;
         };
         'StandardMaterial': {
+            type: typeof BABYLON.StandardMaterial;
             properties: string[];
             format: (mat: BABYLON.StandardMaterial) => string;
         };
         'PrimitiveAlignment': {
+            type: typeof BABYLON.PrimitiveAlignment;
             properties: string[];
         };
         'PrimitiveThickness': {
+            type: typeof BABYLON.PrimitiveThickness;
             properties: string[];
         };
         'BoundingInfo2D': {
+            type: typeof BABYLON.BoundingInfo2D;
             properties: string[];
         };
         'SolidColorBrush2D': {
+            type: typeof BABYLON.SolidColorBrush2D;
             properties: string[];
         };
         'GradientColorBrush2D': {
+            type: typeof BABYLON.GradientColorBrush2D;
             properties: string[];
         };
         'PBRMaterial': {
+            type: typeof BABYLON.PBRMaterial;
             properties: string[];
         };
     };
@@ -485,6 +504,16 @@ declare module INSPECTOR {
          */
         static GET_TYPE(obj: any): string;
         /**
+         * Check if some properties are defined for the given type.
+         */
+        private static _CheckIfTypeExists(type);
+        /**
+         * Returns the name of the type of the given object, where the name
+         * is in PROPERTIES constant.
+         * Returns 'Undefined' if no type exists for this object
+         */
+        private static _GetTypeFor(obj);
+        /**
          * Returns the name of a function (workaround to get object type for IE11)
          */
         private static _GetFnName(fn);

+ 56 - 4
dist/preview release/inspector/babylon.inspector.js

@@ -167,7 +167,7 @@ var INSPECTOR;
          * If a format function exists, returns the result of this function.
          * If this function doesn't exists, return the object type instead */
         format: function (obj) {
-            var type = INSPECTOR.Helpers.GET_TYPE(obj) || 'default';
+            var type = INSPECTOR.Helpers.GET_TYPE(obj) || 'type_not_defined';
             if (INSPECTOR.PROPERTIES[type] && INSPECTOR.PROPERTIES[type].format) {
                 return INSPECTOR.PROPERTIES[type].format(obj);
             }
@@ -175,26 +175,36 @@ var INSPECTOR;
                 return INSPECTOR.Helpers.GET_TYPE(obj);
             }
         },
+        'type_not_defined': {
+            properties: [],
+            format: function () { return ''; }
+        },
         'Vector2': {
+            type: BABYLON.Vector2,
             properties: ['x', 'y'],
             format: function (vec) { return "x:" + INSPECTOR.Helpers.Trunc(vec.x) + ", y:" + INSPECTOR.Helpers.Trunc(vec.y); }
         },
         'Vector3': {
+            type: BABYLON.Vector3,
             properties: ['x', 'y', 'z'],
             format: function (vec) { return "x:" + INSPECTOR.Helpers.Trunc(vec.x) + ", y:" + INSPECTOR.Helpers.Trunc(vec.y) + ", z:" + INSPECTOR.Helpers.Trunc(vec.z); }
         },
         'Color3': {
+            type: BABYLON.Color3,
             properties: ['r', 'g', 'b'],
             format: function (color) { return "R:" + color.r + ", G:" + color.g + ", B:" + color.b; }
         },
         'Quaternion': {
+            type: BABYLON.Quaternion,
             properties: ['x', 'y', 'z', 'w']
         },
         'Size': {
+            type: BABYLON.Size,
             properties: ['width', 'height'],
             format: function (size) { return "Size - w:" + INSPECTOR.Helpers.Trunc(size.width) + ", h:" + INSPECTOR.Helpers.Trunc(size.height); }
         },
         'Texture': {
+            type: BABYLON.Texture,
             properties: [
                 'hasAlpha',
                 'level',
@@ -211,12 +221,15 @@ var INSPECTOR;
             ],
         },
         'ArcRotateCamera': {
+            // type: BABYLON.ArcRotateCamera,
             properties: ['alpha', 'beta', 'radius']
         },
         'Scene': {
+            type: BABYLON.Scene,
             properties: ['actionManager', 'activeCamera', 'ambientColor', 'clearColor']
         },
         'Mesh': {
+            type: BABYLON.Mesh,
             properties: [
                 'name',
                 'position',
@@ -228,6 +241,7 @@ var INSPECTOR;
             format: function (m) { return m.name; }
         },
         'StandardMaterial': {
+            type: BABYLON.StandardMaterial,
             properties: [
                 'name',
                 'alpha',
@@ -261,21 +275,27 @@ var INSPECTOR;
             format: function (mat) { return mat.name; }
         },
         'PrimitiveAlignment': {
+            type: BABYLON.PrimitiveAlignment,
             properties: ['horizontal', 'vertical']
         },
         'PrimitiveThickness': {
+            type: BABYLON.PrimitiveThickness,
             properties: ['topPixels', 'leftPixels', 'rightPixels', 'bottomPixels']
         },
         'BoundingInfo2D': {
+            type: BABYLON.BoundingInfo2D,
             properties: ['radius', 'center', 'extent']
         },
         'SolidColorBrush2D': {
+            type: BABYLON.SolidColorBrush2D,
             properties: ['color']
         },
         'GradientColorBrush2D': {
+            type: BABYLON.GradientColorBrush2D,
             properties: ['color1', 'color2', 'translation', 'rotation', 'scale']
         },
         'PBRMaterial': {
+            type: BABYLON.PBRMaterial,
             properties: [
                 'name',
                 'albedoColor',
@@ -1195,7 +1215,7 @@ var INSPECTOR;
          * Returns true if the value is null
          */
         PropertyLine.prototype._isSimple = function () {
-            if (this.value != null) {
+            if (this.value != null && this.type !== 'type_not_defined') {
                 if (PropertyLine._SIMPLE_TYPE.indexOf(this.type) == -1) {
                     // complex type : return the type name
                     return false;
@@ -1581,11 +1601,41 @@ var INSPECTOR;
                         classname = this._GetFnName(obj.constructor);
                     }
                 }
+                // If the class name has no matching properties, check every type
+                if (!this._CheckIfTypeExists(classname)) {
+                    return this._GetTypeFor(obj);
+                }
                 return classname;
             }
             else {
-                return '';
+                return 'type_not_defined';
+            }
+        };
+        /**
+         * Check if some properties are defined for the given type.
+         */
+        Helpers._CheckIfTypeExists = function (type) {
+            var properties = INSPECTOR.PROPERTIES[type];
+            if (properties) {
+                return true;
             }
+            return false;
+        };
+        /**
+         * Returns the name of the type of the given object, where the name
+         * is in PROPERTIES constant.
+         * Returns 'Undefined' if no type exists for this object
+         */
+        Helpers._GetTypeFor = function (obj) {
+            for (var type in INSPECTOR.PROPERTIES) {
+                var typeBlock = INSPECTOR.PROPERTIES[type];
+                if (typeBlock.type) {
+                    if (obj instanceof typeBlock.type) {
+                        return type;
+                    }
+                }
+            }
+            return 'type_not_defined';
         };
         /**
          * Returns the name of a function (workaround to get object type for IE11)
@@ -3139,7 +3189,9 @@ var INSPECTOR;
             // Type
             var type = INSPECTOR.Inspector.DOCUMENT.createElement('span');
             type.className = 'property-type';
-            type.textContent = ' - ' + this._adapter.type();
+            if (this._adapter.type() !== 'type_not_defined') {
+                type.textContent = ' - ' + this._adapter.type();
+            }
             this._div.appendChild(type);
             this._lineContent = INSPECTOR.Helpers.CreateDiv('line-content', this._div);
             this._addEvent();

File diff suppressed because it is too large
+ 2 - 2
dist/preview release/inspector/babylon.inspector.min.js


+ 1 - 1
inspector/src/details/PropertyLine.ts

@@ -304,7 +304,7 @@ module INSPECTOR {
          * Returns true if the value is null
          */
         private _isSimple() : boolean {
-            if (this.value != null) {
+            if (this.value != null && this.type !== 'type_not_defined') {
                 if (PropertyLine._SIMPLE_TYPE.indexOf(this.type) == -1) {
                     // complex type : return the type name
                     return false;

+ 32 - 1
inspector/src/helpers/Helpers.ts

@@ -16,12 +16,43 @@ module INSPECTOR {
                         classname = this._GetFnName(obj.constructor);
                     }
                 }
+                // If the class name has no matching properties, check every type
+                if (!this._CheckIfTypeExists(classname)) {
+                    return this._GetTypeFor(obj);
+                }
                 return classname;
             } else {
-                return '';
+                return 'type_not_defined';
             }
         }
+        
+        /**
+         * Check if some properties are defined for the given type.
+         */
+        private static _CheckIfTypeExists(type:string) {
+            let properties = PROPERTIES[type];
+            if (properties) {
+                return true;
+            } 
+            return false;
+        }
 
+        /** 
+         * Returns the name of the type of the given object, where the name 
+         * is in PROPERTIES constant.
+         * Returns 'Undefined' if no type exists for this object
+         */
+        private static _GetTypeFor(obj:any) {
+            for (let type in PROPERTIES) {
+                let typeBlock = PROPERTIES[type];
+                if (typeBlock.type) {
+                    if (obj instanceof typeBlock.type) {
+                        return type;
+                    }
+                }
+            }
+            return 'type_not_defined';
+        }
         /**
          * Returns the name of a function (workaround to get object type for IE11)
          */

+ 21 - 1
inspector/src/properties.ts

@@ -5,34 +5,44 @@ module INSPECTOR {
          * If a format function exists, returns the result of this function.
          * If this function doesn't exists, return the object type instead */
         format : (obj:any) => {
-            let type = Helpers.GET_TYPE(obj) ||  'default';
+            let type = Helpers.GET_TYPE(obj) ||  'type_not_defined';
             if (PROPERTIES[type] && PROPERTIES[type].format) {
                 return PROPERTIES[type].format(obj);
             } else {
                 return Helpers.GET_TYPE(obj);
             }
         },
+        'type_not_defined' : {
+            properties : [],
+            format: () => ''
+        },
         
         'Vector2' : {
+            type: BABYLON.Vector2,
             properties: ['x', 'y'],
             format: (vec : BABYLON.Vector2) => {return `x:${Helpers.Trunc(vec.x)}, y:${Helpers.Trunc(vec.y)}`;}
         },
         'Vector3' : {
+            type: BABYLON.Vector3,
             properties: ['x', 'y', 'z'],
             format: (vec : BABYLON.Vector3) => {return `x:${Helpers.Trunc(vec.x)}, y:${Helpers.Trunc(vec.y)}, z:${Helpers.Trunc(vec.z)}`} 
         },
         'Color3' : {
+            type: BABYLON.Color3,
             properties : ['r', 'g', 'b'],
             format: (color: BABYLON.Color3) => { return `R:${color.r}, G:${color.g}, B:${color.b}`}
         },
         'Quaternion' : {
+            type: BABYLON.Quaternion,
             properties : ['x', 'y', 'z', 'w']
         },
         'Size' : {
+            type: BABYLON.Size,
             properties :['width', 'height'],
             format: (size:BABYLON.Size) => { return `Size - w:${Helpers.Trunc(size.width)}, h:${Helpers.Trunc(size.height)}`} 
         },
         'Texture' : {
+            type: BABYLON.Texture,
             properties :[
                 'hasAlpha', 
                 'level', 
@@ -50,13 +60,16 @@ module INSPECTOR {
         },
         
         'ArcRotateCamera' : {
+            // type: BABYLON.ArcRotateCamera,
             properties : ['alpha', 'beta', 'radius']  
         },
         
         'Scene' : {
+            type: BABYLON.Scene,
             properties:['actionManager', 'activeCamera', 'ambientColor', 'clearColor']  
         },
         'Mesh': {
+            type: BABYLON.Mesh,
             properties : [
                 'name', 
                 'position', 
@@ -68,6 +81,7 @@ module INSPECTOR {
             format : (m:BABYLON.Mesh) : string => {return m.name;}
         },        
         'StandardMaterial' : {
+            type: BABYLON.StandardMaterial,
             properties : [
                 'name', 
                 'alpha',
@@ -105,21 +119,27 @@ module INSPECTOR {
             format : (mat:BABYLON.StandardMaterial) : string => {return mat.name;}
         },
         'PrimitiveAlignment':{
+            type: BABYLON.PrimitiveAlignment,
             properties:['horizontal', 'vertical']
         },
         'PrimitiveThickness':{
+            type: BABYLON.PrimitiveThickness,
             properties:['topPixels', 'leftPixels', 'rightPixels', 'bottomPixels']
         },
         'BoundingInfo2D':{
+            type: BABYLON.BoundingInfo2D,
             properties:['radius','center', 'extent']
         },
         'SolidColorBrush2D':{
+            type: BABYLON.SolidColorBrush2D,
             properties:['color']
         },
         'GradientColorBrush2D':{
+            type: BABYLON.GradientColorBrush2D,
             properties:['color1', 'color2', 'translation', 'rotation', 'scale']
         },
         'PBRMaterial' : {
+            type: BABYLON.PBRMaterial,
             properties: [
                 'name', 
                 'albedoColor', 

+ 3 - 1
inspector/src/tree/TreeItem.ts

@@ -89,7 +89,9 @@
             // Type
             let type = Inspector.DOCUMENT.createElement('span'); 
             type.className = 'property-type';
-            type.textContent = ' - '+this._adapter.type(); 
+            if (this._adapter.type() !== 'type_not_defined') {
+                type.textContent = ' - '+this._adapter.type();
+            } 
             this._div.appendChild(type);
             
             this._lineContent = Helpers.CreateDiv('line-content', this._div);