// 场景初始化 const scene new THREE.Scene(); scene.background new THREE.Color(0x2a2a3e); // 深色背景衬托模型 const renderer new THREE.WebGLRenderer({antialias: true}); renderer.setSize(innerWidth, innerHeight); renderer.shadowMap.enabled true; renderer.shadowMap.type THREE.PCFSoftShadowMap; // Babylon.js Sandbox 风格设置 renderer.toneMapping THREE.ACESFilmicToneMapping; // 保留电影质感 renderer.toneMappingExposure 1.0; // 标准曝光 renderer.outputEncoding THREE.sRGBEncoding; // sRGB 色彩空间 document.body.appendChild(renderer.domElement); // 极简灯光仅用于产生阴影和方向感 // 环境光非常低主要靠环境贴图照明 scene.add(new THREE.AmbientLight(0xffffff, 0.3)); // 主方向光仅用于产生柔和阴影 const dl new THREE.DirectionalLight(0xffffff, 0.8); dl.position.set(1, 2, 1); dl.castShadow true; dl.shadow.mapSize.set(2048, 2048); dl.shadow.camera.near 0.1; dl.shadow.camera.far 50; dl.shadow.bias -0.0001; dl.shadow.normalBias 0.02; scene.add(dl); // 生成高质量环境贴图 const pmremGenerator new THREE.PMREMGenerator(renderer); pmremGenerator.compileEquirectangularShader(); // 方法1使用渐变背景模拟专业产品摄影棚 const canvas document.createElement(canvas); canvas.width 512; canvas.height 256; const ctx canvas.getContext(2d); // 创建渐变背景 const gradient ctx.createLinearGradient(0, 0, 0, 256); gradient.addColorStop(0, #e8edf5); // 顶部亮白偏蓝 gradient.addColorStop(0.5, #bcc6d4); // 中部中性灰蓝 gradient.addColorStop(1, #4a5568); // 底部深灰蓝 ctx.fillStyle gradient; ctx.fillRect(0, 0, 512, 256); // 添加一些亮点模拟窗户/灯光反射 ctx.fillStyle rgba(255, 255, 255, 0.3); ctx.beginPath(); ctx.arc(100, 60, 40, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle rgba(255, 255, 255, 0.2); ctx.beginPath(); ctx.arc(350, 50, 60, 0, Math.PI * 2); ctx.fill(); const texture new THREE.CanvasTexture(canvas); texture.colorSpace THREE.SRGBColorSpace; scene.environment pmremGenerator.fromEquirectangular(texture).texture; texture.dispose(); pmremGenerator.dispose();