效果图
代码
import * as THREE from 'three';
const width = document.documentElement.clientWidth
const height = document.documentElement.clientHeight
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera()
camera.position.z = 7
camera.position.y = 3
const boxGeometry = new THREE.BoxGeometry(0.5,0.5,0.5)
const material = new THREE.MeshBasicMaterial({ color: "#70a1ff" })
const mesh = new THREE.Mesh(boxGeometry,material)
mesh.position.set(0, 3, 0)
scene.add(mesh)
const renderer = new THREE.WebGLRenderer({ antialias: true })
renderer.setSize(width, height)
renderer.setAnimationLoop(animate)
document.body.appendChild(renderer.domElement)
const gridHelper = new THREE.GridHelper(10, 10)
scene.add(gridHelper)
function animate(time) {
mesh.rotation.x = time / 2000;
mesh.rotation.y = time / 1000;
renderer.render( scene, camera );
}