JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdn.rawgit.com/mrdoob/three.js/master/build/three.min.js"></script>
JavaScript
let camera, scene, renderer, clock;
let curve, t = 0, speed = 0.1;
const point = new THREE.Vector3();
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.z = 1;
scene = new THREE.Scene();
clock = new THREE.Clock();
const geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
const material = new THREE.MeshNormalMaterial();
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
curve = new THREE.LineCurve3(
new THREE.Vector3( 0.2, 0.2, 0 ),
new THREE.Vector3( 1, 1, 0 )
);
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
}
function animate() {
requestAnimationFrame( animate );
t += clock.getDelta() * speed;
curve.getPointAt( t % 1, camera.position ); // t % 1 means we only use the fractional part of the number
camera.lookAt( scene.position );
renderer.render( scene, camera );
}