David Catuhe 7 سال پیش
والد
کامیت
d853b0348b

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 2206 - 2163
Playground/babylon.d.txt


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 2321 - 2278
dist/preview release/babylon.d.ts


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 44 - 44
dist/preview release/babylon.js


+ 115 - 94
dist/preview release/babylon.max.js

@@ -21650,15 +21650,18 @@ var BABYLON;
                     }
                 }
             }
+            // Todo. Move into an occlusion query component.
             var scene = this.getScene();
-            var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
-            if (!this._occlusionQuery) {
-                this._occlusionQuery = engine.createQuery();
+            if (scene.getBoundingBoxRenderer) {
+                var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
+                if (!this._occlusionQuery) {
+                    this._occlusionQuery = engine.createQuery();
+                }
+                engine.beginOcclusionQuery(this.occlusionQueryAlgorithmType, this._occlusionQuery);
+                occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
+                engine.endOcclusionQuery(this.occlusionQueryAlgorithmType);
+                this._isOcclusionQueryInProgress = true;
             }
-            engine.beginOcclusionQuery(this.occlusionQueryAlgorithmType, this._occlusionQuery);
-            occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
-            engine.endOcclusionQuery(this.occlusionQueryAlgorithmType);
-            this._isOcclusionQueryInProgress = true;
         };
         /** No occlusion */
         AbstractMesh.OCCLUSION_TYPE_NONE = 0;
@@ -23964,15 +23967,20 @@ var BABYLON;
         SceneComponentConstants.NAME_EFFECTLAYER = "EffectLayer";
         SceneComponentConstants.NAME_LAYER = "Layer";
         SceneComponentConstants.NAME_LENSFLARESYSTEM = "LensFlareSystem";
+        SceneComponentConstants.NAME_BOUNDINGBOXRENDERER = "BoundingBoxRenderer";
         SceneComponentConstants.STEP_ISREADYFORMESH_EFFECTLAYER = 0;
+        SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER = 0;
+        SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER = 0;
+        SceneComponentConstants.STEP_ACTIVEMESH_BOUNDINGBOXRENDERER = 0;
         SceneComponentConstants.STEP_CAMERADRAWRENDERTARGET_EFFECTLAYER = 1;
         SceneComponentConstants.STEP_BEFORECAMERADRAW_EFFECTLAYER = 0;
         SceneComponentConstants.STEP_BEFORECAMERADRAW_LAYER = 1;
         SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_EFFECTLAYER_DRAW = 0;
         SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER = 0;
         SceneComponentConstants.STEP_AFTERCAMERADRAW_LENSFLARESYSTEM = 1;
-        SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 2;
-        SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER = 3;
+        SceneComponentConstants.STEP_AFTERCAMERADRAW_BOUNDINGBOXRENDERER = 2;
+        SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 3;
+        SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER = 4;
         return SceneComponentConstants;
     }());
     BABYLON.SceneComponentConstants = SceneComponentConstants;
@@ -24249,10 +24257,6 @@ var BABYLON;
             _this._forceWireframe = false;
             _this._forcePointsCloud = false;
             /**
-             * Gets or sets a boolean indicating if all bounding boxes must be rendered
-             */
-            _this.forceShowBoundingBoxes = false;
-            /**
              * Gets or sets a boolean indicating if animations are enabled
              */
             _this.animationsEnabled = true;
@@ -24651,6 +24655,10 @@ var BABYLON;
              */
             _this._components = [];
             /**
+             * Backing store of defined scene components.
+             */
+            _this._serializableComponents = [];
+            /**
              * List of components to register on the next registration step.
              */
             _this._transientComponents = [];
@@ -24659,6 +24667,18 @@ var BABYLON;
              */
             _this._isReadyForMeshStage = BABYLON.Stage.Create();
             /**
+             * Defines the actions happening before evaluate active mesh checks.
+             */
+            _this._beforeEvaluateActiveMeshStage = BABYLON.Stage.Create();
+            /**
+             * Defines the actions happening during the evaluate sub mesh checks.
+             */
+            _this._evaluateSubMeshStage = BABYLON.Stage.Create();
+            /**
+             * Defines the actions happening during the active mesh stage.
+             */
+            _this._activeMeshStage = BABYLON.Stage.Create();
+            /**
              * Defines the actions happening during the per camera render target step.
              */
             _this._cameraDrawRenderTargetStage = BABYLON.Stage.Create();
@@ -25157,6 +25177,10 @@ var BABYLON;
         Scene.prototype._addComponent = function (component) {
             this._components.push(component);
             this._transientComponents.push(component);
+            var serializableComponent = component;
+            if (serializableComponent.addFromContainer) {
+                this._serializableComponents.push(serializableComponent);
+            }
         };
         /**
          * Gets a component from the scene.
@@ -25283,16 +25307,6 @@ var BABYLON;
             return this._cachedEffect !== effect || this._cachedMaterial !== material || this._cachedVisibility !== visibility;
         };
         /**
-         * Gets the bounding box renderer associated with the scene
-         * @returns a BoundingBoxRenderer
-         */
-        Scene.prototype.getBoundingBoxRenderer = function () {
-            if (!this._boundingBoxRenderer) {
-                this._boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(this);
-            }
-            return this._boundingBoxRenderer;
-        };
-        /**
          * Gets the outline renderer associated with the scene
          * @returns a OutlineRenderer
          */
