1
z8018
2025-04-16 1f361850d35ba47225951efbc49d592eea685cf8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<template>
  <div ref="container" class="scene-container"></div>
</template>
  
  <script>
import { onMounted, onBeforeUnmount, ref } from "vue";
import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import { EffectComposer, RenderPass, UnrealBloomPass } from "postprocessing";
 
export default {
  setup() {
    const container = ref(null);
    let scene = null;
    let camera = null;
    let renderer = null;
    let controls = null;
    let composer = null;
    let animationFrameId = null;
 
    // 科技感背景配置
    const bgConfig = {
      gradient: {
        colors: ["#001219", "#005f73", "#0a9396"],
        angle: 45
      },
      bloom: {
        strength: 1.6,
        radius: 0.8,
        threshold: 0.6
      }
    };
 
    const initScene = () => {
      // 初始化核心组件
      scene = new THREE.Scene();
      camera = new THREE.PerspectiveCamera(
        75,
        container.value.clientWidth / container.value.clientHeight,
        0.1,
        1000
      );
 
      // 配置带透明通道的渲染器
      renderer = new THREE.WebGLRenderer({
        antialias: true,
        alpha: true
      });
      renderer.setSize(
        container.value.clientWidth,
        container.value.clientHeight
      );
      renderer.setPixelRatio(window.devicePixelRatio);
      container.value.appendChild(renderer.domElement);
 
      // 初始化后期特效
      composer = new EffectComposer(renderer);
      composer.addPass(new RenderPass(scene, camera));
      composer.addPass(
        new UnrealBloomPass(
          new THREE.Vector2(window.innerWidth, window.innerHeight),
          bgConfig.bloom.strength,
          bgConfig.bloom.radius,
          bgConfig.bloom.threshold
        )
      );
 
      // 添加科技感光效
      const ambientLight = new THREE.AmbientLight(0xffffff, 0.3);
      const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
      directionalLight.position.set(10, 15, 10);
      scene.add(ambientLight, directionalLight);
 
      // 生成货架结构
      scene.add(generateRack());
 
      // 相机与控制器设置
      camera.position.set(8, 12, 15);
      controls = new OrbitControls(camera, renderer.domElement);
      controls.enableDamping = true;
      controls.dampingFactor = 0.05;
    };
 
    const generateRack = () => {
      // 货架生成逻辑保持不变...
    };
 
    const animate = () => {
      animationFrameId = requestAnimationFrame(animate);
      controls.update();
      composer.render();
    };
 
    onMounted(() => {
      initScene();
      animate();
      window.addEventListener("resize", handleResize);
    });
 
    onBeforeUnmount(() => {
      // 资源清理逻辑保持不变...
    });
 
    return { container };
  }
};
</script>
  
  <style scoped>
.scene-container {
  width: 100vw;
  height: 100vh;
  position: fixed;
  background: linear-gradient(
    v-bind("bgConfig.gradient.angle") + "deg",
    v-bind("bgConfig.gradient.colors[0]"),
    v-bind("bgConfig.gradient.colors[1]"),
    v-bind("bgConfig.gradient.colors[2]")
  );
}
 
canvas {
  mix-blend-mode: screen;
}
</style>