threejs-animations
Version:
A package for three.js light and transformations animations
33 lines (26 loc) • 813 B
JavaScript
import * as THREE from "three";
import { clickMove } from "threejs-animations"; // import function
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const object = new THREE.Mesh(
new THREE.BoxGeometry(),
new THREE.MeshBasicMaterial({ color: 0x00ff00 })
);
scene.add(object);
camera.position.z = 5;
clickMove(object, camera, 1, [1, 0.2, -0.6]); // x, y, z positions
const animate = () => {
object.rotation.x += 0.01;
object.rotation.y += 0.01;
requestAnimationFrame(animate);
renderer.render(scene, camera);
};
animate();