@@ -27680,11 +27694,9 @@ var BABYLON;
         };
         Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
             if (this.dispatchAllSubMeshesOfActiveMeshes || mesh.alwaysSelectAsActiveMesh || mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
-                if (mesh.showSubMeshesBoundingBox) {
-                    var boundingInfo = subMesh.getBoundingInfo();
-                    if (boundingInfo !== null && boundingInfo !== undefined) {
-                        this.getBoundingBoxRenderer().renderList.push(boundingInfo.boundingBox);
-                    }
+                for (var _i = 0, _a = this._evaluateSubMeshStage; _i < _a.length; _i++) {
+                    var step = _a[_i];
+                    step.action(mesh, subMesh);
                 }
                 var material = subMesh.getMaterial();
                 if (material !== null && material !== undefined) {
@@ -27796,8 +27808,9 @@ var BABYLON;
             this._activeParticleSystems.reset();
             this._activeSkeletons.reset();
             this._softwareSkinnedMeshes.reset();
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer.reset();
+            for (var _i = 0, _a = this._beforeEvaluateActiveMeshStage; _i < _a.length; _i++) {
+                var step = _a[_i];
+                step.action();
             }
             // Meshes
             var meshes;
@@ -27885,9 +27898,9 @@ var BABYLON;
                     this._softwareSkinnedMeshes.pushNoDuplicate(mesh);
                 }
             }
-            if (sourceMesh.showBoundingBox || this.forceShowBoundingBoxes) {
-                var boundingInfo = sourceMesh.getBoundingInfo();
-                this.getBoundingBoxRenderer().renderList.push(boundingInfo.boundingBox);
+            for (var _i = 0, _a = this._activeMeshStage; _i < _a.length; _i++) {
+                var step = _a[_i];
+                step.action(sourceMesh, mesh);
             }
             if (mesh !== undefined && mesh !== null
                 && mesh.subMeshes !== undefined && mesh.subMeshes !== null && mesh.subMeshes.length > 0) {
@@ -28001,10 +28014,6 @@ var BABYLON;
                 var step = _e[_d];
                 step.action(this.activeCamera);
             }
-            // Bounding boxes
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer.render();
-            }
             // Finalize frame
             if (this.postProcessManager) {
                 this.postProcessManager._finalizeFrame(camera.isIntermediate);
@@ -28494,6 +28503,9 @@ var BABYLON;
             this.morphTargetManagers = [];
             this._transientComponents = [];
             this._isReadyForMeshStage.clear();
+            this._beforeEvaluateActiveMeshStage.clear();
+            this._evaluateSubMeshStage.clear();
+            this._activeMeshStage.clear();
             this._cameraDrawRenderTargetStage.clear();
             this._beforeCameraDrawStage.clear();
             this._beforeRenderingGroupDrawStage.clear();
@@ -28526,9 +28538,6 @@ var BABYLON;
             this._softwareSkinnedMeshes.dispose();
             this._renderTargets.dispose();
             this._registeredForLateAnimationBindings.dispose();
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer.dispose();
-            }
             this._meshesForIntersections.dispose();
             this._toBeDisposed.dispose();
             // Abort active requests
@@ -29119,9 +29128,6 @@ var BABYLON;
                 var component = _e[_d];
                 component.rebuild();
             }
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer._rebuild();
-            }
             for (var _f = 0, _g = this.particleSystems; _f < _g.length; _f++) {
                 var system = _g[_f];
                 system.rebuild();
@@ -29521,7 +29527,7 @@ var BABYLON;
             this.textures.forEach(function (o) {
                 _this.scene.addTexture(o);
             });
-            for (var _i = 0, _a = this.scene._components; _i < _a.length; _i++) {
+            for (var _i = 0, _a = this.scene._serializableComponents; _i < _a.length; _i++) {
                 var component = _a[_i];
                 component.addFromContainer(this.scene);
             }
@@ -29578,7 +29584,7 @@ var BABYLON;
             this.textures.forEach(function (o) {
                 _this.scene.removeTexture(o);
             });
-            for (var _i = 0, _a = this.scene._components; _i < _a.length; _i++) {
+            for (var _i = 0, _a = this.scene._serializableComponents; _i < _a.length; _i++) {
                 var component = _a[_i];
                 component.removeFromContainer(this.scene);
             }
@@ -89284,33 +89290,85 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    Object.defineProperty(BABYLON.Scene.prototype, "forceShowBoundingBoxes", {
+        get: function () {
+            return this._forceShowBoundingBoxes || false;
+        },
+        set: function (value) {
+            this._forceShowBoundingBoxes = value;
+            // Lazyly creates a BB renderer if needed.
+            if (value) {
+                this.getBoundingBoxRenderer();
+            }
+        },
+        enumerable: true,
+        configurable: true
+    });
+    BABYLON.Scene.prototype.getBoundingBoxRenderer = function () {
+        if (!this._boundingBoxRenderer) {
+            this._boundingBoxRenderer = new BoundingBoxRenderer(this);
+        }
+        return this._boundingBoxRenderer;
+    };
     var BoundingBoxRenderer = /** @class */ (function () {
         function BoundingBoxRenderer(scene) {
+            /**
+             * The component name helpfull to identify the component in the list of scene components.
+             */
+            this.name = BABYLON.SceneComponentConstants.NAME_BOUNDINGBOXRENDERER;
             this.frontColor = new BABYLON.Color3(1, 1, 1);
             this.backColor = new BABYLON.Color3(0.1, 0.1, 0.1);
             this.showBackLines = true;
             this.renderList = new BABYLON.SmartArray(32);
             this._vertexBuffers = {};
-            this._scene = scene;
+            this.scene = scene;
+            scene._addComponent(this);
         }
+        /**
+         * Registers the component in a given scene
+         */
+        BoundingBoxRenderer.prototype.register = function () {
+            this.scene._beforeEvaluateActiveMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER, this, this.reset);
+            this.scene._activeMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_ACTIVEMESH_BOUNDINGBOXRENDERER, this, this._activeMesh);
+            this.scene._evaluateSubMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER, this, this._evaluateSubMesh);
+            this.scene._afterCameraDrawStage.registerStep(BABYLON.SceneComponentConstants.STEP_AFTERCAMERADRAW_BOUNDINGBOXRENDERER, this, this.render);
+        };
+        BoundingBoxRenderer.prototype._evaluateSubMesh = function (mesh, subMesh) {
+            if (mesh.showSubMeshesBoundingBox) {
+                var boundingInfo = subMesh.getBoundingInfo();
+                if (boundingInfo !== null && boundingInfo !== undefined) {
+                    this.renderList.push(boundingInfo.boundingBox);
+                }
+            }
+        };
+        BoundingBoxRenderer.prototype._activeMesh = function (sourceMesh, mesh) {
+            if (sourceMesh.showBoundingBox || this.scene.forceShowBoundingBoxes) {
+                var boundingInfo = sourceMesh.getBoundingInfo();
+                this.renderList.push(boundingInfo.boundingBox);
+            }
+        };
         BoundingBoxRenderer.prototype._prepareRessources = function () {
             if (this._colorShader) {
                 return;
             }
-            this._colorShader = new BABYLON.ShaderMaterial("colorShader", this._scene, "color", {
+            this._colorShader = new BABYLON.ShaderMaterial("colorShader", this.scene, "color", {
                 attributes: [BABYLON.VertexBuffer.PositionKind],
                 uniforms: ["world", "viewProjection", "color"]
             });
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             var boxdata = BABYLON.VertexData.CreateBox({ size: 1.0 });
             this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = new BABYLON.VertexBuffer(engine, boxdata.positions, BABYLON.VertexBuffer.PositionKind, false);
             this._createIndexBuffer();
         };
         BoundingBoxRenderer.prototype._createIndexBuffer = function () {
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
         };
-        BoundingBoxRenderer.prototype._rebuild = function () {
+        /**
+         * Rebuilds the elements related to this component in case of
+         * context lost for instance.
+         */
+        BoundingBoxRenderer.prototype.rebuild = function () {
             var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
             if (vb) {
                 vb._rebuild();
@@ -89328,7 +89386,7 @@ var BABYLON;
             if (!this._colorShader.isReady()) {
                 return;
             }
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             engine.setDepthWrite(false);
             this._colorShader._preBind();
             for (var boundingBoxIndex = 0; boundingBoxIndex < this.renderList.length; boundingBoxIndex++) {
@@ -89345,7 +89403,7 @@ var BABYLON;
                 if (this.showBackLines) {
                     // Back
                     engine.setDepthFunctionToGreaterOrEqual();
-                    this._scene.resetCachedMaterial();
+                    this.scene.resetCachedMaterial();
                     this._colorShader.setColor4("color", this.backColor.toColor4());
                     this._colorShader.bind(worldMatrix);
                     // Draw order
@@ -89353,7 +89411,7 @@ var BABYLON;
                 }
                 // Front
                 engine.setDepthFunctionToLess();
-                this._scene.resetCachedMaterial();
+                this.scene.resetCachedMaterial();
                 this._colorShader.setColor4("color", this.frontColor.toColor4());
                 this._colorShader.bind(worldMatrix);
                 // Draw order
@@ -89368,7 +89426,7 @@ var BABYLON;
             if (!this._colorShader.isReady() || !mesh._boundingInfo) {
                 return;
             }
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             engine.setDepthWrite(false);
             engine.setColorWrite(false);
             this._colorShader._preBind();
@@ -89382,7 +89440,7 @@ var BABYLON;
                 .multiply(boundingBox.getWorldMatrix());
             engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
             engine.setDepthFunctionToLess();
-            this._scene.resetCachedMaterial();
+            this.scene.resetCachedMaterial();
             this._colorShader.bind(worldMatrix);
             engine.drawElementsType(BABYLON.Material.LineListDrawMode, 0, 24);
             this._colorShader.unbind();
@@ -89401,7 +89459,7 @@ var BABYLON;
                 buffer.dispose();
                 this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = null;
             }
-            this._scene.getEngine()._releaseBuffer(this._indexBuffer);
+            this.scene.getEngine()._releaseBuffer(this._indexBuffer);
         };
         return BoundingBoxRenderer;
     }());
@@ -99743,7 +99801,7 @@ var BABYLON;
                 }
             }
             // Components
-            for (var _b = 0, _c = scene._components; _b < _c.length; _b++) {
+            for (var _b = 0, _c = scene._serializableComponents; _b < _c.length; _b++) {
                 var component = _c[_b];
                 component.serialize(serializationObject);
             }
@@ -99940,43 +99998,6 @@ var BABYLON;
             }
         };
         /**
-         * Serializes the component data to the specified json object
-         * @param serializationObject The object to serialize to
-         */
-        LayerSceneComponent.prototype.serialize = function (serializationObject) {
-            // TODO. Implement layer serialization
-            // serializationObject.layers = [];
-            // for (let layer of this._layers) {
-            //     if (layer.serialize) {
-            //         serializationObject.layers.push(layer.serialize());
-            //     }
-            // }
-        };
-        /**
-         * Adds all the element from the container to the scene
-         * @param container the container holding the elements
-         */
-        LayerSceneComponent.prototype.addFromContainer = function (container) {
-            if (!container.layers) {
-                return;
-            }
-            // container.layers.forEach((o) => {
-            //     this.scene.addLayer(o);
-            // });
-        };
-        /**
-         * Removes all the elements in the container from the scene
-         * @param container contains the elements to remove
-         */
-        LayerSceneComponent.prototype.removeFromContainer = function (container) {
-            if (!container.layers) {
-                return;
-            }
-            // container.layers.forEach((o) => {
-            //     this.scene.removeLayer(o);
-            // });
-        };
-        /**
          * Disposes the component and the associated ressources.
          */
         LayerSceneComponent.prototype.dispose = function () {

+ 115 - 94
dist/preview release/babylon.no-module.max.js

@@ -21617,15 +21617,18 @@ var BABYLON;
                     }
                 }
             }
