提供一个threejs的简单案例
时间: 2023-04-01 09:04:31 浏览: 149
好的,我可以提供一个threejs的简单案例。您可以使用以下代码创建一个简单的threejs场景:
```
<!DOCTYPE html>
<html>
<head>
<title>Three.js Example</title>
<style>
body { margin: ; }
canvas { display: block; }
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/three@.128./build/three.min.js"></script>
<script>
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, .1, 100 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial( { color: x00ff00 } );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 5;
function animate() {
requestAnimationFrame( animate );
cube.rotation.x += .01;
cube.rotation.y += .01;
renderer.render( scene, camera );
}
animate();
</script>
</body>
</html>
```
这个案例创建了一个简单的场景,其中包含一个绿色的立方体,可以通过旋转来观察它。
阅读全文