浏览代码

Fix NullEngine when using textures

David Catuhe 7 年之前
父节点
当前提交
ee6164969b

文件差异内容过多而无法显示
+ 8730 - 8701
Playground/babylon.d.txt


文件差异内容过多而无法显示
+ 8449 - 8444
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 56 - 56
dist/preview release/babylon.js


文件差异内容过多而无法显示
+ 28420 - 28444
dist/preview release/babylon.max.js


文件差异内容过多而无法显示
+ 28420 - 28444
dist/preview release/babylon.no-module.max.js


文件差异内容过多而无法显示
+ 56 - 56
dist/preview release/babylon.worker.js


文件差异内容过多而无法显示
+ 28422 - 28446
dist/preview release/es6.js


+ 26 - 2
dist/preview release/gui/babylon.gui.d.ts

@@ -1316,6 +1316,23 @@ declare module BABYLON.GUI {
 
 
 declare module BABYLON.GUI {
 declare module BABYLON.GUI {
     /**
     /**
+     * Enum that determines the text-wrapping mode to use.
+     */
+    enum TextWrapping {
+        /**
+         * Clip the text when it's larger than Control.width; this is the default mode.
+         */
+        Clip = 0,
+        /**
+         * Wrap the text word-wise, i.e. try to add line-breaks at word boundary to fit within Control.width.
+         */
+        WordWrap = 1,
+        /**
+         * Ellipsize the text, i.e. shrink with trailing … when text is larger than Control.width.
+         */
+        Ellipsis = 2,
+    }
+    /**
      * Class used to create text block control
      * Class used to create text block control
      */
      */
     class TextBlock extends Control {
     class TextBlock extends Control {
@@ -1357,7 +1374,7 @@ declare module BABYLON.GUI {
         /**
         /**
          * Gets or sets a boolean indicating if text must be wrapped
          * Gets or sets a boolean indicating if text must be wrapped
          */
          */
-        textWrapping: boolean;
+        textWrapping: TextWrapping | boolean;
         /**
         /**
          * Gets or sets text to display
          * Gets or sets text to display
          */
          */
@@ -1416,9 +1433,16 @@ declare module BABYLON.GUI {
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         protected _applyStates(context: CanvasRenderingContext2D): void;
         protected _applyStates(context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
+        protected _breakLines(refWidth: number, context: CanvasRenderingContext2D): object[];
         protected _parseLine(line: string | undefined, context: CanvasRenderingContext2D): object;
         protected _parseLine(line: string | undefined, context: CanvasRenderingContext2D): object;
-        protected _parseLineWithTextWrapping(line: string | undefined, context: CanvasRenderingContext2D): object;
+        protected _parseLineEllipsis(line: string | undefined, width: number, context: CanvasRenderingContext2D): object;
+        protected _parseLineWordWrap(line: string | undefined, width: number, context: CanvasRenderingContext2D): object[];
         protected _renderLines(context: CanvasRenderingContext2D): void;
         protected _renderLines(context: CanvasRenderingContext2D): void;
+        /**
+         * Given a width constraint applied on the text block, find the expected height
+         * @returns expected height
+         */
+        computeExpectedHeight(): number;
         dispose(): void;
         dispose(): void;
     }
     }
 }
 }

+ 71 - 12
dist/preview release/gui/babylon.gui.js

@@ -4483,6 +4483,24 @@ var BABYLON;
     var GUI;
     var GUI;
     (function (GUI) {
     (function (GUI) {
         /**
         /**
+         * Enum that determines the text-wrapping mode to use.
+         */
+        var TextWrapping;
+        (function (TextWrapping) {
+            /**
+             * Clip the text when it's larger than Control.width; this is the default mode.
+             */
+            TextWrapping[TextWrapping["Clip"] = 0] = "Clip";
+            /**
+             * Wrap the text word-wise, i.e. try to add line-breaks at word boundary to fit within Control.width.
+             */
+            TextWrapping[TextWrapping["WordWrap"] = 1] = "WordWrap";
+            /**
+             * Ellipsize the text, i.e. shrink with trailing … when text is larger than Control.width.
+             */
+            TextWrapping[TextWrapping["Ellipsis"] = 2] = "Ellipsis";
+        })(TextWrapping = GUI.TextWrapping || (GUI.TextWrapping = {}));
+        /**
          * Class used to create text block control
          * Class used to create text block control
          */
          */
         var TextBlock = /** @class */ (function (_super) {
         var TextBlock = /** @class */ (function (_super) {
@@ -4501,7 +4519,7 @@ var BABYLON;
                 var _this = _super.call(this, name) || this;
                 var _this = _super.call(this, name) || this;
                 _this.name = name;
                 _this.name = name;
                 _this._text = "";
                 _this._text = "";
-                _this._textWrapping = false;
+                _this._textWrapping = TextWrapping.Clip;
                 _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
                 _this._textHorizontalAlignment = GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
                 _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
                 _this._textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
                 _this._resizeToFit = false;
                 _this._resizeToFit = false;
@@ -4563,7 +4581,7 @@ var BABYLON;
                     if (this._textWrapping === value) {
                     if (this._textWrapping === value) {
                         return;
                         return;
                     }
                     }
-                    this._textWrapping = value;
+                    this._textWrapping = +value;
                     this._markAsDirty();
                     this._markAsDirty();
                 },
                 },
                 enumerable: true,
                 enumerable: true,
@@ -4734,37 +4752,59 @@ var BABYLON;
                 }
                 }
             };
             };
             TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
             TextBlock.prototype._additionalProcessing = function (parentMeasure, context) {
-                this._lines = [];
+                this._lines = this._breakLines(this._currentMeasure.width, context);
+                this.onLinesReadyObservable.notifyObservers(this);
+            };
+            TextBlock.prototype._breakLines = function (refWidth, context) {
+                var lines = [];
                 var _lines = this.text.split("\n");
                 var _lines = this.text.split("\n");
-                if (this._textWrapping && !this._resizeToFit) {
+                if (this._textWrapping === TextWrapping.Ellipsis && !this._resizeToFit) {
                     for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
                     for (var _i = 0, _lines_1 = _lines; _i < _lines_1.length; _i++) {
                         var _line = _lines_1[_i];
                         var _line = _lines_1[_i];
-                        this._lines.push(this._parseLineWithTextWrapping(_line, context));
+                        lines.push(this._parseLineEllipsis(_line, refWidth, context));
                     }
                     }
                 }
                 }
-                else {
+                else if (this._textWrapping === TextWrapping.WordWrap && !this._resizeToFit) {
                     for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
                     for (var _a = 0, _lines_2 = _lines; _a < _lines_2.length; _a++) {
                         var _line = _lines_2[_a];
                         var _line = _lines_2[_a];
-                        this._lines.push(this._parseLine(_line, context));
+                        lines.push.apply(lines, this._parseLineWordWrap(_line, refWidth, context));
                     }
                     }
                 }
                 }
-                this.onLinesReadyObservable.notifyObservers(this);
+                else {
+                    for (var _b = 0, _lines_3 = _lines; _b < _lines_3.length; _b++) {
+                        var _line = _lines_3[_b];
+                        lines.push(this._parseLine(_line, context));
+                    }
+                }
+                return lines;
             };
             };
             TextBlock.prototype._parseLine = function (line, context) {
             TextBlock.prototype._parseLine = function (line, context) {
                 if (line === void 0) { line = ''; }
                 if (line === void 0) { line = ''; }
                 return { text: line, width: context.measureText(line).width };
                 return { text: line, width: context.measureText(line).width };
             };
             };
-            TextBlock.prototype._parseLineWithTextWrapping = function (line, context) {
+            TextBlock.prototype._parseLineEllipsis = function (line, width, context) {
                 if (line === void 0) { line = ''; }
                 if (line === void 0) { line = ''; }
+                var lineWidth = context.measureText(line).width;
+                if (lineWidth > width) {
+                    line += '…';
+                }
+                while (line.length > 2 && lineWidth > width) {
+                    line = line.slice(0, -2) + '…';
+                    lineWidth = context.measureText(line).width;
+                }
+                return { text: line, width: lineWidth };
+            };
+            TextBlock.prototype._parseLineWordWrap = function (line, width, context) {
+                if (line === void 0) { line = ''; }
+                var lines = [];
                 var words = line.split(' ');
                 var words = line.split(' ');
-                var width = this._currentMeasure.width;
                 var lineWidth = 0;
                 var lineWidth = 0;
                 for (var n = 0; n < words.length; n++) {
                 for (var n = 0; n < words.length; n++) {
                     var testLine = n > 0 ? line + " " + words[n] : words[0];
                     var testLine = n > 0 ? line + " " + words[n] : words[0];
                     var metrics = context.measureText(testLine);
                     var metrics = context.measureText(testLine);
                     var testWidth = metrics.width;
                     var testWidth = metrics.width;
                     if (testWidth > width && n > 0) {
                     if (testWidth > width && n > 0) {
-                        this._lines.push({ text: line, width: lineWidth });
+                        lines.push({ text: line, width: lineWidth });
                         line = words[n];
                         line = words[n];
                         lineWidth = context.measureText(line).width;
                         lineWidth = context.measureText(line).width;
                     }
                     }
@@ -4773,7 +4813,8 @@ var BABYLON;
                         line = testLine;
                         line = testLine;
                     }
                     }
                 }
                 }
-                return { text: line, width: lineWidth };
+                lines.push({ text: line, width: lineWidth });
+                return lines;
             };
             };
             TextBlock.prototype._renderLines = function (context) {
             TextBlock.prototype._renderLines = function (context) {
                 var height = this._currentMeasure.height;
                 var height = this._currentMeasure.height;
@@ -4814,6 +4855,24 @@ var BABYLON;
                     this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
                     this.height = this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * this._lines.length + 'px';
                 }
                 }
             };
             };