+            // Todo. Move into an occlusion query component.
             var scene = this.getScene();
-            var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
-            if (!this._occlusionQuery) {
-                this._occlusionQuery = engine.createQuery();
+            if (scene.getBoundingBoxRenderer) {
+                var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
+                if (!this._occlusionQuery) {
+                    this._occlusionQuery = engine.createQuery();
+                }
+                engine.beginOcclusionQuery(this.occlusionQueryAlgorithmType, this._occlusionQuery);
+                occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
+                engine.endOcclusionQuery(this.occlusionQueryAlgorithmType);
+                this._isOcclusionQueryInProgress = true;
             }
-            engine.beginOcclusionQuery(this.occlusionQueryAlgorithmType, this._occlusionQuery);
-            occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
-            engine.endOcclusionQuery(this.occlusionQueryAlgorithmType);
-            this._isOcclusionQueryInProgress = true;
         };
         /** No occlusion */
         AbstractMesh.OCCLUSION_TYPE_NONE = 0;
@@ -23931,15 +23934,20 @@ var BABYLON;
         SceneComponentConstants.NAME_EFFECTLAYER = "EffectLayer";
         SceneComponentConstants.NAME_LAYER = "Layer";
         SceneComponentConstants.NAME_LENSFLARESYSTEM = "LensFlareSystem";
+        SceneComponentConstants.NAME_BOUNDINGBOXRENDERER = "BoundingBoxRenderer";
         SceneComponentConstants.STEP_ISREADYFORMESH_EFFECTLAYER = 0;
+        SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER = 0;
+        SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER = 0;
+        SceneComponentConstants.STEP_ACTIVEMESH_BOUNDINGBOXRENDERER = 0;
         SceneComponentConstants.STEP_CAMERADRAWRENDERTARGET_EFFECTLAYER = 1;
         SceneComponentConstants.STEP_BEFORECAMERADRAW_EFFECTLAYER = 0;
         SceneComponentConstants.STEP_BEFORECAMERADRAW_LAYER = 1;
         SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_EFFECTLAYER_DRAW = 0;
         SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER = 0;
         SceneComponentConstants.STEP_AFTERCAMERADRAW_LENSFLARESYSTEM = 1;
-        SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 2;
-        SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER = 3;
+        SceneComponentConstants.STEP_AFTERCAMERADRAW_BOUNDINGBOXRENDERER = 2;
+        SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 3;
+        SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER = 4;
         return SceneComponentConstants;
     }());
     BABYLON.SceneComponentConstants = SceneComponentConstants;
@@ -24216,10 +24224,6 @@ var BABYLON;
             _this._forceWireframe = false;
             _this._forcePointsCloud = false;
             /**
-             * Gets or sets a boolean indicating if all bounding boxes must be rendered
-             */
-            _this.forceShowBoundingBoxes = false;
-            /**
              * Gets or sets a boolean indicating if animations are enabled
              */
             _this.animationsEnabled = true;
@@ -24618,6 +24622,10 @@ var BABYLON;
              */
             _this._components = [];
             /**
+             * Backing store of defined scene components.
+             */
+            _this._serializableComponents = [];
+            /**
              * List of components to register on the next registration step.
              */
             _this._transientComponents = [];
@@ -24626,6 +24634,18 @@ var BABYLON;
              */
             _this._isReadyForMeshStage = BABYLON.Stage.Create();
             /**
+             * Defines the actions happening before evaluate active mesh checks.
+             */
+            _this._beforeEvaluateActiveMeshStage = BABYLON.Stage.Create();
+            /**
+             * Defines the actions happening during the evaluate sub mesh checks.
+             */
+            _this._evaluateSubMeshStage = BABYLON.Stage.Create();
+            /**
+             * Defines the actions happening during the active mesh stage.
+             */
+            _this._activeMeshStage = BABYLON.Stage.Create();
+            /**
              * Defines the actions happening during the per camera render target step.
              */
             _this._cameraDrawRenderTargetStage = BABYLON.Stage.Create();
