diff --git a/components/qwen-camera-widget.tsx b/components/qwen-camera-widget.tsx index 72fd1bde8..ec5a889f5 100644 --- a/components/qwen-camera-widget.tsx +++ b/components/qwen-camera-widget.tsx @@ -178,8 +178,8 @@ export function QwenCameraWidget({ sceneRef.current = scene; // 相机 - const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000); - camera.position.set(4, 3.5, 4); + const camera = new THREE.PerspectiveCamera(50, width / height, 0.1, 1000); + camera.position.set(4.5, 4, 4.5); camera.lookAt(0, 0.3, 0); cameraRef.current = camera; @@ -330,11 +330,26 @@ export function QwenCameraWidget({ }; animate(); + // 监听容器大小变化 + const resizeObserver = new ResizeObserver((entries) => { + for (const entry of entries) { + const { width, height } = entry.contentRect; + if (width && height && cameraRef.current && rendererRef.current) { + cameraRef.current.aspect = width / height; + cameraRef.current.updateProjectionMatrix(); + rendererRef.current.setSize(width, height); + } + } + }); + + resizeObserver.observe(container); + // 清理 return () => { if (animationIdRef.current) { cancelAnimationFrame(animationIdRef.current); } + resizeObserver.disconnect(); renderer.dispose(); scene.clear(); };