Procházet zdrojové kódy

scene components circular dependencies

sebavan před 6 roky
rodič
revize
2f480b9896

+ 1 - 31
Tools/Config/tempCircularValidation/core.json

@@ -1,22 +1,4 @@
 {
-    "../../src/Layers/effectLayer.ts": [
-        "../../src/Layers/effectLayerSceneComponent.ts"
-    ],
-    "../../src/Layers/effectLayerSceneComponent.ts": [
-        "../../src/Layers/effectLayer.ts"
-    ],
-    "../../src/LensFlares/lensFlareSystem.ts": [
-        "../../src/LensFlares/lensFlareSystemSceneComponent.ts"
-    ],
-    "../../src/LensFlares/lensFlareSystemSceneComponent.ts": [
-        "../../src/LensFlares/lensFlareSystem.ts"
-    ],
-    "../../src/Lights/Shadows/shadowGenerator.ts": [
-        "../../src/Lights/Shadows/shadowGeneratorSceneComponent.ts"
-    ],
-    "../../src/Lights/Shadows/shadowGeneratorSceneComponent.ts": [
-        "../../src/Lights/Shadows/shadowGenerator.ts"
-    ],
     "../../src/Particles/particleHelper.ts": [
         "../../src/Particles/particleSystemSet.ts"
     ],
@@ -29,17 +11,5 @@
     "../../src/Particles/subEmitter.ts": [
         "../../src/Particles/particleSystem.ts"
     ],
-    "../../src/Rendering/depthRenderer.ts": [
-        "../../src/Rendering/depthRendererSceneComponent.ts"
-    ],
-    "../../src/Rendering/depthRendererSceneComponent.ts": [
-        "../../src/Rendering/depthRenderer.ts"
-    ],
-    "../../src/Rendering/geometryBufferRenderer.ts": [
-        "../../src/Rendering/geometryBufferRendererSceneComponent.ts"
-    ],
-    "../../src/Rendering/geometryBufferRendererSceneComponent.ts": [
-        "../../src/Rendering/geometryBufferRenderer.ts"
-    ],
-    "errorCount": 14
+    "errorCount": 4
 }

+ 6 - 7
src/Layers/effectLayer.ts

@@ -13,10 +13,8 @@ import { SubMesh } from "../Meshes/subMesh";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { Mesh } from "../Meshes/mesh";
 import { PostProcess } from "../PostProcesses/postProcess";
-import { SceneComponentConstants } from "../sceneComponent";
 import { _TimeToken } from "../Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "../States/index";
