three.js dev template - module
CSS
body {
margin: 0px;
}
canvas {
display: block;
}
JavaScript
import * as THREE from "https://threejs.org/build/three.module.js";
let renderer, scene, camera, mixer, clock, clip, repetitionInput;
console.log("three.js version "+ THREE.REVISION)
init();
animate();
function init() {
clock = new THREE.Clock();
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.1, 10 );
camera.position.set( 0, 0, 5 );
const geometry = new THREE.BoxBufferGeometry();
const material = new THREE.MeshBasicMaterial();
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
mixer = new THREE.AnimationMixer( mesh );
const keyframeTrack = new THREE.VectorKeyframeTrack( '.position', [ 0, 1 ], [ 0, 0, 0, 1, 0, 0 ] );
clip = new THREE.AnimationClip( 'default', - 1, [ keyframeTrack ] );
repetitionInput = document.createElement('input');
repetitionInput.type = "number";
repetitionInput.min = 1;
repetitionInput.value = 1;
repetitionInput.style.position = "absolute";
repetitionInput.style.top = "0px";
document.body.appendChild(repetitionInput);
const buttonPingPong = document.createElement('button');
buttonPingPong.innerHTML = "PingPong";
buttonPingPong.style.position = "absolute";
buttonPingPong.style.top = "30px";
buttonPingPong.onclick = function () {
playAnimation(THREE.LoopPingPong);
}
document.body.appendChild(buttonPingPong);
const buttonRepeat = document.createElement('button');
buttonRepeat.innerHTML = "Repeat";
buttonRepeat.style.position = "absolute";
buttonRepeat.style.top = "60px";
buttonRepeat.onclick = function () {
playAnimation(THREE.LoopRepeat);
}
document.body.appendChild(buttonRepeat);
...