请输入淘宝链接
// 初始化3D场景,先放一个立方体,确认3D能跑 function init3D() { scene = new THREE.Scene(); scene.background = new THREE.Color(0x222222); camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 1000 ); camera.position.set(0, 1.7, 3); renderer = new THREE.WebGLRenderer({ antialias:true }); renderer.setSize(window.innerWidth, window.innerHeight); document.getElementById('container').appendChild(renderer.domElement); // 灯光 const ambient = new THREE.AmbientLight(0xffffff, 1); scene.add(ambient); const dirLight = new THREE.DirectionalLight(0xffffff, 1.5); dirLight.position.set(5, 10, 7); scene.add(dirLight); // 放一个立方体,确认3D渲染正常 const cube = new THREE.Mesh( new THREE.BoxGeometry(1, 1, 1), new THREE.MeshStandardMaterial({ color: 0x4CAF50 }) ); cube.position.y = 0.5; scene.add(cube); document.getElementById('tip').innerText = '✅ 3D场景加载成功!'; } // 解析淘宝链接 function parseLink() { const url = document.getElementById('linkInput').value.trim(); const tip = document.getElementById('tip'); const m = url.match(/id=(\d+)/); if (m) { const itemId = m[1]; tip.innerText = '解析成功,商品ID:' + itemId; } else { tip.innerText = '未找到商品ID'; } } // 渲染循环 function animate() { requestAnimationFrame(animate); renderer.render(scene, camera); } // 启动 init3D(); animate();