-import { EffectLayerSceneComponent } from "./effectLayerSceneComponent";
 import { BaseTexture } from "../Materials/Textures/baseTexture";
 import { Texture } from "../Materials/Textures/texture";
 import { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
@@ -146,6 +144,11 @@ import "../Shaders/glowMapGeneration.vertex";
          */
         public onSizeChangedObservable = new Observable<EffectLayer>();
 
+        /** @hidden */
+        public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {
+            throw "Import EffectLayerSceneComponent before creating EffectLayer.";
+        }
+
         /**
          * Instantiates a new effect Layer and references it in the scene.
          * @param name The name of the layer
@@ -158,11 +161,7 @@ import "../Shaders/glowMapGeneration.vertex";
             this.name = name;
 
             this._scene = scene || EngineStore.LastCreatedScene;
-            let component = this._scene._getComponent(SceneComponentConstants.NAME_EFFECTLAYER) as EffectLayerSceneComponent;
-            if (!component) {
-                component = new EffectLayerSceneComponent(this._scene);
-                this._scene._addComponent(component);
-            }
+            EffectLayer._SceneComponentInitialization(this._scene);
 
             this._engine = this._scene.getEngine();
             this._maxSize = this._engine.getCaps().maxTextureSize;

+ 8 - 0
src/Layers/effectLayerSceneComponent.ts

@@ -255,3 +255,11 @@ declare module "../abstractScene" {
             }
         }
     }
+
+    EffectLayer._SceneComponentInitialization = (scene: Scene) => {
+        let component = scene._getComponent(SceneComponentConstants.NAME_EFFECTLAYER) as EffectLayerSceneComponent;
+        if (!component) {
+            component = new EffectLayerSceneComponent(scene);
+            scene._addComponent(component);
+        }
+    };

+ 6 - 7
src/LensFlares/lensFlareSystem.ts

@@ -9,11 +9,9 @@ import { VertexBuffer } from "../Meshes/buffer";
 import { Ray } from "../Culling/ray";
 import { Effect } from "../Materials/effect";
 import { Material } from "../Materials/material";
-import { SceneComponentConstants } from "../sceneComponent";
 import { _TimeToken } from "../Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "../States/index";
 import { LensFlare } from "./lensFlare";
-import { LensFlareSystemSceneComponent } from "./lensFlareSystemSceneComponent";
 import { Constants } from "../Engines/constants";
 
 import "../Shaders/lensFlare.fragment";
@@ -65,6 +63,11 @@ import "../Shaders/lensFlare.vertex";
         private _positionY: number;
         private _isEnabled = true;
 
+        /** @hidden */
+        public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {
+            throw "Import LensFlareSystemSceneComponent before creating LensFlareSystem.";
+        }
+
         /**
          * Instantiates a lens flare system.
          * This represents a Lens Flare System or the shiny effect created by the light reflection on the  camera lenses.
@@ -83,11 +86,7 @@ import "../Shaders/lensFlare.vertex";
             scene: Scene) {
 
             this._scene = scene || EngineStore.LastCreatedScene;
-            let component = this._scene._getComponent(SceneComponentConstants.NAME_LENSFLARESYSTEM) as LensFlareSystemSceneComponent;
-            if (!component) {
-                component = new LensFlareSystemSceneComponent(this._scene);
-                scene._addComponent(component);
-            }
+            LensFlareSystem._SceneComponentInitialization(this._scene);
 
             this._emitter = emitter;
             this.id = name;

+ 8 - 0
src/LensFlares/lensFlareSystemSceneComponent.ts

@@ -196,3 +196,11 @@ declare module "../abstractScene" {
             }
         }
     }
+
+    LensFlareSystem._SceneComponentInitialization = (scene: Scene) => {
+        let component = scene._getComponent(SceneComponentConstants.NAME_LENSFLARESYSTEM) as LensFlareSystemSceneComponent;
+        if (!component) {
+            component = new LensFlareSystemSceneComponent(scene);
+            scene._addComponent(component);
+        }
+    };

+ 6 - 7
src/Lights/Shadows/shadowGenerator.ts

@@ -9,7 +9,6 @@ import { Mesh } from "../../Meshes/mesh";
 
 import { IShadowLight } from "../../Lights/shadowLight";
 import { Light } from "../../Lights/light";
-import { ShadowGeneratorSceneComponent } from "./shadowGeneratorSceneComponent";
 
 import { Material } from "../../Materials/material";
 import { MaterialDefines } from "../../Materials/materialDefines";
@@ -20,7 +19,6 @@ import { RenderTargetTexture } from "../../Materials/Textures/renderTargetTextur
 
 import { PostProcess } from "../../PostProcesses/postProcess";
 import { BlurPostProcess } from "../../PostProcesses/blurPostProcess";
-import { SceneComponentConstants } from "../../sceneComponent";
 import { _TimeToken } from "../../Instrumentation/timeToken";
 import { _DepthCullingState, _StencilState, _AlphaState } from "../../States/index";
 import { Constants } from "../../Engines/constants";
@@ -670,6 +668,11 @@ import "../../Shaders/depthBoxBlur.fragment";
         private _textureType: number;
         private _defaultTextureMatrix = Matrix.Identity();
 
+        /** @hidden */
+        public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {
+            throw "Import ShadowGeneratorSceneComponent before creating ShadowGenerator.";
+        }
+
         /**
          * Creates a ShadowGenerator object.
          * A ShadowGenerator is the required tool to use the shadows.
@@ -685,11 +688,7 @@ import "../../Shaders/depthBoxBlur.fragment";
             this._scene = light.getScene();
             light._shadowGenerator = this;
 
-            let component = this._scene._getComponent(SceneComponentConstants.NAME_SHADOWGENERATOR);
-            if (!component) {
-                component = new ShadowGeneratorSceneComponent(this._scene);
-                this._scene._addComponent(component);
-            }
+            ShadowGenerator._SceneComponentInitialization(this._scene);
 
             // Texture type fallback from float to int if not supported.
             var caps = this._scene.getEngine().getCaps();

+ 8 - 0
src/Lights/Shadows/shadowGeneratorSceneComponent.ts

@@ -114,3 +114,11 @@ import { AbstractScene } from "../../abstractScene";
             }
         }
     }
+
+    ShadowGenerator._SceneComponentInitialization = (scene: Scene) => {
+        let component = scene._getComponent(SceneComponentConstants.NAME_SHADOWGENERATOR);
+        if (!component) {
+            component = new ShadowGeneratorSceneComponent(scene);
+            scene._addComponent(component);
+        }
+    }

+ 6 - 8
src/Rendering/depthRenderer.ts

@@ -10,8 +10,6 @@ import { Effect } from "../Materials/effect";
 import { Material } from "../Materials/material";
 import { Camera } from "../Cameras/camera";
 import { Constants } from "../Engines/constants";
-import { SceneComponentConstants } from "../sceneComponent";
-import { DepthRendererSceneComponent } from "./depthRendererSceneComponent";
 
 import "../Shaders/depth.fragment";
 import "../Shaders/depth.vertex";
@@ -35,6 +33,11 @@ import "../Shaders/depth.vertex";
          */
         public useOnlyInActiveCamera: boolean = false;
 
+        /** @hidden */
+        public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {
+            throw "Import DepthRendererSceneComponent before creating DepthRenderer.";
+        }
+
         /**
          * Instantiates a depth renderer
          * @param scene The scene the renderer belongs to
@@ -43,12 +46,7 @@ import "../Shaders/depth.vertex";
          */
         constructor(scene: Scene, type: number = Constants.TEXTURETYPE_FLOAT, camera: Nullable<Camera> = null) {
             this._scene = scene;
-            // Register the G Buffer component to the scene.
-            let component = scene._getComponent(SceneComponentConstants.NAME_DEPTHRENDERER) as DepthRendererSceneComponent;
-            if (!component) {
-                component = new DepthRendererSceneComponent(scene);
-                scene._addComponent(component);
-            }
+            DepthRenderer._SceneComponentInitialization(this._scene);
 
             this._camera = camera;
             var engine = scene.getEngine();

+ 9 - 0
src/Rendering/depthRendererSceneComponent.ts

@@ -131,3 +131,12 @@ declare module "../scene" {
             }
         }
     }
