From 414212d6d55f8d3e924787bece138ede7e0ab6af Mon Sep 17 00:00:00 2001
From: fuliqi <fuliqi@qq.com>
Date: 星期一, 28 十月 2024 12:19:33 +0800
Subject: [PATCH] 数据中心视频优化完
---
src/views/screen/components/screen-map-three/experience/index.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 55 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 8dd4eb2..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,9 +1,10 @@
-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";
import Camera from "./camera";
import Renderer from "./renderer";
+import CSSRenderer from './cssRenderer';
// 宸ュ叿绫�
import Sizes from "./utils/sizes";
@@ -12,11 +13,13 @@
export default class Experience {
constructor(canvas) {
this.canvas = canvas;
+ this.container = canvas.parentElement;
this.sizes = new Sizes(this.canvas);
this.time = new Time();
this.scene = new Scene();
this.camera = new Camera(this);
this.renderer = new Renderer(this);
+ this.cssRenderer = new CSSRenderer(this);
this.world = new World(this);
// const size = 100;
@@ -25,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', () => {
@@ -40,6 +43,53 @@
this.camera.update();
this.world.update();
this.renderer.update();
- this.stats.update();
+ this.cssRenderer.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