-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy paththree_box.html
66 lines (56 loc) · 1.77 KB
/
three_box.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
<html>
<head>
<title>Three.js WebGPU Renderer Box</title>
<style>
body {
margin: 0;
background-color: #000;
color: #fff;
overscroll-behavior: none;
}
</style>
</head>
<body>
<script type="module">
import {
BoxBufferGeometry,
Camera,
Mesh,
MeshNormalMaterial,
PerspectiveCamera,
Scene
} from 'https://raw.githack.com/mrdoob/three.js/r111/build/three.module.js';
import WebGPURenderer from './js/webgpu_renderer.js';
// @TODO: Detect WebGPU capability
const run = () => {
const renderer = new WebGPURenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio);
document.body.appendChild(renderer.domElement);
const scene = new Scene();
const camera = new PerspectiveCamera(90, window.innerWidth / window.innerHeight, 0.1, 1000.0);
camera.position.y = 0.5;
const box = new Mesh(
new BoxBufferGeometry(2, 2, 2),
new MeshNormalMaterial()
);
box.position.z = -4;
box.rotation.x = 45 * Math.PI / 180;
scene.add(box);
const render = () => {
requestAnimationFrame(render);
box.rotation.y += 0.01;
renderer.render(scene, camera);
};
const onResize = event => {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
};
window.addEventListener('resize', onResize, false);
render();
};
run();
</script>
</body>
</html>