From 41c453bf194bc05269b98ccf416e69e1df1510bb Mon Sep 17 00:00:00 2001 From: jerrywwl Date: Wed, 2 Jan 2019 16:15:26 +0800 Subject: [PATCH] rename scene-manager to render-scene --- cocos/core/root.ts | 34 +++++++++---------- cocos/renderer/scene/camera.js | 8 ++--- cocos/renderer/scene/light.js | 8 ++--- .../scene/render-scene.ts} | 28 +++++++++------ 4 files changed, 42 insertions(+), 36 deletions(-) rename cocos/{scene/scene-manager.ts => renderer/scene/render-scene.ts} (78%) diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 6cf372bb49..9649d82e3f 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -3,7 +3,7 @@ import { GFXDevice } from "../gfx/device"; import { RenderView, RenderViewInfo, RenderViewPriority } from "../pipeline/render-view"; import { RenderPipeline } from "../pipeline/render-pipeline"; import { ForwardPipeline } from "../pipeline/forward/forward-pipeline"; -import { SceneManager, SceneManagerInfo } from "../scene/scene-manager"; +import { RenderScene, RenderSceneInfo } from "../renderer/scene/render-scene"; export interface RootInfo { }; @@ -38,7 +38,7 @@ export class Root { public destroy() { this.destroyViews(); - this.destroySceneManagers(); + this.destroyScenes(); if (this._pipeline) { this._pipeline.destroy(); @@ -87,31 +87,31 @@ export class Root { this._windows = []; } - public createSceneManager(info: SceneManagerInfo): SceneManager | null { - let scene = new SceneManager; + public createScene(info: RenderSceneInfo): RenderScene | null { + let scene = new RenderScene; if(scene.initialize(info)) { - this._sceneMgrs.push(scene); + this._scenes.push(scene); return scene; } else { return null; } } - public destroySceneManager(sceneMgr: SceneManager) { - for (let i = 0; i < this._sceneMgrs.length; ++i) { - if (this._sceneMgrs[i] === sceneMgr) { - sceneMgr.destroy(); - this._sceneMgrs.splice(i); + public destroyScene(scene: RenderScene) { + for (let i = 0; i < this._scenes.length; ++i) { + if (this._scenes[i] === scene) { + scene.destroy(); + this._scenes.splice(i); return; } } } - public destroySceneManagers() { - for (let i = 0; i < this._sceneMgrs.length; ++i) { - this._sceneMgrs[i].destroy(); + public destroyScenes() { + for (let i = 0; i < this._scenes.length; ++i) { + this._scenes[i].destroy(); } - this._sceneMgrs = []; + this._scenes = []; } public createView(info: RenderViewInfo): RenderView | null { @@ -155,8 +155,8 @@ export class Root { return this._pipeline; } - public get sceneManagers(): SceneManager[] { - return this._sceneMgrs; + public get sceneManagers(): RenderScene[] { + return this._scenes; } public get views(): RenderView[] { @@ -167,6 +167,6 @@ export class Root { private _windows: GFXWindow[] = []; private _mainWindow: GFXWindow | null = null; private _pipeline: RenderPipeline | null = null; - private _sceneMgrs: SceneManager[] = []; + private _scenes: RenderScene[] = []; private _views: RenderView[] = []; }; diff --git a/cocos/renderer/scene/camera.js b/cocos/renderer/scene/camera.js index 5511fc08ff..8e9ec33d2a 100644 --- a/cocos/renderer/scene/camera.js +++ b/cocos/renderer/scene/camera.js @@ -18,9 +18,9 @@ export default class Camera { /** * Setup a default perspective camera */ - constructor(sceneMgr, name) { + constructor(scene, name) { - this._sceneMgr = sceneMgr; + this._scene = scene; this._name = name; this._poolID = -1; @@ -55,8 +55,8 @@ export default class Camera { this._orthoHeight = 10; } - get sceneMgr() { - return this._sceneMgr; + get scene() { + return this._scene; } get name() { diff --git a/cocos/renderer/scene/light.js b/cocos/renderer/scene/light.js index 61d5c3a234..16e4f59a87 100644 --- a/cocos/renderer/scene/light.js +++ b/cocos/renderer/scene/light.js @@ -51,9 +51,9 @@ export default class Light { /** * Setup a default directional light with no shadows */ - constructor(sceneMgr, name) { + constructor(scene, name) { - this._sceneMgr = sceneMgr; + this._scene = scene; this._name = name; this._poolID = -1; @@ -94,8 +94,8 @@ export default class Light { this._shadowFrustumSize = 50; // used for directional light. } - get sceneMgr() { - return this._sceneMgr; + get scene() { + return this._scene; } get name() { diff --git a/cocos/scene/scene-manager.ts b/cocos/renderer/scene/render-scene.ts similarity index 78% rename from cocos/scene/scene-manager.ts rename to cocos/renderer/scene/render-scene.ts index b4c764e478..dd31338cb9 100644 --- a/cocos/scene/scene-manager.ts +++ b/cocos/renderer/scene/render-scene.ts @@ -1,25 +1,29 @@ -import Node from "../scene-graph/node"; -import Camera from "../renderer/scene/camera"; -import Light from "../renderer/scene/light"; +import Node from "../../scene-graph/node"; +import Camera from "./camera"; +import Light from "./light"; -export interface SceneManagerInfo { +export interface RenderSceneInfo { name: string; }; export interface SceneNodeInfo { name: string; - isStatic: boolean; + isStatic?: boolean; //parent: Node; } -export class SceneManager { +export class RenderScene { constructor() { } - public initialize(info: SceneManagerInfo): boolean { + public initialize(info: RenderSceneInfo): boolean { this._name = info.name; + let cameraNode = this.createNode({ name: "mainCamNode", isStatic: false }); + this._mainCamera = this.createCamera("mainCamera"); + this._mainCamera.setNode(cameraNode); + return true; } @@ -69,6 +73,7 @@ export class SceneManager { public destroyCameras() { this._cameras = []; + this._mainCamera = null; } public getCamera(name: string): Camera | null { @@ -124,8 +129,9 @@ export class SceneManager { return this._lights; } - protected _name: string = ""; - protected _nodes: Map = new Map; - protected _cameras: Camera[] = []; - protected _lights: Light[] = []; + private _name: string = ""; + private _nodes: Map = new Map; + private _cameras: Camera[] = []; + private _mainCamera: Camera | null = null; + private _lights: Light[] = []; };