Bläddra i källkod

Externalize Scene Components.

sebastien 7 år sedan
förälder
incheckning
f7477b6b7c

+ 5 - 2
Tools/Gulp/config.json

@@ -732,7 +732,8 @@
         },
         "geometryBufferRenderer": {
             "files": [
-                "../../src/Rendering/babylon.geometryBufferRenderer.js"
+                "../../src/Rendering/babylon.geometryBufferRenderer.js",
+                "../../src/Rendering/babylon.geometryBufferRendererSceneComponent.js"
             ],
             "dependUpon": [
                 "core"
@@ -988,7 +989,8 @@
             ],
             "dependUpon": [
                 "renderingPipeline",
-                "depthRenderer"
+                "depthRenderer",
+                "geometryBufferRenderer"
             ],
             "shaders": [
                 "ssao.fragment",
@@ -1269,6 +1271,7 @@
         "optimizations": {
             "files": [
                 "../../src/Mesh/babylon.meshSimplification.js",
+                "../../src/Mesh/babylon.meshSimplificationSceneComponent.js",
                 "../../src/Mesh/babylon.meshLODLevel.js",
                 "../../src/Tools/babylon.sceneOptimizer.js"
             ],

+ 0 - 105
src/Mesh/babylon.meshSimplification.ts

@@ -1,57 +1,4 @@
 module BABYLON {
-    export interface Scene {
-        /** @hidden (Backing field) */
-        _simplificationQueue: SimplificationQueue;
-
-        /**
-         * Gets or sets the simplification queue attached to the scene
-         * @see http://doc.babylonjs.com/how_to/in-browser_mesh_simplification
-         */
-        simplificationQueue: SimplificationQueue;
-    }
-
-    Object.defineProperty(Scene.prototype, "simplificationQueue", {
-        get: function (this:Scene) {
-            if (!this._simplificationQueue) {
-                this._simplificationQueue = new SimplificationQueue();
-                let component = this._getComponent(SceneComponentConstants.NAME_SIMPLIFICATIONQUEUE) as SimplicationQueueSceneComponent;
-                if (!component) {
-                    component = new SimplicationQueueSceneComponent(this);
-                    this._addComponent(component);
-                }
-            }
-            return this._simplificationQueue;
-        },
-        set: function (this:Scene, value: SimplificationQueue) {
-            this._simplificationQueue = value;
-        },
-        enumerable: true,
-        configurable: true
-    });
-
-    export interface Mesh {
-        /**
-         * Simplify the mesh according to the given array of settings.
-         * Function will return immediately and will simplify async. It returns the Mesh.  
-         * @param settings a collection of simplification settings.
-         * @param parallelProcessing should all levels calculate parallel or one after the other.
-         * @param type the type of simplification to run.
-         * @param successCallback optional success callback to be called after the simplification finished processing all settings.
-         */
-        simplify(settings: Array<ISimplificationSettings>, parallelProcessing?: boolean, simplificationType?: SimplificationType, successCallback?: (mesh?: Mesh, submeshIndex?: number) => void): Mesh;
-    }
-
-    Mesh.prototype.simplify = function(settings: Array<ISimplificationSettings>, parallelProcessing: boolean = true, simplificationType: SimplificationType = SimplificationType.QUADRATIC, successCallback?: (mesh?: Mesh, submeshIndex?: number) => void): Mesh {
-        this.getScene().simplificationQueue.addTask({
-            settings: settings,
-            parallelProcessing: parallelProcessing,
-            mesh: this,
-            simplificationType: simplificationType,
-            successCallback: successCallback
-        });
-        return this;
-    }
-
     /**
      * A simplifier interface for future simplification implementations.
      */
@@ -797,56 +744,4 @@
             return error;
         }
     }
-
-    /**
-     * Defines the simplification queue scene component responsible to help scheduling the various simplification task
-     * created in a scene
-     */
-    export class SimplicationQueueSceneComponent implements ISceneComponent {
-        /**
-         * The component name helpfull to identify the component in the list of scene components.
-         */
-        public readonly name = SceneComponentConstants.NAME_SIMPLIFICATIONQUEUE;
-
-        /**
-         * The scene the component belongs to.
-         */
-        public scene: Scene;
-
-        /**
-         * Creates a new instance of the component for the given scene
-         * @param scene Defines the scene to register the component in
-         */
-        constructor(scene: Scene) {
-            this.scene = scene;
-        }
-
-        /**
-         * Registers the component in a given scene
-         */
-        public register(): void {
-            this.scene._beforeCameraUpdateStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERAUPDATE_SIMPLIFICATIONQUEUE, this, this._beforeCameraUpdate);
-        }
-
-        /**
-         * Rebuilds the elements related to this component in case of
-         * context lost for instance.
-         */
-        public rebuild(): void {
-            // Nothing to do for this component
-        }
-
-        /**
-         * Disposes the component and the associated ressources
-         */
-        public dispose(): void {
-            // Nothing to do for this component
-        }
-
-        private _beforeCameraUpdate(): void {
-            if (this.scene._simplificationQueue && !this.scene._simplificationQueue.running) {
-                this.scene._simplificationQueue.executeNext();
-            }
-        }
-    }
 } 