@@ -25124,6 +25144,10 @@ var BABYLON;
         Scene.prototype._addComponent = function (component) {
             this._components.push(component);
             this._transientComponents.push(component);
+            var serializableComponent = component;
+            if (serializableComponent.addFromContainer) {
+                this._serializableComponents.push(serializableComponent);
+            }
         };
         /**
          * Gets a component from the scene.
@@ -25250,16 +25274,6 @@ var BABYLON;
             return this._cachedEffect !== effect || this._cachedMaterial !== material || this._cachedVisibility !== visibility;
         };
         /**
-         * Gets the bounding box renderer associated with the scene
-         * @returns a BoundingBoxRenderer
-         */
-        Scene.prototype.getBoundingBoxRenderer = function () {
-            if (!this._boundingBoxRenderer) {
-                this._boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(this);
-            }
-            return this._boundingBoxRenderer;
-        };
-        /**
          * Gets the outline renderer associated with the scene
          * @returns a OutlineRenderer
          */
@@ -27647,11 +27661,9 @@ var BABYLON;
         };
         Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
             if (this.dispatchAllSubMeshesOfActiveMeshes || mesh.alwaysSelectAsActiveMesh || mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
-                if (mesh.showSubMeshesBoundingBox) {
-                    var boundingInfo = subMesh.getBoundingInfo();
-                    if (boundingInfo !== null && boundingInfo !== undefined) {
-                        this.getBoundingBoxRenderer().renderList.push(boundingInfo.boundingBox);
-                    }
+                for (var _i = 0, _a = this._evaluateSubMeshStage; _i < _a.length; _i++) {
+                    var step = _a[_i];
+                    step.action(mesh, subMesh);
                 }
                 var material = subMesh.getMaterial();
                 if (material !== null && material !== undefined) {
@@ -27763,8 +27775,9 @@ var BABYLON;
             this._activeParticleSystems.reset();
             this._activeSkeletons.reset();
             this._softwareSkinnedMeshes.reset();
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer.reset();
+            for (var _i = 0, _a = this._beforeEvaluateActiveMeshStage; _i < _a.length; _i++) {
+                var step = _a[_i];
+                step.action();
             }
             // Meshes
             var meshes;
@@ -27852,9 +27865,9 @@ var BABYLON;
                     this._softwareSkinnedMeshes.pushNoDuplicate(mesh);
                 }
             }
-            if (sourceMesh.showBoundingBox || this.forceShowBoundingBoxes) {
-                var boundingInfo = sourceMesh.getBoundingInfo();
-                this.getBoundingBoxRenderer().renderList.push(boundingInfo.boundingBox);
+            for (var _i = 0, _a = this._activeMeshStage; _i < _a.length; _i++) {
+                var step = _a[_i];
+                step.action(sourceMesh, mesh);
             }
             if (mesh !== undefined && mesh !== null
                 && mesh.subMeshes !== undefined && mesh.subMeshes !== null && mesh.subMeshes.length > 0) {
@@ -27968,10 +27981,6 @@ var BABYLON;
                 var step = _e[_d];
                 step.action(this.activeCamera);
             }
-            // Bounding boxes
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer.render();
-            }
             // Finalize frame
             if (this.postProcessManager) {
                 this.postProcessManager._finalizeFrame(camera.isIntermediate);
@@ -28461,6 +28470,9 @@ var BABYLON;
             this.morphTargetManagers = [];
             this._transientComponents = [];
             this._isReadyForMeshStage.clear();
+            this._beforeEvaluateActiveMeshStage.clear();
+            this._evaluateSubMeshStage.clear();
+            this._activeMeshStage.clear();
             this._cameraDrawRenderTargetStage.clear();
             this._beforeCameraDrawStage.clear();
             this._beforeRenderingGroupDrawStage.clear();
@@ -28493,9 +28505,6 @@ var BABYLON;
             this._softwareSkinnedMeshes.dispose();
             this._renderTargets.dispose();
             this._registeredForLateAnimationBindings.dispose();
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer.dispose();
-            }
             this._meshesForIntersections.dispose();
             this._toBeDisposed.dispose();
             // Abort active requests
@@ -29086,9 +29095,6 @@ var BABYLON;
                 var component = _e[_d];
                 component.rebuild();
             }
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer._rebuild();
-            }
             for (var _f = 0, _g = this.particleSystems; _f < _g.length; _f++) {
                 var system = _g[_f];
                 system.rebuild();
@@ -29488,7 +29494,7 @@ var BABYLON;
             this.textures.forEach(function (o) {
                 _this.scene.addTexture(o);
             });
-            for (var _i = 0, _a = this.scene._components; _i < _a.length; _i++) {
+            for (var _i = 0, _a = this.scene._serializableComponents; _i < _a.length; _i++) {
                 var component = _a[_i];
                 component.addFromContainer(this.scene);
             }
@@ -29545,7 +29551,7 @@ var BABYLON;
             this.textures.forEach(function (o) {
                 _this.scene.removeTexture(o);
             });
-            for (var _i = 0, _a = this.scene._components; _i < _a.length; _i++) {
+            for (var _i = 0, _a = this.scene._serializableComponents; _i < _a.length; _i++) {
                 var component = _a[_i];
                 component.removeFromContainer(this.scene);
             }
@@ -89251,33 +89257,85 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    Object.defineProperty(BABYLON.Scene.prototype, "forceShowBoundingBoxes", {
+        get: function () {
+            return this._forceShowBoundingBoxes || false;
+        },
+        set: function (value) {
+            this._forceShowBoundingBoxes = value;
+            // Lazyly creates a BB renderer if needed.
+            if (value) {
+                this.getBoundingBoxRenderer();
+            }
+        },
+        enumerable: true,
+        configurable: true
+    });
+    BABYLON.Scene.prototype.getBoundingBoxRenderer = function () {
+        if (!this._boundingBoxRenderer) {
+            this._boundingBoxRenderer = new BoundingBoxRenderer(this);
+        }
+        return this._boundingBoxRenderer;
+    };
     var BoundingBoxRenderer = /** @class */ (function () {
         function BoundingBoxRenderer(scene) {
+            /**
+             * The component name helpfull to identify the component in the list of scene components.
+             */
+            this.name = BABYLON.SceneComponentConstants.NAME_BOUNDINGBOXRENDERER;
             this.frontColor = new BABYLON.Color3(1, 1, 1);
             this.backColor = new BABYLON.Color3(0.1, 0.1, 0.1);
             this.showBackLines = true;
             this.renderList = new BABYLON.SmartArray(32);
             this._vertexBuffers = {};
-            this._scene = scene;
+            this.scene = scene;
+            scene._addComponent(this);
         }
+        /**
+         * Registers the component in a given scene
+         */
+        BoundingBoxRenderer.prototype.register = function () {
+            this.scene._beforeEvaluateActiveMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER, this, this.reset);
+            this.scene._activeMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_ACTIVEMESH_BOUNDINGBOXRENDERER, this, this._activeMesh);
+            this.scene._evaluateSubMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER, this, this._evaluateSubMesh);
+            this.scene._afterCameraDrawStage.registerStep(BABYLON.SceneComponentConstants.STEP_AFTERCAMERADRAW_BOUNDINGBOXRENDERER, this, this.render);
+        };
+        BoundingBoxRenderer.prototype._evaluateSubMesh = function (mesh, subMesh) {
+            if (mesh.showSubMeshesBoundingBox) {
+                var boundingInfo = subMesh.getBoundingInfo();
+                if (boundingInfo !== null && boundingInfo !== undefined) {
+                    this.renderList.push(boundingInfo.boundingBox);
+                }
+            }
+        };
+        BoundingBoxRenderer.prototype._activeMesh = function (sourceMesh, mesh) {
+            if (sourceMesh.showBoundingBox || this.scene.forceShowBoundingBoxes) {
+                var boundingInfo = sourceMesh.getBoundingInfo();
+                this.renderList.push(boundingInfo.boundingBox);
+            }
+        };
         BoundingBoxRenderer.prototype._prepareRessources = function () {
             if (this._colorShader) {
                 return;
             }
-            this._colorShader = new BABYLON.ShaderMaterial("colorShader", this._scene, "color", {
+            this._colorShader = new BABYLON.ShaderMaterial("colorShader", this.scene, "color", {
                 attributes: [BABYLON.VertexBuffer.PositionKind],
                 uniforms: ["world", "viewProjection", "color"]
             });
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             var boxdata = BABYLON.VertexData.CreateBox({ size: 1.0 });
             this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = new BABYLON.VertexBuffer(engine, boxdata.positions, BABYLON.VertexBuffer.PositionKind, false);
             this._createIndexBuffer();
         };
         BoundingBoxRenderer.prototype._createIndexBuffer = function () {
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
         };
-        BoundingBoxRenderer.prototype._rebuild = function () {
+        /**
+         * Rebuilds the elements related to this component in case of
+         * context lost for instance.
+         */
+        BoundingBoxRenderer.prototype.rebuild = function () {
             var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
             if (vb) {
                 vb._rebuild();
@@ -89295,7 +89353,7 @@ var BABYLON;
             if (!this._colorShader.isReady()) {
                 return;
             }
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             engine.setDepthWrite(false);
             this._colorShader._preBind();
             for (var boundingBoxIndex = 0; boundingBoxIndex < this.renderList.length; boundingBoxIndex++) {
@@ -89312,7 +89370,7 @@ var BABYLON;
                 if (this.showBackLines) {
                     // Back
                     engine.setDepthFunctionToGreaterOrEqual();
-                    this._scene.resetCachedMaterial();
+                    this.scene.resetCachedMaterial();
                     this._colorShader.setColor4("color", this.backColor.toColor4());
                     this._colorShader.bind(worldMatrix);
                     // Draw order
@@ -89320,7 +89378,7 @@ var BABYLON;
                 }
                 // Front
                 engine.setDepthFunctionToLess();
-                this._scene.resetCachedMaterial();
+                this.scene.resetCachedMaterial();
                 this._colorShader.setColor4("color", this.frontColor.toColor4());
                 this._colorShader.bind(worldMatrix);
                 // Draw order
@@ -89335,7 +89393,7 @@ var BABYLON;
             if (!this._colorShader.isReady() || !mesh._boundingInfo) {
                 return;
             }
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             engine.setDepthWrite(false);
             engine.setColorWrite(false);
             this._colorShader._preBind();
@@ -89349,7 +89407,7 @@ var BABYLON;
                 .multiply(boundingBox.getWorldMatrix());
             engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
             engine.setDepthFunctionToLess();
-            this._scene.resetCachedMaterial();
+            this.scene.resetCachedMaterial();
             this._colorShader.bind(worldMatrix);
             engine.drawElementsType(BABYLON.Material.LineListDrawMode, 0, 24);
             this._colorShader.unbind();
@@ -89368,7 +89426,7 @@ var BABYLON;
                 buffer.dispose();
                 this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = null;
             }
-            this._scene.getEngine()._releaseBuffer(this._indexBuffer);
+            this.scene.getEngine()._releaseBuffer(this._indexBuffer);
         };
         return BoundingBoxRenderer;
     }());
@@ -99710,7 +99768,7 @@ var BABYLON;
                 }
             }
             // Components
-            for (var _b = 0, _c = scene._components; _b < _c.length; _b++) {
+            for (var _b = 0, _c = scene._serializableComponents; _b < _c.length; _b++) {
                 var component = _c[_b];
                 component.serialize(serializationObject);
             }
@@ -99907,43 +99965,6 @@ var BABYLON;
             }
         };
         /**
-         * Serializes the component data to the specified json object
-         * @param serializationObject The object to serialize to
-         */
-        LayerSceneComponent.prototype.serialize = function (serializationObject) {
-            // TODO. Implement layer serialization
-            // serializationObject.layers = [];
-            // for (let layer of this._layers) {
-            //     if (layer.serialize) {
-            //         serializationObject.layers.push(layer.serialize());
-            //     }
-            // }
-        };
-        /**
-         * Adds all the element from the container to the scene
-         * @param container the container holding the elements
-         */
-        LayerSceneComponent.prototype.addFromContainer = function (container) {
-            if (!container.layers) {
-                return;
-            }
-            // container.layers.forEach((o) => {
-            //     this.scene.addLayer(o);
-            // });
-        };
-        /**
-         * Removes all the elements in the container from the scene
-         * @param container contains the elements to remove
-         */
-        LayerSceneComponent.prototype.removeFromContainer = function (container) {
-            if (!container.layers) {
-                return;
-            }
-            // container.layers.forEach((o) => {
-            //     this.scene.removeLayer(o);
-            // });
-        };
-        /**
          * Disposes the component and the associated ressources.
          */
         LayerSceneComponent.prototype.dispose = function () {

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 44 - 44
dist/preview release/babylon.worker.js


+ 115 - 94
dist/preview release/es6.js

@@ -21617,15 +21617,18 @@ var BABYLON;
                     }
                 }
             }
