新增场景释放机制和Dispose方法

This commit is contained in:
2025-05-09 11:23:57 +08:00
parent 4a648c2f97
commit efb220612e
9 changed files with 294 additions and 93 deletions

View File

@@ -29,8 +29,6 @@ async function textureRenderUpdate(textureRecord:TextureTableRecord){
*/
export class MaterialEditor extends Singleton
{
private _pointerLocked = false;
Geometrys: Map<string, Geometry | BufferGeometry>;
CurGeometryName = "球";
@@ -38,6 +36,7 @@ export class MaterialEditor extends Singleton
ShowObject: Object3D;
ShowMesh: Mesh;
Viewer: Viewer;
CameraControl?: MaterialEditorCameraControl;
private _MeshMaterial: MeshPhysicalMaterial = new MeshPhysicalMaterial({});
//构造
@@ -72,7 +71,7 @@ export class MaterialEditor extends Singleton
// this.Viewer.PreViewer.Cursor.CursorObject.visible = false;
// this.Viewer.UsePass = false;
this.initScene();
new MaterialEditorCameraControl(this.Viewer, this.ShowObject.position);
this.CameraControl = new MaterialEditorCameraControl(this.Viewer, this.ShowObject.position);
this.Viewer.ZoomAll();
// 初始化相机位置到观察物体的正后方
@@ -82,6 +81,9 @@ export class MaterialEditor extends Singleton
this.Viewer.UpdateRender();
this.Viewer.Fov = 90;
}
else {
console.warn("Viewer has already been initialized");
}
}
SetViewer(canvas: HTMLElement)
{
@@ -186,8 +188,24 @@ export class MaterialEditor extends Singleton
this.Update();
}
dispose()
Dispose()
{
this.Geometrys.clear();
this.Geometrys = undefined;
this.Canvas = undefined;
// object在Viewer中进行释放
this.ShowObject = undefined;
this.ShowMesh = undefined;
this.CameraControl?.dispose();
this.Viewer?.Dispose();
this.CameraControl = undefined;
this.Viewer = undefined;
this.exrPromise = undefined;
this.exrTexture?.dispose();
this.exrTexture = undefined;
this.metaTexture?.dispose();
this.metaTexture = undefined;
}
async Update()