+ 106 - 0
src/Mesh/babylon.meshSimplificationSceneComponent.ts

@@ -0,0 +1,106 @@
+module BABYLON {
+    export interface Scene {
+        /** @hidden (Backing field) */
+        _simplificationQueue: SimplificationQueue;
+
+        /**
+         * Gets or sets the simplification queue attached to the scene
+         * @see http://doc.babylonjs.com/how_to/in-browser_mesh_simplification
+         */
+        simplificationQueue: SimplificationQueue;
+    }
+
+    Object.defineProperty(Scene.prototype, "simplificationQueue", {
+        get: function (this:Scene) {
+            if (!this._simplificationQueue) {
+                this._simplificationQueue = new SimplificationQueue();
+                let component = this._getComponent(SceneComponentConstants.NAME_SIMPLIFICATIONQUEUE) as SimplicationQueueSceneComponent;
+                if (!component) {
+                    component = new SimplicationQueueSceneComponent(this);
+                    this._addComponent(component);
+                }
+            }
+            return this._simplificationQueue;
+        },
+        set: function (this:Scene, value: SimplificationQueue) {
+            this._simplificationQueue = value;
+        },
+        enumerable: true,
+        configurable: true
+    });
+
+    export interface Mesh {
+        /**
+         * Simplify the mesh according to the given array of settings.
+         * Function will return immediately and will simplify async. It returns the Mesh.  
+         * @param settings a collection of simplification settings.
+         * @param parallelProcessing should all levels calculate parallel or one after the other.
+         * @param type the type of simplification to run.
+         * @param successCallback optional success callback to be called after the simplification finished processing all settings.
+         */
+        simplify(settings: Array<ISimplificationSettings>, parallelProcessing?: boolean, simplificationType?: SimplificationType, successCallback?: (mesh?: Mesh, submeshIndex?: number) => void): Mesh;
+    }
+
+    Mesh.prototype.simplify = function(settings: Array<ISimplificationSettings>, parallelProcessing: boolean = true, simplificationType: SimplificationType = SimplificationType.QUADRATIC, successCallback?: (mesh?: Mesh, submeshIndex?: number) => void): Mesh {
+        this.getScene().simplificationQueue.addTask({
+            settings: settings,
+            parallelProcessing: parallelProcessing,
+            mesh: this,
+            simplificationType: simplificationType,
+            successCallback: successCallback
+        });
+        return this;
+    }
+
+    /**
+     * Defines the simplification queue scene component responsible to help scheduling the various simplification task
+     * created in a scene
+     */
+    export class SimplicationQueueSceneComponent implements ISceneComponent {
+        /**
+         * The component name helpfull to identify the component in the list of scene components.
+         */
+        public readonly name = SceneComponentConstants.NAME_SIMPLIFICATIONQUEUE;
+
+        /**
+         * The scene the component belongs to.
+         */
+        public scene: Scene;
+
+        /**
+         * Creates a new instance of the component for the given scene
+         * @param scene Defines the scene to register the component in
+         */
+        constructor(scene: Scene) {
+            this.scene = scene;
+        }
+
+        /**
+         * Registers the component in a given scene
+         */
+        public register(): void {
+            this.scene._beforeCameraUpdateStage.registerStep(SceneComponentConstants.STEP_BEFORECAMERAUPDATE_SIMPLIFICATIONQUEUE, this, this._beforeCameraUpdate);
+        }
+
+        /**
+         * Rebuilds the elements related to this component in case of
+         * context lost for instance.
+         */
+        public rebuild(): void {
+            // Nothing to do for this component
+        }
+
+        /**
+         * Disposes the component and the associated ressources
+         */
+        public dispose(): void {
+            // Nothing to do for this component
+        }
+
+        private _beforeCameraUpdate(): void {
+            if (this.scene._simplificationQueue && !this.scene._simplificationQueue.running) {
+                this.scene._simplificationQueue.executeNext();
+            }
+        }
+    }
+} 

+ 2 - 112
src/Rendering/babylon.geometryBufferRenderer.ts