+            // Todo. Move into an occlusion query component.
             var scene = this.getScene();
-            var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
-            if (!this._occlusionQuery) {
-                this._occlusionQuery = engine.createQuery();
+            if (scene.getBoundingBoxRenderer) {
+                var occlusionBoundingBoxRenderer = scene.getBoundingBoxRenderer();
+                if (!this._occlusionQuery) {
+                    this._occlusionQuery = engine.createQuery();
+                }
+                engine.beginOcclusionQuery(this.occlusionQueryAlgorithmType, this._occlusionQuery);
+                occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
+                engine.endOcclusionQuery(this.occlusionQueryAlgorithmType);
+                this._isOcclusionQueryInProgress = true;
             }
-            engine.beginOcclusionQuery(this.occlusionQueryAlgorithmType, this._occlusionQuery);
-            occlusionBoundingBoxRenderer.renderOcclusionBoundingBox(this);
-            engine.endOcclusionQuery(this.occlusionQueryAlgorithmType);
-            this._isOcclusionQueryInProgress = true;
         };
         /** No occlusion */
         AbstractMesh.OCCLUSION_TYPE_NONE = 0;
@@ -23931,15 +23934,20 @@ var BABYLON;
         SceneComponentConstants.NAME_EFFECTLAYER = "EffectLayer";
         SceneComponentConstants.NAME_LAYER = "Layer";
         SceneComponentConstants.NAME_LENSFLARESYSTEM = "LensFlareSystem";
+        SceneComponentConstants.NAME_BOUNDINGBOXRENDERER = "BoundingBoxRenderer";
         SceneComponentConstants.STEP_ISREADYFORMESH_EFFECTLAYER = 0;