+
+    DepthRenderer._SceneComponentInitialization = (scene: Scene) => {
+        // Register the G Buffer component to the scene.
+        let component = scene._getComponent(SceneComponentConstants.NAME_DEPTHRENDERER) as DepthRendererSceneComponent;
+        if (!component) {
+            component = new DepthRendererSceneComponent(scene);
+            scene._addComponent(component);
+        }
+    };

+ 6 - 8
src/Rendering/geometryBufferRenderer.ts

@@ -8,9 +8,7 @@ import { Texture } from "../Materials/Textures/texture";
 import { MultiRenderTarget } from "../Materials/Textures/multiRenderTarget";
 import { Effect } from "../Materials/effect";
 import { Material } from "../Materials/material";
-import { GeometryBufferRendererSceneComponent } from "./geometryBufferRendererSceneComponent";
 import { Scene } from "../scene";
-import { SceneComponentConstants } from "../sceneComponent";
 
 import "../Shaders/geometry.fragment";
 import "../Shaders/geometry.vertex";
@@ -124,6 +122,11 @@ import "../Shaders/geometry.vertex";
             return this._ratio;
         }
 
+        /** @hidden */
+        public static _SceneComponentInitialization: (scene: Scene) => void = (_) => {
+            throw "Import GeometryBufferRendererSceneComponent before creating GeometryBufferRenderer.";
+        }
+
         /**
          * Creates a new G Buffer for the scene
          * @param scene The scene the buffer belongs to
@@ -133,12 +136,7 @@ import "../Shaders/geometry.vertex";
             this._scene = scene;
             this._ratio = ratio;
 
-            // Register the G Buffer component to the scene.
-            let component = scene._getComponent(SceneComponentConstants.NAME_GEOMETRYBUFFERRENDERER) as GeometryBufferRendererSceneComponent;
-            if (!component) {
-                component = new GeometryBufferRendererSceneComponent(scene);
-                scene._addComponent(component);
-            }
+            GeometryBufferRenderer._SceneComponentInitialization(this._scene);
 
             // Render target
             this._createRenderTargets();

+ 9 - 0
src/Rendering/geometryBufferRendererSceneComponent.ts

@@ -115,3 +115,12 @@ declare module "../scene" {
             }
         }
     }
+
+    GeometryBufferRenderer._SceneComponentInitialization = (scene: Scene) => {
+        // Register the G Buffer component to the scene.
+        let component = scene._getComponent(SceneComponentConstants.NAME_GEOMETRYBUFFERRENDERER) as GeometryBufferRendererSceneComponent;
+        if (!component) {
+            component = new GeometryBufferRendererSceneComponent(scene);
+            scene._addComponent(component);
+        }
+    };