@@ -1,62 +1,4 @@
 module BABYLON {
-    export interface Scene {
-        /** @hidden (Backing field) */
-        _geometryBufferRenderer: Nullable<GeometryBufferRenderer>;
-
-        /**
-         * Gets or Sets the current geometry buffer associated to the scene.
-         */
-        geometryBufferRenderer: Nullable<GeometryBufferRenderer>;
-
-        /**
-         * Enables a GeometryBufferRender and associates it with the scene
-         * @param ratio defines the scaling ratio to apply to the renderer (1 by default which means same resolution)
-         * @returns the GeometryBufferRenderer
-         */
-        enableGeometryBufferRenderer(ratio?: number): Nullable<GeometryBufferRenderer>;
-
-        /**
-         * Disables the GeometryBufferRender associated with the scene
-         */
-        disableGeometryBufferRenderer(): void;
-    }
-
-    Object.defineProperty(Scene.prototype, "geometryBufferRenderer", {
-        get: function (this:Scene) {
-            this._geometryBufferRenderer;
-        },
-        set: function (this:Scene, value: Nullable<GeometryBufferRenderer>) {
-            if (value && value.isSupported) {
-                this._geometryBufferRenderer = value;
-            };
-        },
-        enumerable: true,
-        configurable: true
-    });
-
-    Scene.prototype.enableGeometryBufferRenderer = function(ratio: number = 1): Nullable<GeometryBufferRenderer> {
-        if (this._geometryBufferRenderer) {
-            return this._geometryBufferRenderer;
-        }
-
-        this._geometryBufferRenderer = new GeometryBufferRenderer(this, ratio);
-        if (!this._geometryBufferRenderer.isSupported) {
-            this._geometryBufferRenderer = null;
-        }
-
-        return this._geometryBufferRenderer;
-    }
-
-    Scene.prototype.disableGeometryBufferRenderer = function(): void {
-        if (!this._geometryBufferRenderer) {
-            return;
-        }
-
-        this._geometryBufferRenderer.dispose();
-        this._geometryBufferRenderer = null;
-    }
-
-
     /**
      * This renderer is helpfull to fill one of the render target with a geometry buffer.
      */
@@ -126,9 +68,9 @@ module BABYLON {
             this._ratio = ratio;
 
             // Register the G Buffer component to the scene.
-            let component = scene._getComponent(SceneComponentConstants.NAME_GEOMETRYBUFFER) as GeometryBufferSceneComponent;
+            let component = scene._getComponent(SceneComponentConstants.NAME_GEOMETRYBUFFER) as GeometryBufferRendererSceneComponent;
             if (!component) {
-                component = new GeometryBufferSceneComponent(scene);
+                component = new GeometryBufferRendererSceneComponent(scene);
                 scene._addComponent(component);
             }
 
@@ -334,56 +276,4 @@ module BABYLON {
             };
         }
     }
-
-    /**
-     * Defines the Geometry Buffer scene component responsible to manage a G-Buffer usefull
-     * in several rendering techniques.
-     */
-    export class GeometryBufferSceneComponent implements ISceneComponent {
-        /**
-         * The component name helpfull to identify the component in the list of scene components.
-         */
-        public readonly name = SceneComponentConstants.NAME_GEOMETRYBUFFER;
-
-        /**
-         * The scene the component belongs to.
-         */
-        public scene: Scene;
-
-        /**
-         * Creates a new instance of the component for the given scene
-         * @param scene Defines the scene to register the component in
-         */
-        constructor(scene: Scene) {
-            this.scene = scene;
-        }
-
-        /**
-         * Registers the component in a given scene
-         */
-        public register(): void {
-            this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_GEOMETRYBUFFER, this, this._gatherRenderTargets);
-        }
-
-        /**
-         * Rebuilds the elements related to this component in case of
-         * context lost for instance.
-         */
-        public rebuild(): void {
-            // Nothing to do for this component
-        }
-
-        /**
-         * Disposes the component and the associated ressources
-         */
-        public dispose(): void {
-            // Nothing to do for this component
-        }
-
-        private _gatherRenderTargets(renderTargets: SmartArrayNoDuplicate<RenderTargetTexture>): void {
-            if (this.scene._geometryBufferRenderer) {
-                renderTargets.push(this.scene._geometryBufferRenderer.getGBuffer());
-            }
-        }
-    }
 } 

+ 110 - 0
src/Rendering/babylon.geometryBufferRendererSceneComponent.ts