+        SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER = 0;
+        SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER = 0;
+        SceneComponentConstants.STEP_ACTIVEMESH_BOUNDINGBOXRENDERER = 0;
         SceneComponentConstants.STEP_CAMERADRAWRENDERTARGET_EFFECTLAYER = 1;
         SceneComponentConstants.STEP_BEFORECAMERADRAW_EFFECTLAYER = 0;
         SceneComponentConstants.STEP_BEFORECAMERADRAW_LAYER = 1;
         SceneComponentConstants.STEP_AFTERRENDERINGGROUPDRAW_EFFECTLAYER_DRAW = 0;
         SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER = 0;
         SceneComponentConstants.STEP_AFTERCAMERADRAW_LENSFLARESYSTEM = 1;
-        SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 2;
-        SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER = 3;
+        SceneComponentConstants.STEP_AFTERCAMERADRAW_BOUNDINGBOXRENDERER = 2;
+        SceneComponentConstants.STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 3;
+        SceneComponentConstants.STEP_AFTERCAMERADRAW_LAYER = 4;
         return SceneComponentConstants;
     }());
     BABYLON.SceneComponentConstants = SceneComponentConstants;
@@ -24216,10 +24224,6 @@ var BABYLON;
             _this._forceWireframe = false;
             _this._forcePointsCloud = false;
             /**
-             * Gets or sets a boolean indicating if all bounding boxes must be rendered
-             */
-            _this.forceShowBoundingBoxes = false;
-            /**
              * Gets or sets a boolean indicating if animations are enabled
              */
             _this.animationsEnabled = true;
@@ -24618,6 +24622,10 @@ var BABYLON;
              */
             _this._components = [];
             /**
+             * Backing store of defined scene components.
+             */
+            _this._serializableComponents = [];
+            /**
              * List of components to register on the next registration step.
              */
             _this._transientComponents = [];
@@ -24626,6 +24634,18 @@ var BABYLON;
              */
             _this._isReadyForMeshStage = BABYLON.Stage.Create();
             /**
+             * Defines the actions happening before evaluate active mesh checks.
+             */
+            _this._beforeEvaluateActiveMeshStage = BABYLON.Stage.Create();
+            /**
+             * Defines the actions happening during the evaluate sub mesh checks.
+             */
+            _this._evaluateSubMeshStage = BABYLON.Stage.Create();
+            /**
+             * Defines the actions happening during the active mesh stage.
+             */
+            _this._activeMeshStage = BABYLON.Stage.Create();
+            /**
              * Defines the actions happening during the per camera render target step.
              */
             _this._cameraDrawRenderTargetStage = BABYLON.Stage.Create();
@@ -25124,6 +25144,10 @@ var BABYLON;
         Scene.prototype._addComponent = function (component) {
             this._components.push(component);
             this._transientComponents.push(component);
+            var serializableComponent = component;
+            if (serializableComponent.addFromContainer) {
+                this._serializableComponents.push(serializableComponent);
+            }
         };
         /**
          * Gets a component from the scene.
@@ -25250,16 +25274,6 @@ var BABYLON;
             return this._cachedEffect !== effect || this._cachedMaterial !== material || this._cachedVisibility !== visibility;
         };
         /**
-         * Gets the bounding box renderer associated with the scene
-         * @returns a BoundingBoxRenderer
-         */
-        Scene.prototype.getBoundingBoxRenderer = function () {
-            if (!this._boundingBoxRenderer) {
-                this._boundingBoxRenderer = new BABYLON.BoundingBoxRenderer(this);
-            }
-            return this._boundingBoxRenderer;
-        };
-        /**
          * Gets the outline renderer associated with the scene
          * @returns a OutlineRenderer
          */
