mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-05 11:02:40 +08:00
fix model create/destroy
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user