+            /**
+             * Given a width constraint applied on the text block, find the expected height
+             * @returns expected height
+             */
+            TextBlock.prototype.computeExpectedHeight = function () {
+                if (this.text && this.widthInPixels) {
+                    var context = document.createElement('canvas').getContext('2d');
+                    if (context) {
+                        this._applyStates(context);
+                        if (!this._fontOffset) {
+                            this._fontOffset = GUI.Control._GetFontOffset(context.font);
+                        }
+                        var lines = this._lines ? this._lines : this._breakLines(this.widthInPixels - this.paddingLeftInPixels - this.paddingRightInPixels, context);
+                        return this.paddingTopInPixels + this.paddingBottomInPixels + this._fontOffset.height * lines.length;
+                    }
+                }
+                return 0;
+            };
             TextBlock.prototype.dispose = function () {
             TextBlock.prototype.dispose = function () {
                 _super.prototype.dispose.call(this);
                 _super.prototype.dispose.call(this);
                 this.onTextChangedObservable.clear();
                 this.onTextChangedObservable.clear();

文件差异内容过多而无法显示
+ 3 - 3
dist/preview release/gui/babylon.gui.min.js


+ 26 - 2
dist/preview release/gui/babylon.gui.module.d.ts

@@ -1321,6 +1321,23 @@ declare module BABYLON.GUI {
 
 
 declare module BABYLON.GUI {
 declare module BABYLON.GUI {
     /**
     /**
+     * Enum that determines the text-wrapping mode to use.
+     */
+    enum TextWrapping {
+        /**
+         * Clip the text when it's larger than Control.width; this is the default mode.
+         */
+        Clip = 0,
+        /**
+         * Wrap the text word-wise, i.e. try to add line-breaks at word boundary to fit within Control.width.
+         */
+        WordWrap = 1,
+        /**
+         * Ellipsize the text, i.e. shrink with trailing … when text is larger than Control.width.
+         */
+        Ellipsis = 2,
+    }
+    /**
      * Class used to create text block control
      * Class used to create text block control
      */
      */
     class TextBlock extends Control {
     class TextBlock extends Control {
@@ -1362,7 +1379,7 @@ declare module BABYLON.GUI {
         /**
         /**
          * Gets or sets a boolean indicating if text must be wrapped
          * Gets or sets a boolean indicating if text must be wrapped
          */
          */
-        textWrapping: boolean;
+        textWrapping: TextWrapping | boolean;
         /**
         /**
          * Gets or sets text to display
          * Gets or sets text to display
          */
          */
@@ -1421,9 +1438,16 @@ declare module BABYLON.GUI {
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         protected _applyStates(context: CanvasRenderingContext2D): void;
         protected _applyStates(context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
+        protected _breakLines(refWidth: number, context: CanvasRenderingContext2D): object[];
         protected _parseLine(line: string | undefined, context: CanvasRenderingContext2D): object;
         protected _parseLine(line: string | undefined, context: CanvasRenderingContext2D): object;
-        protected _parseLineWithTextWrapping(line: string | undefined, context: CanvasRenderingContext2D): object;
+        protected _parseLineEllipsis(line: string | undefined, width: number, context: CanvasRenderingContext2D): object;
+        protected _parseLineWordWrap(line: string | undefined, width: number, context: CanvasRenderingContext2D): object[];
         protected _renderLines(context: CanvasRenderingContext2D): void;
         protected _renderLines(context: CanvasRenderingContext2D): void;
+        /**
+         * Given a width constraint applied on the text block, find the expected height
+         * @returns expected height
+         */
+        computeExpectedHeight(): number;
         dispose(): void;
         dispose(): void;
     }
     }
 }
 }

+ 37 - 2
dist/preview release/typedocValidationBaseline.json

@@ -1,7 +1,7 @@
 {
 {
-  "errors": 4233,
+  "errors": 4240,
   "babylon.typedoc.json": {
   "babylon.typedoc.json": {
-    "errors": 4233,
+    "errors": 4240,
     "AbstractMesh": {
     "AbstractMesh": {
       "Property": {
       "Property": {
         "showBoundingBox": {
         "showBoundingBox": {
@@ -5190,6 +5190,21 @@
             "NotPascalCase": true
             "NotPascalCase": true
           }
           }
         },
         },
+        "beginTransformFeedback": {
+          "Naming": {
+            "NotPascalCase": true
+          }
+        },
+        "bindTransformFeedback": {
+          "Naming": {
+            "NotPascalCase": true
+          }
+        },
+        "bindTransformFeedbackBuffer": {
+          "Naming": {
+            "NotPascalCase": true
+          }
+        },
         "createEffectForParticles": {
         "createEffectForParticles": {
           "Naming": {
           "Naming": {
             "NotPascalCase": true
             "NotPascalCase": true
@@ -5200,11 +5215,21 @@
             "NotPascalCase": true
             "NotPascalCase": true
           }
           }
         },
         },
+        "createTransformFeedback": {
+          "Naming": {
+            "NotPascalCase": true
+          }
+        },
         "deleteQuery": {
         "deleteQuery": {
           "Naming": {
           "Naming": {
             "NotPascalCase": true
             "NotPascalCase": true
           }
           }
         },
         },
+        "deleteTransformFeedback": {
+          "Naming": {
+            "NotPascalCase": true
+          }
+        },
         "endOcclusionQuery": {
         "endOcclusionQuery": {
           "Naming": {
           "Naming": {
             "NotPascalCase": true
             "NotPascalCase": true
@@ -5215,6 +5240,11 @@
             "NotPascalCase": true
             "NotPascalCase": true
           }
           }
         },
         },
+        "endTransformFeedback": {
+          "Naming": {
+            "NotPascalCase": true
+          }
+        },
         "getQueryResult": {
         "getQueryResult": {
           "Naming": {
           "Naming": {
             "NotPascalCase": true
             "NotPascalCase": true
@@ -5225,6 +5255,11 @@
             "NotPascalCase": true
             "NotPascalCase": true
           }
           }
         },
         },
+        "setTranformFeedbackVaryings": {
+          "Naming": {
+            "NotPascalCase": true
+          }
+        },
         "startTimeQuery": {
         "startTimeQuery": {
           "Naming": {
           "Naming": {
             "NotPascalCase": true
             "NotPascalCase": true

文件差异内容过多而无法显示
+ 65 - 65
dist/preview release/viewer/babylon.viewer.js


文件差异内容过多而无法显示
+ 28420 - 28444
dist/preview release/viewer/babylon.viewer.max.js


+ 1 - 1
src/Particles/babylon.gpuParticleSystem.ts

@@ -1211,7 +1211,7 @@
             // Update
             // Update
             this._engine.bindTransformFeedbackBuffer(this._targetBuffer.getBuffer());
             this._engine.bindTransformFeedbackBuffer(this._targetBuffer.getBuffer());
             this._engine.setRasterizerState(false);
             this._engine.setRasterizerState(false);
-            this._engine.beginTransformFeedback();
+            this._engine.beginTransformFeedback(true);
             this._engine.drawArraysType(Material.PointListDrawMode, 0, this._currentActiveCount);
             this._engine.drawArraysType(Material.PointListDrawMode, 0, this._currentActiveCount);
             this._engine.endTransformFeedback();
             this._engine.endTransformFeedback();
             this._engine.setRasterizerState(true);
             this._engine.setRasterizerState(true);

+ 1 - 1
src/Tools/babylon.tools.ts

@@ -197,7 +197,7 @@
         }
         }
 
 
         public static SetImmediate(action: () => void) {
         public static SetImmediate(action: () => void) {
-            if (window.setImmediate) {
+            if (Tools.IsWindowObjectExist() && window.setImmediate) {
                 window.setImmediate(action);
                 window.setImmediate(action);
             } else {
             } else {
                 setTimeout(action, 1);
                 setTimeout(action, 1);

+ 128 - 35
tests/nullEngine/app.js

@@ -174,50 +174,143 @@ var engine = new BABYLON.NullEngine();
 // scene.render();
 // scene.render();
 // engine.dispose();
 // engine.dispose();
 
 
-var scene = new BABYLON.Scene(engine);
-var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene);
+// var scene = new BABYLON.Scene(engine);
+// var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene);
 
 
-var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene);
+// var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene);
 
 
-var assetsManager = new BABYLON.AssetsManager(scene);
-var meshTask = assetsManager.addMeshTask("skull task", "", "https://raw.githubusercontent.com/RaggarDK/Baby/baby/", "he4.babylon");
+// var assetsManager = new BABYLON.AssetsManager(scene);
+// var meshTask = assetsManager.addMeshTask("skull task", "", "https://raw.githubusercontent.com/RaggarDK/Baby/baby/", "he4.babylon");
+
+// meshTask.onSuccess = function (task) {
+//     
+//     //0 = ground plane, 1,2,3 = boxes
+//     for(var i=1;i<task.loadedMeshes.length;i++){
+//         var mesh = task.loadedMeshes[i];
+//         //mesh.computeWorldMatrix(true);
+
+//         var position = mesh.position.clone();
+//         var rotation = mesh.rotationQuaternion.clone();
+//         var scaling = mesh.getBoundingInfo().boundingBox.extendSize;
+//         var centerWorld = mesh.getBoundingInfo().boundingBox.centerWorld;
+//         console.log(position);
+//         console.log(mesh.getBoundingInfo());
+
+//         var box = BABYLON.MeshBuilder.CreateBox("box"+i,{height:2,width:2,depth:2});
+//         box.scaling.copyFromFloats(scaling.x,scaling.y,scaling.z);    
+//         box.rotationQuaternion = rotation;
+//         //box.position = position;
+//         box.position.set(centerWorld.x,centerWorld.y,centerWorld.z);
+
+//         var material = new BABYLON.StandardMaterial("mat", scene);
+//         material.diffuseColor = new BABYLON.Color3(0.5,1,0.5); 
+//         box.material = material;       
 
 
-meshTask.onSuccess = function (task) {
-    
-    //0 = ground plane, 1,2,3 = boxes
-    for(var i=1;i<task.loadedMeshes.length;i++){
-        var mesh = task.loadedMeshes[i];
-        //mesh.computeWorldMatrix(true);
+//     }
 
 
-        var position = mesh.position.clone();
-        var rotation = mesh.rotationQuaternion.clone();
-        var scaling = mesh.getBoundingInfo().boundingBox.extendSize;
-        var centerWorld = mesh.getBoundingInfo().boundingBox.centerWorld;
-        console.log(position);
-        console.log(mesh.getBoundingInfo());
+// }	
 
 
-        var box = BABYLON.MeshBuilder.CreateBox("box"+i,{height:2,width:2,depth:2});
-        box.scaling.copyFromFloats(scaling.x,scaling.y,scaling.z);    
-        box.rotationQuaternion = rotation;
-        //box.position = position;
-        box.position.set(centerWorld.x,centerWorld.y,centerWorld.z);
+// scene.registerBeforeRender(function () {
+//     light.position = camera.position;
+// });
 
 
-        var material = new BABYLON.StandardMaterial("mat", scene);
-        material.diffuseColor = new BABYLON.Color3(0.5,1,0.5); 
-        box.material = material;       
+// assetsManager.onFinish = function (tasks) {
+//     engine.runRenderLoop(function () {
+//         scene.render();
+//     });
+// };
 
 
-    }
+// assetsManager.load();
+
+var scene = new BABYLON.Scene(engine);
+var camera = new BABYLON.ArcRotateCamera("Camera", -Math.PI / 1,  Math.PI / 1, 5, BABYLON.Vector3.Zero(), scene);
+camera.setPosition(new BABYLON.Vector3(-800,1200,-2000));
+camera.setTarget(BABYLON.Vector3.Zero());
+var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
+light.intensity = 1;
+
+
+function createPart(name,opt,parent){
 
 
-}	
+    var part = BABYLON.MeshBuilder.CreateBox(name, opt.size, scene);
+    part.position = new BABYLON.Vector3(opt.pos.x, opt.pos.y, opt.pos.z);
 
 
-scene.registerBeforeRender(function () {
-    light.position = camera.position;
-});
+    let mate = new BABYLON.StandardMaterial('mat-'+name, scene);
 
 
-assetsManager.onFinish = function (tasks) {
-    engine.runRenderLoop(function () {
-        scene.render();
+    if(parent) {
+        mate.specularPower = 200;
+        mate.specularColor = new BABYLON.Color3(0.5, 0.5, 0.5);
+        mate.diffuseTexture = new BABYLON.Texture(opt.mat.url,scene);
+        mate.diffuseTexture.wAng = opt.mat.grain*Math.PI/180;
+        part.parent = parent;
+    }else{
+        mate.alpha = 0;
+    }
+
+    part.material = mate;
+
+    return part;
+}
+
+
+
+var parent;
+
+function createUnit(x,y,z,b){
+
+    var item = {
+        size:{width:x,depth:y,height:z},
+        pos:{x:0,y:0,z:0},
+        mat:{url:false,grain:0},
+        child:{
+            left:{
+                size:{width:b,depth:y,height:z},
+                pos:{x:-(x-b)/2,y:0,z:0},
+                mat:{url:"/playground/textures/crate.png",grain:90}
+            },
+            right:{
+                size:{width:b,depth:y,height:z},
+                pos:{x:(x-b)/2,y:0,z:0},
+                mat:{url:"/playground/textures/crate.png",grain:90}
+            },
+            top:{
+                size:{width:x-(b*2),depth:y,height:b},
+                pos:{x:0,y:(z-b-1)/2,z:0},
+                mat:{url:"/playground/textures/albedo.png",grain:0}
+            },
+            bottom:{
+                size:{width:x-(b*2),depth:y,height:b},
+                pos:{x:0,y:-(z-b-1)/2,z:0},
+                mat:{url:"/playground/textures/albedo.png",grain:0}
+            },
+            back:{
+                size:{width:x-(b*2),depth:b,height:z-(b*2)-1},
+                pos:{x:0,y:0,z:(y-b)/2-20},
+                mat:{url:"/playground/textures/albedo.png",grain:0}
+            },
+            shelf:{
+                size:{width:x-(b*2)-1,depth:y-b-30,height:b},
+                pos:{x:0,y:0,z:-((b+20)/2)+5},
+                mat:{url:"textures/crate.png",grain:45}
+            }
+        }
+    };
+
+    if(parent){
+        parent.dispose();
+    }
+    
+    parent = createPart("Unit",item,false);
+
+    Object.keys(item.child).forEach(function(key) {
+        createPart(key,item.child[key],parent);
     });
     });
-};
 
 
-assetsManager.load();
+    return item;
+}
+
+createUnit(600,300,900,18);
+
+
+var serialized = BABYLON.SceneSerializer.SerializeMesh(parent, true, true);
+console.log(serialized);