要将带有3D模型的Three.js场景添加到div中,可以按照以下步骤进行操作:
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<div id="scene-container"></div>
const sceneContainer = document.getElementById('scene-container');
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, sceneContainer.clientWidth / sceneContainer.clientHeight, 0.1, 1000);
camera.position.z = 5;
const renderer = new THREE.WebGLRenderer();
renderer.setSize(sceneContainer.clientWidth, sceneContainer.clientHeight);
sceneContainer.appendChild(renderer.domElement);
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
通过以上步骤,你可以将带有3D模型的Three.js场景添加到指定的div中。请注意,以上代码仅为示例,你可以根据实际需求进行修改和扩展。
关于Three.js和相关概念的更多信息,你可以参考腾讯云的产品介绍页面: Three.js产品介绍
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云