|
@@ -1,20 +1,19 @@
|
|
|
import * as THREE from 'three';
|
|
|
-import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
|
|
|
// 导入轨道控制器
|
|
|
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
|
|
|
import { CSS3DRenderer } from 'three/examples/jsm/renderers/CSS3DRenderer.js';
|
|
|
import { CSS2DRenderer } from 'three/examples/jsm/renderers/CSS2DRenderer.js';
|
|
|
-// import gsap from 'gsap';
|
|
|
-import ResourceTracker from '/@/utils/threejs/ResourceTracker.js';
|
|
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
|
-import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';
|
|
|
+// import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';
|
|
|
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
|
|
|
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
|
|
|
import { FXAAShader } from 'three/examples/jsm/shaders/FXAAShader.js';
|
|
|
import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass.js';
|
|
|
import Stats from 'three/examples/jsm/libs/stats.module.js';
|
|
|
import { useModelStore } from '/@/store/modules/threejs';
|
|
|
-import { TWEEN } from 'three/examples/jsm/libs/tween.module.min.js';
|
|
|
+import TWEEN from 'three/examples/jsm/libs/tween.module.js';
|
|
|
+import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
|
|
|
+
|
|
|
// import * as dat from 'dat.gui';
|
|
|
// const gui = new dat.GUI();
|
|
|
// gui.domElement.style = 'position:absolute;top:10px;left:10px;z-index:99999999999999';
|
|
@@ -34,20 +33,20 @@ class UseThree {
|
|
|
clock: THREE.Clock | null = new THREE.Clock(); // 计时器
|
|
|
timeoutId: NodeJS.Timeout | null = null;
|
|
|
animationId = 0;
|
|
|
+ isRender = true;
|
|
|
spriteText: THREE.Sprite | null = null;
|
|
|
mouse = new THREE.Vector2();
|
|
|
rayCaster: THREE.Raycaster | null = null;
|
|
|
animations: THREE.AnimationClip[] = [];
|
|
|
mixers: THREE.AnimationMixer[] = [];
|
|
|
- renderT = 1 / 60;
|
|
|
+ renderT = 1 / 40;
|
|
|
timeS = 0;
|
|
|
- resourceTracker: ResourceTracker | null = null;
|
|
|
track: any = null;
|
|
|
composer; //后期
|
|
|
timeOut: NodeJS.Timeout | null = null; //
|
|
|
+ textureMap = new Map<string, THREE.Texture>();
|
|
|
|
|
|
constructor(canvasSelector, css3Canvas?, css2Canvas?) {
|
|
|
- this.animationId = 0;
|
|
|
this.canvasContainer = document.querySelector(canvasSelector);
|
|
|
//初始化
|
|
|
this.init(css3Canvas, css2Canvas);
|
|
@@ -105,8 +104,17 @@ class UseThree {
|
|
|
}
|
|
|
|
|
|
initCamera() {
|
|
|
- this.camera = new THREE.PerspectiveCamera(50, this.canvasContainer.clientWidth / this.canvasContainer.clientHeight, 0.0000001, 1000);
|
|
|
- this.camera.layers.enableAll();
|
|
|
+ // this.camera = new THREE.PerspectiveCamera(50, this.canvasContainer.clientWidth / this.canvasContainer.clientHeight, 0.0000001, 1000);
|
|
|
+ if (!window['$camera']) {
|
|
|
+ throw new Error('threejs摄像头初始化异常!');
|
|
|
+ } else {
|
|
|
+ this.camera = window['$camera'] as THREE.PerspectiveCamera;
|
|
|
+ this.camera.layers.enableAll();
|
|
|
+ if (this.canvasContainer) this.camera.aspect = this.canvasContainer.clientWidth / this.canvasContainer.clientHeight;
|
|
|
+ this.camera.near = 0.0000001;
|
|
|
+ this.camera.far = 1000;
|
|
|
+ }
|
|
|
+
|
|
|
//
|
|
|
// const helper = new THREE.CameraHelper(this.camera);
|
|
|
// this.scene?.add(helper);
|
|
@@ -119,28 +127,19 @@ class UseThree {
|
|
|
}
|
|
|
|
|
|
initRenderer() {
|
|
|
- this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true, logarithmicDepthBuffer: true }) as THREE.WebGLRenderer;
|
|
|
- // 设置屏幕像素比
|
|
|
- this.renderer?.setPixelRatio(window.devicePixelRatio);
|
|
|
- // 设置渲染的尺寸
|
|
|
- this.renderer?.setSize(this.canvasContainer.clientWidth, this.canvasContainer.clientHeight);
|
|
|
- // 色调映射
|
|
|
- this.renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
|
-
|
|
|
- this.renderer.outputEncoding = THREE.sRGBEncoding;
|
|
|
- // this.renderer.sortObjects = false;
|
|
|
-
|
|
|
- this.renderer.shadowMap.enabled = true;
|
|
|
-
|
|
|
- // 曝光程度
|
|
|
- this.renderer.toneMappingExposure = 1;
|
|
|
-
|
|
|
- this.renderer.setClearAlpha(0);
|
|
|
-
|
|
|
- // this.renderer.physicallyCorrectLights = true;
|
|
|
- // this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
|
|
-
|
|
|
- this.canvasContainer?.appendChild(this.renderer.domElement);
|
|
|
+ if (!window['$renderer']) {
|
|
|
+ throw new Error('threejs渲染器初始化异常!');
|
|
|
+ } else {
|
|
|
+ this.renderer = window['$renderer'];
|
|
|
+ if (this.canvasContainer) {
|
|
|
+ this.renderer.toneMappingExposure = 1.0;
|
|
|
+ // const gl = this.renderer?.getContext('webgl');
|
|
|
+ // gl && gl.getExtension('WEBGL_lose_context')?.restoreContext();
|
|
|
+ // this.renderer?.forceContextRestore()
|
|
|
+ this.renderer?.setSize(this.canvasContainer.clientWidth, this.canvasContainer.clientHeight);
|
|
|
+ this.canvasContainer.appendChild(this.renderer.domElement);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
initCSS3Renderer(cssCanvas) {
|
|
@@ -171,11 +170,20 @@ class UseThree {
|
|
|
}
|
|
|
|
|
|
initControles() {
|
|
|
- this.orbitControls = new OrbitControls(this.camera as THREE.Camera, this.renderer?.domElement) as OrbitControls;
|
|
|
+ if (!window['$orbitControls']) {
|
|
|
+ throw new Error('threejs控制器初始化异常!');
|
|
|
+ } else {
|
|
|
+ this.orbitControls = window['$orbitControls'];
|
|
|
+ this.orbitControls.panSpeed = 1;
|
|
|
+ this.orbitControls.rotateSpeed = 1;
|
|
|
+ this.orbitControls.maxPolarAngle = Math.PI;
|
|
|
+ this.orbitControls.minPolarAngle = 0;
|
|
|
+ }
|
|
|
+ // this.orbitControls = new OrbitControls(this.camera as THREE.Camera, this.renderer?.domElement) as OrbitControls;
|
|
|
// this.orbitControls.update();
|
|
|
// this.orbitControls.minDistance = 1;
|
|
|
// this.orbitControls.maxDistance = 100;
|
|
|
- // this.orbitControls.enableDamping = true;
|
|
|
+ // this.orbitControls.maxDistance = true;
|
|
|
}
|
|
|
|
|
|
setGLTFModel(modalNames, group = null) {
|
|
@@ -206,7 +214,12 @@ class UseThree {
|
|
|
let modalValue;
|
|
|
if (!data) {
|
|
|
const modalArr = await db.modal.where('modalName').equals(modalNameStr).toArray();
|
|
|
- if (modalArr.length > 0) modalValue = modalArr[0].modalVal;
|
|
|
+ if (modalArr.length > 0) {
|
|
|
+ modalValue = modalArr[0].modalVal;
|
|
|
+ } else {
|
|
|
+ // 开启线程下载
|
|
|
+ console.log('需要开启线程下载模型资源。。。。。');
|
|
|
+ }
|
|
|
} else {
|
|
|
modalValue = data.modalVal;
|
|
|
}
|
|
@@ -274,89 +287,89 @@ class UseThree {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- setFBXModel(modalNames, group = null) {
|
|
|
- window['startTime'] = new Date().getTime();
|
|
|
- const modelStore = useModelStore();
|
|
|
- return new Promise(async (resolve, reject) => {
|
|
|
- try {
|
|
|
- const fbxLoader = new FBXLoader();
|
|
|
-
|
|
|
- fbxLoader.setPath('/model/fbx/');
|
|
|
-
|
|
|
- const db = window['CustomDB'];
|
|
|
- const resolvePromise: Promise<any>[] = [];
|
|
|
-
|
|
|
- let modalNameArr = Object.prototype.toString.call(modalNames) === '[object Array]' ? modalNames : [modalNames];
|
|
|
- let len = modalNameArr.length;
|
|
|
-
|
|
|
- for (let i = 0; i < len; i++) {
|
|
|
- resolvePromise[i] = new Promise(async (childResolve, reject) => {
|
|
|
- try {
|
|
|
- // 解析模型
|
|
|
- let modalValue;
|
|
|
- const modalNameStr = modalNameArr[i];
|
|
|
- let data = modelStore.modelArr.get(modalNameStr) || null;
|
|
|
- if (!data) {
|
|
|
- const modalArr = await db.modal.where('modalName').equals(modalNameStr).toArray();
|
|
|
- if (modalArr.length > 0) modalValue = modalArr[0].modalVal;
|
|
|
- } else {
|
|
|
- modalValue = data.modalVal;
|
|
|
- }
|
|
|
- if (modalValue) {
|
|
|
- const object = fbxLoader.parse(modalValue, '/model/fbx/');
|
|
|
- // const object = fbx.scene;
|
|
|
- // setModalCenter(object);
|
|
|
- if (object) {
|
|
|
- object.traverse((obj) => {
|
|
|
- if (obj instanceof THREE.Mesh) {
|
|
|
- obj.material.emissiveIntensity = 1;
|
|
|
- obj.material.emissiveMap = obj.material.map;
|
|
|
- obj.material.blending = THREE.CustomBlending;
|
|
|
- if (obj.material.opacity < 1) {
|
|
|
- obj.material.transparent = true;
|
|
|
- }
|
|
|
- if (obj.material.map) {
|
|
|
- obj.material.map.encoding = THREE.sRGBEncoding;
|
|
|
- obj.material.map.flipY = false;
|
|
|
- obj.material.map.anisotropy = 1;
|
|
|
- }
|
|
|
- if (obj.material.emissiveMap) {
|
|
|
- obj.material.emissiveMap.encoding = THREE.sRGBEncoding;
|
|
|
- obj.material.emissiveMap.flipY = false;
|
|
|
- }
|
|
|
-
|
|
|
- if (obj.material.map || obj.material.emissiveMap) {
|
|
|
- obj.material.needsUpdate = true;
|
|
|
- }
|
|
|
-
|
|
|
- // if (envMap) {
|
|
|
- // obj.material.envMap = envMap;
|
|
|
- // obj.material.envMapIntensity = 1;
|
|
|
- // }
|
|
|
- // obj.renderOrder = 1;
|
|
|
- }
|
|
|
- });
|
|
|
- object.animations = object.animations;
|
|
|
- object.name = modalNameStr;
|
|
|
- group?.add(object);
|
|
|
- childResolve(object);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.log(error);
|
|
|
- reject();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- Promise.all(resolvePromise).then((objects) => {
|
|
|
- resolve(objects);
|
|
|
- });
|
|
|
- } catch (error) {
|
|
|
- reject('加载模型出错');
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ // setFBXModel(modalNames, group = null) {
|
|
|
+ // window['startTime'] = new Date().getTime();
|
|
|
+ // const modelStore = useModelStore();
|
|
|
+ // return new Promise(async (resolve, reject) => {
|
|
|
+ // try {
|
|
|
+ // const fbxLoader = new FBXLoader();
|
|
|
+
|
|
|
+ // fbxLoader.setPath('/model/fbx/');
|
|
|
+
|
|
|
+ // const db = window['CustomDB'];
|
|
|
+ // const resolvePromise: Promise<any>[] = [];
|
|
|
+
|
|
|
+ // let modalNameArr = Object.prototype.toString.call(modalNames) === '[object Array]' ? modalNames : [modalNames];
|
|
|
+ // let len = modalNameArr.length;
|
|
|
+
|
|
|
+ // for (let i = 0; i < len; i++) {
|
|
|
+ // resolvePromise[i] = new Promise(async (childResolve, reject) => {
|
|
|
+ // try {
|
|
|
+ // // 解析模型
|
|
|
+ // let modalValue;
|
|
|
+ // const modalNameStr = modalNameArr[i];
|
|
|
+ // let data = modelStore.modelArr.get(modalNameStr) || null;
|
|
|
+ // if (!data) {
|
|
|
+ // const modalArr = await db.modal.where('modalName').equals(modalNameStr).toArray();
|
|
|
+ // if (modalArr.length > 0) modalValue = modalArr[0].modalVal;
|
|
|
+ // } else {
|
|
|
+ // modalValue = data.modalVal;
|
|
|
+ // }
|
|
|
+ // if (modalValue) {
|
|
|
+ // const object = fbxLoader.parse(modalValue, '/model/fbx/');
|
|
|
+ // // const object = fbx.scene;
|
|
|
+ // // setModalCenter(object);
|
|
|
+ // if (object) {
|
|
|
+ // object.traverse((obj) => {
|
|
|
+ // if (obj instanceof THREE.Mesh) {
|
|
|
+ // obj.material.emissiveIntensity = 1;
|
|
|
+ // obj.material.emissiveMap = obj.material.map;
|
|
|
+ // obj.material.blending = THREE.CustomBlending;
|
|
|
+ // if (obj.material.opacity < 1) {
|
|
|
+ // obj.material.transparent = true;
|
|
|
+ // }
|
|
|
+ // if (obj.material.map) {
|
|
|
+ // obj.material.map.encoding = THREE.sRGBEncoding;
|
|
|
+ // obj.material.map.flipY = false;
|
|
|
+ // obj.material.map.anisotropy = 1;
|
|
|
+ // }
|
|
|
+ // if (obj.material.emissiveMap) {
|
|
|
+ // obj.material.emissiveMap.encoding = THREE.sRGBEncoding;
|
|
|
+ // obj.material.emissiveMap.flipY = false;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if (obj.material.map || obj.material.emissiveMap) {
|
|
|
+ // obj.material.needsUpdate = true;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // // if (envMap) {
|
|
|
+ // // obj.material.envMap = envMap;
|
|
|
+ // // obj.material.envMapIntensity = 1;
|
|
|
+ // // }
|
|
|
+ // // obj.renderOrder = 1;
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // object.animations = object.animations;
|
|
|
+ // object.name = modalNameStr;
|
|
|
+ // group?.add(object);
|
|
|
+ // childResolve(object);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // } catch (error) {
|
|
|
+ // console.log(error);
|
|
|
+ // reject();
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // Promise.all(resolvePromise).then((objects) => {
|
|
|
+ // resolve(objects);
|
|
|
+ // });
|
|
|
+ // } catch (error) {
|
|
|
+ // reject('加载模型出错');
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
|
|
|
setTestPlane() {
|
|
|
const plane = new THREE.Mesh(new THREE.PlaneGeometry(10, 10), new THREE.MeshPhongMaterial({ color: 0x999999, specular: 0x101010 }));
|
|
@@ -376,14 +389,12 @@ class UseThree {
|
|
|
|
|
|
/* 场景环境背景 */
|
|
|
setEnvMap(hdr) {
|
|
|
- const pmremGenerator = new THREE.PMREMGenerator(this.renderer as THREE.WebGLRenderer); // 使用hdr作为背景色
|
|
|
- pmremGenerator.compileEquirectangularShader();
|
|
|
- new THREE.TextureLoader().setPath('/model/hdr/').load(hdr + '.jpeg', (texture) => {
|
|
|
- texture.encoding = THREE.sRGBEncoding;
|
|
|
+ // (this.scene as THREE.Scene).environment
|
|
|
+ new RGBELoader().setPath('/model/hdr/').load(hdr + '.hdr', (texture) => {
|
|
|
+ texture.colorSpace = THREE.SRGBColorSpace;
|
|
|
texture.mapping = THREE.EquirectangularReflectionMapping;
|
|
|
- const envMap = pmremGenerator.fromEquirectangular(texture).texture;
|
|
|
- (this.scene as THREE.Scene).environment = envMap;
|
|
|
- pmremGenerator.dispose();
|
|
|
+ (this.scene as THREE.Scene).environment = texture;
|
|
|
+ texture.dispose();
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -417,24 +428,25 @@ class UseThree {
|
|
|
renderAnimationScene() {}
|
|
|
|
|
|
animate() {
|
|
|
- if (this.animationId != -1) {
|
|
|
+ if (this.isRender) {
|
|
|
this.animationId = requestAnimationFrame(this.animate.bind(this));
|
|
|
- // const T = this.clock?.getDelta() || 0;
|
|
|
- // this.timeS = this.timeS + T;
|
|
|
- // if (this.timeS > this.renderT) {
|
|
|
- // this.stats?.update();
|
|
|
- // // this.renderAnimationScene();
|
|
|
- // if (this.renderEnabled) {
|
|
|
- // this.render();
|
|
|
- // }
|
|
|
- // this.timeS = 0;
|
|
|
- // }
|
|
|
- this.stats?.update();
|
|
|
- TWEEN.update();
|
|
|
- // this.renderAnimationScene();
|
|
|
- if (this.renderEnabled) {
|
|
|
- this.render();
|
|
|
+ const T = this.clock?.getDelta() || 0;
|
|
|
+ this.timeS = this.timeS + T;
|
|
|
+ if (this.timeS > this.renderT) {
|
|
|
+ // this.renderAnimationScene();
|
|
|
+
|
|
|
+ if (this.renderEnabled) {
|
|
|
+ this.render();
|
|
|
+ }
|
|
|
+ this.stats?.update();
|
|
|
+ this.timeS = 0;
|
|
|
}
|
|
|
+ // this.stats?.update();
|
|
|
+ // // TWEEN.update();
|
|
|
+ // // this.renderAnimationScene();
|
|
|
+ // if (this.renderEnabled) {
|
|
|
+ // this.render();
|
|
|
+ // }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -462,60 +474,77 @@ class UseThree {
|
|
|
}, 500);
|
|
|
}
|
|
|
|
|
|
+ clearMesh(item) {
|
|
|
+ item.geometry?.dispose();
|
|
|
+ if (item.material) {
|
|
|
+ const material = item.material;
|
|
|
+
|
|
|
+ for (const key of Object.keys(material)) {
|
|
|
+ const value = material[key];
|
|
|
+ // if (value && typeof value === 'object' && 'minFilter' in value) {
|
|
|
+ // // this.textureMap.set(value.uuid, value);
|
|
|
+ // value.dispose();
|
|
|
+ // }
|
|
|
+ if (value && typeof value === 'object' && value['dispose'] && typeof value['dispose'] === 'function') {
|
|
|
+ value.dispose();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ material.dispose();
|
|
|
+ }
|
|
|
+ if (item.texture) {
|
|
|
+ item.texture.dispose();
|
|
|
+ }
|
|
|
+ }
|
|
|
clearGroup(group) {
|
|
|
- const clearCache = (item) => {
|
|
|
- item.geometry?.dispose();
|
|
|
- item.material?.dispose();
|
|
|
- };
|
|
|
const removeObj = (obj) => {
|
|
|
- if (obj?.children && obj?.children.length > 0) {
|
|
|
+ if (obj && obj?.children && obj?.children.length > 0) {
|
|
|
for (let i = obj?.children.length - 1; i >= 0; i--) {
|
|
|
const item = obj?.children[i];
|
|
|
- if (item.children.length > 0) {
|
|
|
+ if (item && item.children && item.children.length > 0) {
|
|
|
removeObj(item);
|
|
|
+ item?.clear();
|
|
|
} else {
|
|
|
- clearCache(item);
|
|
|
- item.clear();
|
|
|
+ if (item) {
|
|
|
+ if (item.parent) item.parent.remove(item);
|
|
|
+ this.clearMesh(item);
|
|
|
+ item.clear();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- obj?.removeFromParent();
|
|
|
- obj?.clear();
|
|
|
};
|
|
|
removeObj(group);
|
|
|
}
|
|
|
|
|
|
- deleteModal() {
|
|
|
+ clearScene() {
|
|
|
+ this.clearGroup(this.scene);
|
|
|
+ // console.log('场景纹理数量----------->', this.textureMap.size);
|
|
|
+ this.textureMap.forEach((texture) => {
|
|
|
+ texture?.dispose();
|
|
|
+ });
|
|
|
+ this.textureMap.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ destroy() {
|
|
|
+ TWEEN.getAll().forEach((item) => {
|
|
|
+ item.stop();
|
|
|
+ });
|
|
|
+ TWEEN.removeAll();
|
|
|
+ this.isRender = false;
|
|
|
cancelAnimationFrame(this.animationId);
|
|
|
- this.animationId = -1;
|
|
|
- for (let i = this.scene?.children.length - 1; i > -1; i--) {
|
|
|
- const obj: any = this.scene?.children[i];
|
|
|
- if (obj.type === 'Group') {
|
|
|
- this.clearGroup(obj);
|
|
|
- } else if (obj.type === 'Mesh') {
|
|
|
- if (obj.material) {
|
|
|
- obj.material.dispose();
|
|
|
- } else if (obj.geometry) {
|
|
|
- obj.geometry.dispose();
|
|
|
- }
|
|
|
- obj.clear();
|
|
|
- }
|
|
|
- obj.removeFromParent();
|
|
|
- this.scene?.remove(obj);
|
|
|
- }
|
|
|
+ this.clearScene();
|
|
|
+ window.removeEventListener('resize', this.resizeRenderer);
|
|
|
+ // this.orbitControls?.dispose();
|
|
|
+ this.scene?.environment?.dispose();
|
|
|
+ this.scene?.clear();
|
|
|
+ this.renderer?.dispose();
|
|
|
+ this.renderer?.getRenderTarget()?.dispose();
|
|
|
|
|
|
+ if (this.renderer && this.canvasContainer) this.canvasContainer.innerHTML = '';
|
|
|
+ if (this.CSSCanvasContainer && this.css3dRender) this.CSSCanvasContainer.innerHTML = '';
|
|
|
+
|
|
|
+ // if (this.renderer) this.renderer.domElement = null;
|
|
|
this.renderer?.clear();
|
|
|
- this.renderer?.dispose();
|
|
|
- this.renderer?.forceContextLoss();
|
|
|
- const gl = this.renderer?.getContext('webgl');
|
|
|
- gl && gl.getExtension('WEBGL_lose_context')?.loseContext();
|
|
|
- if (this.renderer && this.canvasContainer) this.canvasContainer?.removeChild(this.renderer?.domElement as Node);
|
|
|
- // const glCss = this.css3dRender?.getContext('webgl');
|
|
|
- // glCss && glCss.getExtension('WEBGL_lose_context')?.loseContext();
|
|
|
- if (this.CSSCanvasContainer && this.css3dRender) this.CSSCanvasContainer.removeChild(this.css3dRender?.domElement as Node);
|
|
|
- this.camera = null;
|
|
|
- this.orbitControls = null;
|
|
|
- if (this.renderer) this.renderer.domElement = null;
|
|
|
|
|
|
if (this.css3dRender) this.css3dRender.domElement = null;
|
|
|
if (this.css2dRender) this.css2dRender.domElement = null;
|
|
@@ -523,17 +552,15 @@ class UseThree {
|
|
|
if (this.canvasContainer) this.canvasContainer.innerHTML = '';
|
|
|
if (this.CSSCanvasContainer) this.CSSCanvasContainer.innerHTML = '';
|
|
|
|
|
|
- this.resourceTracker && this.resourceTracker.dispose();
|
|
|
- this.scene?.environment?.dispose();
|
|
|
- !!this.scene?.clear ?? this.scene?.clear();
|
|
|
-
|
|
|
+ this.camera = null;
|
|
|
+ this.orbitControls = null;
|
|
|
+ this.renderer = null;
|
|
|
this.stats = null;
|
|
|
this.scene = null;
|
|
|
this.css3dRender = null;
|
|
|
this.css2dRender = null;
|
|
|
-
|
|
|
- this.renderer = null;
|
|
|
THREE.Cache.clear();
|
|
|
+ console.log('场景销毁后信息----------->', window['$renderer']?.info, this.scene);
|
|
|
}
|
|
|
}
|
|
|
|