fix model create/destroy

This commit is contained in:
zhuxuguang
2019-02-19 11:11:07 +08:00
parent ba491ae9d5
commit 312c5dc0de
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -192,7 +192,7 @@ export class ModelComponent extends RenderableComponent {
return;
}
if (this._model) {
if (this._model && this._model.inited) {
this._model.destroy();
} else {
this._createModel();
+8
View File
@@ -42,6 +42,7 @@ export class Model {
private _matRefCount: Map<Material, number>;
private _uboLocal: UBOLocal;
private _localUBO: GFXBuffer | null;
private _inited: boolean;
/**
* Setup a default empty model
@@ -56,6 +57,7 @@ export class Model {
this._matRefCount = new Map<Material, number>();
this._uboLocal = new UBOLocal();
this._localUBO = null;
this._inited = false;
}
public destroy () {
@@ -72,6 +74,7 @@ export class Model {
this._subModels.splice(0);
this._matPSORecord.clear();
this._matRefCount.clear();
this._inited = false;
}
set scene (scene: RenderScene) {
@@ -91,6 +94,10 @@ export class Model {
return this._subModels.length;
}
get inited (): boolean {
return this._inited;
}
public getSubModel (idx: number) {
return this._subModels[idx];
}
@@ -186,6 +193,7 @@ export class Model {
}
this.allocatePSO(mat);
this._subModels[idx].initialize(subMeshData, mat, this._matPSORecord.get(mat)!);
this._inited = true;
}
public setSubModelMesh (idx: number, subMeshData: IRenderingSubmesh) {