-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathfog.html
More file actions
73 lines (63 loc) · 2.24 KB
/
Copy pathfog.html
File metadata and controls
73 lines (63 loc) · 2.24 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
69
70
71
72
73
<html>
<head>
<meta charset="utf-8" />
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.webgpu.js",
"three/webgpu": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.webgpu.js"
}
}
</script>
<script type="module">
import * as THREE from "three/webgpu";
// サイズを指定
const width = 960;
const height = 540;
// レンダラーを作成
const renderer = new THREE.WebGPURenderer({
canvas: document.querySelector("#myCanvas"),
antialias: true,
devicePixelRatio: devicePixelRatio,
});
renderer.setSize(width, height);
renderer.setAnimationLoop(tick);
// シーンを作成
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x000000);
// フォグを設定
scene.fog = new THREE.Fog(0x000000, 50, 2000);
// カメラを作成
const camera = new THREE.PerspectiveCamera(45, width / height);
camera.position.set(0, 0, +1000);
// グループを作成
const group = new THREE.Group();
scene.add(group);
const geometry = new THREE.BoxGeometry(50, 50, 50);
const material = new THREE.MeshStandardMaterial();
for (let i = 0; i < 1000; i++) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.x = (Math.random() - 0.5) * 2000;
mesh.position.y = (Math.random() - 0.5) * 2000;
mesh.position.z = (Math.random() - 0.5) * 2000;
mesh.rotation.x = Math.random() * 2 * Math.PI;
mesh.rotation.y = Math.random() * 2 * Math.PI;
mesh.rotation.z = Math.random() * 2 * Math.PI;
// グループに格納する
group.add(mesh);
}
// 光源
scene.add(new THREE.DirectionalLight(0xff0000, 2)); // 平行光源
scene.add(new THREE.AmbientLight(0x00ffff)); // 環境光源
// 毎フレーム時に実行されるループイベントです
function tick() {
// グループを回す
group.rotateY(0.01);
renderer.render(scene, camera); // レンダリング
}
</script>
</head>
<body>
<canvas id="myCanvas"></canvas>
</body>
</html>