From 39e7d257caeae7c241544af7281be1d70747bb8a Mon Sep 17 00:00:00 2001
From: ZhangXianQiang <1135831638@qq.com>
Date: 星期五, 19 四月 2024 15:23:07 +0800
Subject: [PATCH] Merge branch 'dev-threejs'

---
 src/views/screen/components/screen-map-three/experience/index.js |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/src/views/screen/components/screen-map-three/experience/index.js b/src/views/screen/components/screen-map-three/experience/index.js
index 17affbd..df12788 100644
--- a/src/views/screen/components/screen-map-three/experience/index.js
+++ b/src/views/screen/components/screen-map-three/experience/index.js
@@ -1,4 +1,4 @@
-import { Scene, GridHelper,AxesHelper } from 'three';
+import { Scene, GridHelper, AxesHelper } from 'three';
 import Stats from "three/examples/jsm/libs/stats.module";
 
 import World from "./world/world";
@@ -28,10 +28,10 @@
     // const gridHelper = new GridHelper(size, divisions);
     // this.scene.add(gridHelper);
 
-    this.stats = new Stats();
-    document.querySelector('.map-container').appendChild(this.stats.dom);
+    // this.stats = new Stats();
+    // document.querySelector('.map-container').appendChild(this.stats.dom);
 
-    
+
 
     // 甯�
     this.time.on('tick', () => {
@@ -44,6 +44,52 @@
     this.world.update();
     this.renderer.update();
     this.cssRenderer.update();
-    this.stats.update();
+    // this.stats.update();
+  }
+
+  /**
+   * 閿�姣佸満鏅�
+   */
+  destroy() {
+    this.disposeObject();
+    this.resetObject();
+  }
+
+  disposeObject() {
+    this.time.destroy();
+    this.world.destroy();
+    this.camera.destroy();
+    this.renderer.destroy();
+    this.cssRenderer.destroy();
+    this.scene.traverse((child) => {
+      if (child.material) {
+        // 鍙兘瀛樺湪鏉愯川涓烘暟缁勭殑鎯呭喌
+        if (child.material instanceof Array) {
+          child.material.forEach((item) => item.dispose());
+        } else {
+          child.material.dispose();
+          if (child.material.map) {
+            child.material.map.dispose();
+          }
+        }
+      }
+      if (child.geometry) {
+        child.geometry.dispose();
+        child.geometry.attributes = null; // 杩欎簺灞炴�у寘鎷琾osition, normal, uv绛夌瓑
+      }
+      child = null;
+    });
+  }
+
+  resetObject() {
+    this.world = null;
+    this.camera = null;
+    this.renderer = null;
+    this.cssRenderer = null;
+    this.scene = null;
+    this.canvas = null;
+    this.container = null;
+    this.time = null;
+    this.sizes = null;
   }
 }
\ No newline at end of file

--
Gitblit v1.8.0