|
@@ -14,6 +14,7 @@
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
+ animationId: null, // 存储动画帧ID
|
|
|
model:null,
|
|
|
rotateType:true,
|
|
|
subModels: [],
|
|
@@ -134,6 +135,15 @@
|
|
|
},
|
|
|
|
|
|
beforeDestroy() {
|
|
|
+ // 停止动画循环
|
|
|
+ if (this.animationId) {
|
|
|
+ cancelAnimationFrame(this.animationId);
|
|
|
+ }
|
|
|
+ // 销毁Three.js相关资源
|
|
|
+ this.disposeThreeResources();
|
|
|
+ // 停止所有补间动画
|
|
|
+ TWEEN.removeAll();
|
|
|
+ // 移除事件监听器
|
|
|
window.removeEventListener('resize', this.onWindowResize);
|
|
|
this.renderer.dispose();
|
|
|
},
|
|
@@ -254,19 +264,13 @@
|
|
|
this.model.rotation.y += 0.001; // 添加简单旋转动画
|
|
|
}else if(this.model&&!this.rotateType){
|
|
|
this.model.rotation.y = 0;
|
|
|
- // if(this.model.rotation.y > 10){
|
|
|
- // this.model.rotation.y -= 10;
|
|
|
- // }else if(this.model.rotation.y > 1){
|
|
|
- // this.model.rotation.y -= 1;
|
|
|
- // }else if(this.model.rotation.y > 0.1){
|
|
|
- // this.model.rotation.y -= 0.1;
|
|
|
- // }else if(this.model.rotation.y > 0.01){
|
|
|
- // this.model.rotation.y -= 0.01;
|
|
|
- // }else if(this.model.rotation.y > 0.001){
|
|
|
- // this.model.rotation.y -= 0.001;
|
|
|
- // }
|
|
|
}
|
|
|
- requestAnimationFrame(this.animate);
|
|
|
+ // requestAnimationFrame(this.animate);
|
|
|
+ // TWEEN.update();
|
|
|
+ // this.controls.update();
|
|
|
+ // this.renderer.render(this.scene, this.camera);
|
|
|
+ // this.labelRenderer.render(this.scene, this.camera);
|
|
|
+ this.animationId = requestAnimationFrame(this.animate);
|
|
|
TWEEN.update();
|
|
|
this.controls.update();
|
|
|
this.renderer.render(this.scene, this.camera);
|
|
@@ -805,7 +809,34 @@
|
|
|
function isInner(userIp,begin,end){
|
|
|
return (userIp>=begin) && (userIp<=end);
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ // 资源销毁方法
|
|
|
+ disposeThreeResources() {
|
|
|
+ // 释放几何体和材质
|
|
|
+ this.scene.traverse(child => {
|
|
|
+ if (child.isMesh) {
|
|
|
+ child.geometry.dispose();
|
|
|
+ if (Array.isArray(child.material)) {
|
|
|
+ child.material.forEach(m => m.dispose());
|
|
|
+ } else {
|
|
|
+ child.material.dispose();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 释放渲染器
|
|
|
+ this.renderer.dispose();
|
|
|
+ this.labelRenderer.domElement.remove();
|
|
|
+ this.labelRenderer = null;
|
|
|
+
|
|
|
+ // 释放场景和相机
|
|
|
+ this.scene = null;
|
|
|
+ this.camera = null;
|
|
|
+
|
|
|
+ // 释放控制器
|
|
|
+ this.controls.dispose();
|
|
|
+ this.controls = null;
|
|
|
+ },
|
|
|
}
|
|
|
};
|
|
|
</script>
|