add model management to renderscene

This commit is contained in:
jerrywwl
2019-01-02 17:07:43 +08:00
parent 41c453bf19
commit 80d0339869
3 changed files with 62 additions and 2 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
import { Camera } from "../renderer/scene/camera";
import { GFXWindow } from "../gfx/window";
import { SceneManager } from "../scene/scene-manager";
import { RenderScene } from "../renderer/scene/render-scene";
export enum RenderViewPriority {
GENERAL = 100,
@@ -97,7 +97,7 @@ export class RenderView {
private _priority: number = 0;
private _width: number = 0;
private _height: number = 0;
private _sceneMgr: SceneManager | null = null;
private _sceneMgr: RenderScene | null = null;
private _camera: Camera | null = null;
private _isAttached: boolean = false;
private _isEnable: boolean = true;
+28
View File
@@ -9,8 +9,12 @@ export default class Model {
* Setup a default empty model
*/
constructor() {
this._scene = null;
this._id = 0;
this._type = 'default';
this._poolID = -1;
this._isEnable = true;
this._node = null;
this._inputAssembler = null;
this._effect = null;
@@ -23,6 +27,22 @@ export default class Model {
this._boundingShape = null;
}
setScene(scene) {
this._scene = scene;
if(this._scene) {
this._id = this._scene.generateModelId();
}
}
get scene() {
return this._scene;
}
get id() {
return this._id;
}
_updateTransform() {
if (!this._node._hasChanged || !this._boundingShape) return;
this._node.updateWorldTransformFull();
@@ -41,6 +61,14 @@ export default class Model {
this._boundingShape = aabb.clone(this._bsModelSpace);
}
enable(isEnable) {
this._isEnable = isEnable;
}
isEnable() {
return this._isEnable;
}
/**
* Get the hosting node of this camera
* @returns {Node} the hosting node
+32
View File
@@ -1,6 +1,7 @@
import Node from "../../scene-graph/node";
import Camera from "./camera";
import Light from "./light";
import Model from "./model";
export interface RenderSceneInfo {
name: string;
@@ -31,6 +32,7 @@ export class RenderScene {
this.destroyCameras();
this.destroyLights();
this.destroyNodes();
this.destroyModels();
}
public createNode(info: SceneNodeInfo): Node {
@@ -117,6 +119,30 @@ export class RenderScene {
return null;
}
public createModel<T extends Model>(clazz: new () => T): Model {
let model = new clazz;
model.setScene(this);
this._models.push(model);
return model;
}
public destroyModel(model: Model) {
for (let i = 0; i < this._models.length; ++i) {
if (this._models[i] === model) {
this._models.slice(i);
return;
}
}
}
public destroyModels() {
this._models = [];
}
public generateModelId(): number {
return this._modelId++;
}
public get name(): string {
return this._name;
}
@@ -129,9 +155,15 @@ export class RenderScene {
return this._lights;
}
public get models(): Model[] {
return this._models;
}
private _name: string = "";
private _nodes: Map<number, Node> = new Map;
private _cameras: Camera[] = [];
private _mainCamera: Camera | null = null;
private _lights: Light[] = [];
private _models: Model[] = [];
private _modelId: number = 0;
};