-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
68 lines (58 loc) · 2.35 KB
/
Copy pathindex.html
File metadata and controls
68 lines (58 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<title>Simple TTT3D example with Three.js</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.147.0/three.min.js" integrity="sha512-GWXLkqxMENYgBdQvA/lTeOV+R2auhasgKQxjMTWBFt3Z6GJVZ9owiyAMOzz0Wt6J1ri8bf/g2kHJV0uvWpJTuw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="module" defer>
// import TTT3D
import TTT3D from "https://cdn.jsdelivr.net/npm/@jgtools/ttt3d@1.1.0/dist/index.min.js";
// setup three js
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, 1, 0.1, 1000);
camera.position.set(0, 1, 5);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(512, 512);
document.body.appendChild(renderer.domElement);
const light = new THREE.AmbientLight(0xffffff, 0.1);
scene.add(light);
const dLight = new THREE.DirectionalLight(0xffffff, 1);
dLight.position.set(0, 1, 5);
scene.add(dLight);
// add cube
const geo = new THREE.BoxGeometry(1, 1, 1);
const mat = new THREE.MeshLambertMaterial({ color: 0x00ffff });
const cube = new THREE.Mesh(geo, mat);
scene.add(cube);
// setup transitions (only one in this example)
// [pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale.x, scale.y, scale.z]
const origins = {
cube: [0, 0, 0, 0, 0, 0, 1, 1, 1]
};
const ttt = new TTT3D(origins);
ttt.add("jump", c => {
const t = Math.sin(c * Math.PI);
return {
cube: [0, t * 2, 0, 0, t * 4, 0, 0, t, 0]
};
});
// play jump transition every 3 seconds
setInterval(() => ttt.play("jump"), 3000);
const clock = new THREE.Clock();
const update = () => {
const delta = clock.getDelta();
// update transition system
const res = ttt.update(delta);
// update mesh transform
const part = res["cube"];
cube.position.set(part[0], part[1], part[2]);
cube.rotation.set(part[3], part[4], part[5]);
cube.scale.set(part[6], part[7], part[8]);
renderer.render(scene, camera);
requestAnimationFrame(update);
};
update();
</script>
</body>
</html>