Threejs学习
让物体根据帧渲染动起来
import * as THREE from "three";
import { OrbitControls } from "three/examples/jsm/controls/orbitcontrols";
let scene = new THREE.Scene();
let camera = new THREE.PerspectiveCamera(
60,
window.innerWidth / window.innerHeight,
1,
1000
);
camera.position.set(0,0,30);
scene.add(camera);
let boxsize = new THREE.BoxGeometry(2,2,2);
let boxColor = new THREE.MeshBasicMaterial({
color:0xFFFF00
});
let box= new THREE.Mesh(boxsize,boxColor);
console.log(box);
scene.add(box);
let renderer = new THREE.WebGL1Renderer();
renderer.setSize(window.innerWidth,window.innerHeight);
document.body.appendChild(renderer.domElement);
let orbitcontrols = new OrbitControls(camera,renderer.domElement);
let axes=new THREE.AxesHelper(10);
scene.add(axes);
let clock = new THREE.Clock();
function animi(){
let time =clock.getElapsedTime();
let t= time % 10;
let speed = t * 1;
let scale = t / 100;
box.position.x = speed;
box.position.y = speed;
box.position.z = speed;
box.rotation.x = speed;
box.rotation.y = speed;
box.rotation.z = speed;
renderer.render(scene,camera);
requestAnimationFrame(animi);
}
animi();