-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
87 lines (59 loc) · 2.13 KB
/
index.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
<head>
<title>3-AD examples</title>
</head>
<body>
<h1>Example</h1>
<script type="module" src="/lib/index.ts"></script>
<!-- Pure THREE.js approach - (single-threaded) -->
<script type="module">
import * as THREE from 'three';
{
// init
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 10);
camera.position.z = 1;
const scene = new THREE.Scene();
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);
const renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// animation
requestAnimationFrame(animation);
function animation(time) {
mesh.rotation.x = time / 2000;
mesh.rotation.y = time / 1000;
renderer.render(scene, camera);
requestAnimationFrame(animation);
}
}
</script>
<!-- With 3-AD - (multi-threaded) -->
<script type="module">
import * as THREE from 'three';
import { Graphics } from '/lib/';
{// init
const graphics = new Graphics();
graphics.init();
graphics.camera.position.z = 1;
const geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
const material = new THREE.MeshNormalMaterial();
const mesh = new THREE.Mesh(geometry, material);
graphics.addObjectToScene(mesh);
// animation
requestAnimationFrame(animation);
function animation(time) {
mesh.rotation.x = time / 2000;
mesh.rotation.y = time / 1000;
graphics.update();
requestAnimationFrame(animation);
}
}
</script>
</body>
</html>