@@ -0,0 +1,110 @@
+module BABYLON {
+    export interface Scene {
+        /** @hidden (Backing field) */
+        _geometryBufferRenderer: Nullable<GeometryBufferRenderer>;
+
+        /**
+         * Gets or Sets the current geometry buffer associated to the scene.
+         */
+        geometryBufferRenderer: Nullable<GeometryBufferRenderer>;
+
+        /**
+         * Enables a GeometryBufferRender and associates it with the scene
+         * @param ratio defines the scaling ratio to apply to the renderer (1 by default which means same resolution)
+         * @returns the GeometryBufferRenderer
+         */
+        enableGeometryBufferRenderer(ratio?: number): Nullable<GeometryBufferRenderer>;
+
+        /**
+         * Disables the GeometryBufferRender associated with the scene
+         */
+        disableGeometryBufferRenderer(): void;
+    }
+
+    Object.defineProperty(Scene.prototype, "geometryBufferRenderer", {
+        get: function (this:Scene) {
+            this._geometryBufferRenderer;
+        },
+        set: function (this:Scene, value: Nullable<GeometryBufferRenderer>) {
+            if (value && value.isSupported) {
+                this._geometryBufferRenderer = value;
+            };
+        },
+        enumerable: true,
+        configurable: true
+    });
+
+    Scene.prototype.enableGeometryBufferRenderer = function(ratio: number = 1): Nullable<GeometryBufferRenderer> {
+        if (this._geometryBufferRenderer) {
+            return this._geometryBufferRenderer;
+        }
+
+        this._geometryBufferRenderer = new GeometryBufferRenderer(this, ratio);
+        if (!this._geometryBufferRenderer.isSupported) {
+            this._geometryBufferRenderer = null;
+        }
+
+        return this._geometryBufferRenderer;
+    }
+
+    Scene.prototype.disableGeometryBufferRenderer = function(): void {
+        if (!this._geometryBufferRenderer) {
+            return;
+        }
+
+        this._geometryBufferRenderer.dispose();
+        this._geometryBufferRenderer = null;
+    }
+
+    /**
+     * Defines the Geometry Buffer scene component responsible to manage a G-Buffer usefull
+     * in several rendering techniques.
+     */
+    export class GeometryBufferRendererSceneComponent implements ISceneComponent {
+        /**
+         * The component name helpfull to identify the component in the list of scene components.
+         */
+        public readonly name = SceneComponentConstants.NAME_GEOMETRYBUFFERRENDERER;
+
+        /**
+         * The scene the component belongs to.
+         */
+        public scene: Scene;
+
+        /**
+         * Creates a new instance of the component for the given scene
+         * @param scene Defines the scene to register the component in
+         */
+        constructor(scene: Scene) {
+            this.scene = scene;
+        }
+
+        /**
+         * Registers the component in a given scene
+         */
+        public register(): void {
+            this.scene._gatherRenderTargetsStage.registerStep(SceneComponentConstants.STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER, this, this._gatherRenderTargets);
+        }
+
+        /**
+         * Rebuilds the elements related to this component in case of
+         * context lost for instance.
+         */
+        public rebuild(): void {
+            // Nothing to do for this component
+        }
+
+        /**
+         * Disposes the component and the associated ressources
+         */
+        public dispose(): void {
+            // Nothing to do for this component
+        }
+
+        private _gatherRenderTargets(renderTargets: SmartArrayNoDuplicate<RenderTargetTexture>): void {
+            if (this.scene._geometryBufferRenderer) {
+                renderTargets.push(this.scene._geometryBufferRenderer.getGBuffer());
+            }
+        }
+    }
+} 

+ 2 - 2
src/babylon.sceneComponent.ts

@@ -11,7 +11,7 @@
         public static readonly NAME_PARTICLESYSTEM = "ParticleSystem";
         public static readonly NAME_GAMEPAD = "Gamepad";
         public static readonly NAME_SIMPLIFICATIONQUEUE = "SimplificationQueue";
-        public static readonly NAME_GEOMETRYBUFFER = "GeometryBuffer";
+        public static readonly NAME_GEOMETRYBUFFERRENDERER = "GeometryBufferRenderer";
 
         public static readonly STEP_ISREADYFORMESH_EFFECTLAYER = 0;
 
@@ -37,7 +37,7 @@
         public static readonly STEP_AFTERCAMERADRAW_EFFECTLAYER_DRAW = 3;
         public static readonly STEP_AFTERCAMERADRAW_LAYER = 4;
 
-        public static readonly STEP_GATHERRENDERTARGETS_GEOMETRYBUFFER = 0;
+        public static readonly STEP_GATHERRENDERTARGETS_GEOMETRYBUFFERRENDERER = 0;
     }
 
     /**