@@ -27647,11 +27661,9 @@ var BABYLON;
         };
         Scene.prototype._evaluateSubMesh = function (subMesh, mesh) {
             if (this.dispatchAllSubMeshesOfActiveMeshes || mesh.alwaysSelectAsActiveMesh || mesh.subMeshes.length === 1 || subMesh.isInFrustum(this._frustumPlanes)) {
-                if (mesh.showSubMeshesBoundingBox) {
-                    var boundingInfo = subMesh.getBoundingInfo();
-                    if (boundingInfo !== null && boundingInfo !== undefined) {
-                        this.getBoundingBoxRenderer().renderList.push(boundingInfo.boundingBox);
-                    }
+                for (var _i = 0, _a = this._evaluateSubMeshStage; _i < _a.length; _i++) {
+                    var step = _a[_i];
+                    step.action(mesh, subMesh);
                 }
                 var material = subMesh.getMaterial();
                 if (material !== null && material !== undefined) {
@@ -27763,8 +27775,9 @@ var BABYLON;
             this._activeParticleSystems.reset();
             this._activeSkeletons.reset();
             this._softwareSkinnedMeshes.reset();
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer.reset();
+            for (var _i = 0, _a = this._beforeEvaluateActiveMeshStage; _i < _a.length; _i++) {
+                var step = _a[_i];
+                step.action();
             }
             // Meshes
             var meshes;
@@ -27852,9 +27865,9 @@ var BABYLON;
                     this._softwareSkinnedMeshes.pushNoDuplicate(mesh);
                 }
             }
-            if (sourceMesh.showBoundingBox || this.forceShowBoundingBoxes) {
-                var boundingInfo = sourceMesh.getBoundingInfo();
-                this.getBoundingBoxRenderer().renderList.push(boundingInfo.boundingBox);
+            for (var _i = 0, _a = this._activeMeshStage; _i < _a.length; _i++) {
+                var step = _a[_i];
+                step.action(sourceMesh, mesh);
             }
             if (mesh !== undefined && mesh !== null
                 && mesh.subMeshes !== undefined && mesh.subMeshes !== null && mesh.subMeshes.length > 0) {
@@ -27968,10 +27981,6 @@ var BABYLON;
                 var step = _e[_d];
                 step.action(this.activeCamera);
             }
-            // Bounding boxes
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer.render();
-            }
             // Finalize frame
             if (this.postProcessManager) {
                 this.postProcessManager._finalizeFrame(camera.isIntermediate);
@@ -28461,6 +28470,9 @@ var BABYLON;
             this.morphTargetManagers = [];
             this._transientComponents = [];
             this._isReadyForMeshStage.clear();
+            this._beforeEvaluateActiveMeshStage.clear();
+            this._evaluateSubMeshStage.clear();
+            this._activeMeshStage.clear();
             this._cameraDrawRenderTargetStage.clear();
             this._beforeCameraDrawStage.clear();
             this._beforeRenderingGroupDrawStage.clear();
@@ -28493,9 +28505,6 @@ var BABYLON;
             this._softwareSkinnedMeshes.dispose();
             this._renderTargets.dispose();
             this._registeredForLateAnimationBindings.dispose();
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer.dispose();
-            }
             this._meshesForIntersections.dispose();
             this._toBeDisposed.dispose();
             // Abort active requests
@@ -29086,9 +29095,6 @@ var BABYLON;
                 var component = _e[_d];
                 component.rebuild();
             }
-            if (this._boundingBoxRenderer) {
-                this._boundingBoxRenderer._rebuild();
-            }
             for (var _f = 0, _g = this.particleSystems; _f < _g.length; _f++) {
                 var system = _g[_f];
                 system.rebuild();
@@ -29488,7 +29494,7 @@ var BABYLON;
             this.textures.forEach(function (o) {
                 _this.scene.addTexture(o);
             });
-            for (var _i = 0, _a = this.scene._components; _i < _a.length; _i++) {
+            for (var _i = 0, _a = this.scene._serializableComponents; _i < _a.length; _i++) {
                 var component = _a[_i];
                 component.addFromContainer(this.scene);
             }
@@ -29545,7 +29551,7 @@ var BABYLON;
             this.textures.forEach(function (o) {
                 _this.scene.removeTexture(o);
             });
-            for (var _i = 0, _a = this.scene._components; _i < _a.length; _i++) {
+            for (var _i = 0, _a = this.scene._serializableComponents; _i < _a.length; _i++) {
                 var component = _a[_i];
                 component.removeFromContainer(this.scene);
             }
@@ -89251,33 +89257,85 @@ var BABYLON;
 
 var BABYLON;
 (function (BABYLON) {
+    Object.defineProperty(BABYLON.Scene.prototype, "forceShowBoundingBoxes", {
+        get: function () {
+            return this._forceShowBoundingBoxes || false;
+        },
+        set: function (value) {
+            this._forceShowBoundingBoxes = value;
+            // Lazyly creates a BB renderer if needed.
+            if (value) {
+                this.getBoundingBoxRenderer();
+            }
+        },
+        enumerable: true,
+        configurable: true
+    });
+    BABYLON.Scene.prototype.getBoundingBoxRenderer = function () {
+        if (!this._boundingBoxRenderer) {
+            this._boundingBoxRenderer = new BoundingBoxRenderer(this);
+        }
+        return this._boundingBoxRenderer;
+    };
     var BoundingBoxRenderer = /** @class */ (function () {
         function BoundingBoxRenderer(scene) {
+            /**
+             * The component name helpfull to identify the component in the list of scene components.
+             */
+            this.name = BABYLON.SceneComponentConstants.NAME_BOUNDINGBOXRENDERER;
             this.frontColor = new BABYLON.Color3(1, 1, 1);
             this.backColor = new BABYLON.Color3(0.1, 0.1, 0.1);
             this.showBackLines = true;
             this.renderList = new BABYLON.SmartArray(32);
             this._vertexBuffers = {};
-            this._scene = scene;
+            this.scene = scene;
+            scene._addComponent(this);
         }
+        /**
+         * Registers the component in a given scene
+         */
+        BoundingBoxRenderer.prototype.register = function () {
+            this.scene._beforeEvaluateActiveMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_BEFOREEVALUATEACTIVEMESH_BOUNDINGBOXRENDERER, this, this.reset);
+            this.scene._activeMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_ACTIVEMESH_BOUNDINGBOXRENDERER, this, this._activeMesh);
+            this.scene._evaluateSubMeshStage.registerStep(BABYLON.SceneComponentConstants.STEP_EVALUATESUBMESH_BOUNDINGBOXRENDERER, this, this._evaluateSubMesh);
+            this.scene._afterCameraDrawStage.registerStep(BABYLON.SceneComponentConstants.STEP_AFTERCAMERADRAW_BOUNDINGBOXRENDERER, this, this.render);
+        };
+        BoundingBoxRenderer.prototype._evaluateSubMesh = function (mesh, subMesh) {
+            if (mesh.showSubMeshesBoundingBox) {
+                var boundingInfo = subMesh.getBoundingInfo();
+                if (boundingInfo !== null && boundingInfo !== undefined) {
+                    this.renderList.push(boundingInfo.boundingBox);
+                }
+            }
+        };
+        BoundingBoxRenderer.prototype._activeMesh = function (sourceMesh, mesh) {
+            if (sourceMesh.showBoundingBox || this.scene.forceShowBoundingBoxes) {
+                var boundingInfo = sourceMesh.getBoundingInfo();
+                this.renderList.push(boundingInfo.boundingBox);
+            }
+        };
         BoundingBoxRenderer.prototype._prepareRessources = function () {
             if (this._colorShader) {
                 return;
             }
-            this._colorShader = new BABYLON.ShaderMaterial("colorShader", this._scene, "color", {
+            this._colorShader = new BABYLON.ShaderMaterial("colorShader", this.scene, "color", {
                 attributes: [BABYLON.VertexBuffer.PositionKind],
                 uniforms: ["world", "viewProjection", "color"]
             });
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             var boxdata = BABYLON.VertexData.CreateBox({ size: 1.0 });
             this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = new BABYLON.VertexBuffer(engine, boxdata.positions, BABYLON.VertexBuffer.PositionKind, false);
             this._createIndexBuffer();
         };
         BoundingBoxRenderer.prototype._createIndexBuffer = function () {
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             this._indexBuffer = engine.createIndexBuffer([0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 7, 1, 6, 2, 5, 3, 4]);
         };
-        BoundingBoxRenderer.prototype._rebuild = function () {
+        /**
+         * Rebuilds the elements related to this component in case of
+         * context lost for instance.
+         */
+        BoundingBoxRenderer.prototype.rebuild = function () {
             var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
             if (vb) {
                 vb._rebuild();
@@ -89295,7 +89353,7 @@ var BABYLON;
             if (!this._colorShader.isReady()) {
                 return;
             }
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             engine.setDepthWrite(false);
             this._colorShader._preBind();
             for (var boundingBoxIndex = 0; boundingBoxIndex < this.renderList.length; boundingBoxIndex++) {
@@ -89312,7 +89370,7 @@ var BABYLON;
                 if (this.showBackLines) {
                     // Back
                     engine.setDepthFunctionToGreaterOrEqual();
-                    this._scene.resetCachedMaterial();
+                    this.scene.resetCachedMaterial();
                     this._colorShader.setColor4("color", this.backColor.toColor4());
                     this._colorShader.bind(worldMatrix);
                     // Draw order
@@ -89320,7 +89378,7 @@ var BABYLON;
                 }
                 // Front
                 engine.setDepthFunctionToLess();
-                this._scene.resetCachedMaterial();
+                this.scene.resetCachedMaterial();
                 this._colorShader.setColor4("color", this.frontColor.toColor4());
                 this._colorShader.bind(worldMatrix);
                 // Draw order
@@ -89335,7 +89393,7 @@ var BABYLON;
             if (!this._colorShader.isReady() || !mesh._boundingInfo) {
                 return;
             }
-            var engine = this._scene.getEngine();
+            var engine = this.scene.getEngine();
             engine.setDepthWrite(false);
             engine.setColorWrite(false);
             this._colorShader._preBind();
@@ -89349,7 +89407,7 @@ var BABYLON;
                 .multiply(boundingBox.getWorldMatrix());
             engine.bindBuffers(this._vertexBuffers, this._indexBuffer, this._colorShader.getEffect());
             engine.setDepthFunctionToLess();
-            this._scene.resetCachedMaterial();
+            this.scene.resetCachedMaterial();
             this._colorShader.bind(worldMatrix);
             engine.drawElementsType(BABYLON.Material.LineListDrawMode, 0, 24);
             this._colorShader.unbind();
@@ -89368,7 +89426,7 @@ var BABYLON;
                 buffer.dispose();
                 this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = null;
             }
-            this._scene.getEngine()._releaseBuffer(this._indexBuffer);
+            this.scene.getEngine()._releaseBuffer(this._indexBuffer);
         };
         return BoundingBoxRenderer;
     }());
@@ -99710,7 +99768,7 @@ var BABYLON;
                 }
             }
             // Components
-            for (var _b = 0, _c = scene._components; _b < _c.length; _b++) {
+            for (var _b = 0, _c = scene._serializableComponents; _b < _c.length; _b++) {
                 var component = _c[_b];
                 component.serialize(serializationObject);
             }
@@ -99907,43 +99965,6 @@ var BABYLON;
             }
         };
         /**
-         * Serializes the component data to the specified json object
-         * @param serializationObject The object to serialize to
-         */
-        LayerSceneComponent.prototype.serialize = function (serializationObject) {
-            // TODO. Implement layer serialization
-            // serializationObject.layers = [];
-            // for (let layer of this._layers) {
-            //     if (layer.serialize) {
-            //         serializationObject.layers.push(layer.serialize());
-            //     }
-            // }
-        };
-        /**
-         * Adds all the element from the container to the scene
-         * @param container the container holding the elements
-         */
-        LayerSceneComponent.prototype.addFromContainer = function (container) {
-            if (!container.layers) {
-                return;
-            }
-            // container.layers.forEach((o) => {
-            //     this.scene.addLayer(o);
-            // });
-        };
-        /**
-         * Removes all the elements in the container from the scene
-         * @param container contains the elements to remove
-         */
-        LayerSceneComponent.prototype.removeFromContainer = function (container) {
-            if (!container.layers) {
-                return;
-            }
-            // container.layers.forEach((o) => {
-            //     this.scene.removeLayer(o);
-            // });
-        };
-        /**
          * Disposes the component and the associated ressources.
          */
         LayerSceneComponent.prototype.dispose = function () {

+ 21 - 2
dist/preview release/viewer/babylon.viewer.d.ts

@@ -20,6 +20,7 @@ declare module BabylonViewer {
     
     
     
+    
     /**
         * BabylonJS Viewer
         *
@@ -402,10 +403,10 @@ declare module BabylonViewer {
                 * Only provided information will be updated, old configuration values will be kept.
                 * If this.configuration was manually changed, you can trigger this function with no parameters,
                 * and the entire configuration will be updated.
-                * @param newConfiguration the partial configuration to update
+                * @param newConfiguration the partial configuration to update or a URL to a JSON holding the updated configuration
                 *
                 */
-            updateConfiguration(newConfiguration?: Partial<ViewerConfiguration>): void;
+            updateConfiguration(newConfiguration?: Partial<ViewerConfiguration> | string): void;
             /**
                 * this is used to register native functions using the configuration object.
                 * This will configure the observers.
@@ -970,6 +971,17 @@ declare module BabylonViewer {
 }
 
 declare module BabylonViewer {
+    
+    /**
+      *
+      * @param name the name of the custom optimizer configuration
+      * @param upgrade set to true if you want to upgrade optimizer and false if you want to degrade
+      */
+    export function getCustomOptimizerByName(name: string, upgrade?: boolean): (sceneManager: SceneManager) => boolean;
+    export function registerCustomOptimizer(name: string, optimizer: (sceneManager: SceneManager) => boolean): void;
+}
+
+declare module BabylonViewer {
     /**
         * Will attach an init function the the DOMContentLoaded event.
         * The init function will be removed automatically after the event was triggered.
@@ -2270,6 +2282,13 @@ declare module BabylonViewer {
         disableTeleportation?: boolean;
         overrideFloorMeshName?: string;
         vrOptions?: BABYLON.VRExperienceHelperOptions;
+        modelHeightCorrection?: number | boolean;
+        rotateUsingControllers?: boolean;
+        cameraPosition?: {
+            x: number;
+            y: number;
+            z: number;
+        };
     }
 }
 

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 62 - 62
dist/preview release/viewer/babylon.viewer.js


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 258 - 203
dist/preview release/viewer/babylon.viewer.max.js


+ 22 - 3
dist/preview release/viewer/babylon.viewer.module.d.ts

@@ -20,6 +20,7 @@ declare module 'babylonjs-viewer' {
     import { AnimationPlayMode, AnimationState } from 'babylonjs-viewer/model/modelAnimation';
     import { ILoaderPlugin } from 'babylonjs-viewer/loader/plugins/loaderPlugin';
     import { AbstractViewerNavbarButton } from 'babylonjs-viewer/templating/viewerTemplatePlugin';
+    import { registerCustomOptimizer } from 'babylonjs-viewer/optimizer/custom';
     /**
         * BabylonJS Viewer
         *
@@ -35,7 +36,7 @@ declare module 'babylonjs-viewer' {
         */
     function disposeAll(): void;
     const Version: string;
-    export { BABYLON, Version, InitTags, DefaultViewer, AbstractViewer, viewerGlobals, telemetryManager, disableInit, viewerManager, mapperManager, disposeAll, ModelLoader, ViewerModel, AnimationPlayMode, AnimationState, ModelState, ILoaderPlugin, AbstractViewerNavbarButton };
+    export { BABYLON, Version, InitTags, DefaultViewer, AbstractViewer, viewerGlobals, telemetryManager, disableInit, viewerManager, mapperManager, disposeAll, ModelLoader, ViewerModel, AnimationPlayMode, AnimationState, ModelState, ILoaderPlugin, AbstractViewerNavbarButton, registerCustomOptimizer };
     export * from 'babylonjs-viewer/configuration';
 }
 
@@ -402,10 +403,10 @@ declare module 'babylonjs-viewer/viewer/viewer' {
                 * Only provided information will be updated, old configuration values will be kept.
                 * If this.configuration was manually changed, you can trigger this function with no parameters,
                 * and the entire configuration will be updated.
-                * @param newConfiguration the partial configuration to update
+                * @param newConfiguration the partial configuration to update or a URL to a JSON holding the updated configuration
                 *
                 */
-            updateConfiguration(newConfiguration?: Partial<ViewerConfiguration>): void;
+            updateConfiguration(newConfiguration?: Partial<ViewerConfiguration> | string): void;
             /**
                 * this is used to register native functions using the configuration object.
                 * This will configure the observers.
@@ -969,6 +970,17 @@ declare module 'babylonjs-viewer/templating/viewerTemplatePlugin' {
     }
 }
 
+declare module 'babylonjs-viewer/optimizer/custom' {
+    import { SceneManager } from "babylonjs-viewer/managers/sceneManager";
+    /**
+      *
+      * @param name the name of the custom optimizer configuration
+      * @param upgrade set to true if you want to upgrade optimizer and false if you want to degrade
+      */
+    export function getCustomOptimizerByName(name: string, upgrade?: boolean): (sceneManager: SceneManager) => boolean;
+    export function registerCustomOptimizer(name: string, optimizer: (sceneManager: SceneManager) => boolean): void;
+}
+
 declare module 'babylonjs-viewer/initializer' {
     /**
         * Will attach an init function the the DOMContentLoaded event.
@@ -2270,6 +2282,13 @@ declare module 'babylonjs-viewer/configuration/interfaces/vrConfiguration' {
         disableTeleportation?: boolean;
         overrideFloorMeshName?: string;
         vrOptions?: VRExperienceHelperOptions;
+        modelHeightCorrection?: number | boolean;
+        rotateUsingControllers?: boolean;
+        cameraPosition?: {
+            x: number;
+            y: number;
+            z: number;
+        };
     }
 }