Repository navigation
Expand file tree
/
Copy pathcamera_basic.html
More file actions
60 lines (52 loc) · 1.81 KB
/
Copy pathcamera_basic.html
File metadata and controls
60 lines (52 loc) · 1.81 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
<html>
<head>
<meta charset="utf-8" />
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.182.0/build/three.webgpu.js",
"three/webgpu": "https://cdn.jsdelivr.net/npm/three@0.182.0/build/three.webgpu.js"
}
}
</script>
<script type="module">
import * as THREE from "three/webgpu";
// サイズを指定
const width = 960;
const height = 540;
let rot = 0;
// レンダラーを作成
const renderer = new THREE.WebGPURenderer({
canvas: document.querySelector("#myCanvas"),
});
renderer.setSize(width, height);
renderer.setAnimationLoop(tick);
// シーンを作成
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x000000);
// カメラを作成
const camera = new THREE.PerspectiveCamera(45, width / height);
// 直方体を作成
const material = new THREE.MeshNormalMaterial({ wireframe: true });
const geometry = new THREE.SphereGeometry(300, 30, 30);
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
// 毎フレーム時に実行されるループイベントです
function tick() {
rot += 0.5; // 毎フレーム角度を0.5度ずつ足していく
// ラジアンに変換する
const radian = (rot * Math.PI) / 180;
// 角度に応じてカメラの位置を設定
camera.position.x = 1000 * Math.sin(radian);
camera.position.z = 1000 * Math.cos(radian);
// 原点方向を見つめる
camera.lookAt(new THREE.Vector3(0, 0, 0));
// レンダリング
renderer.render(scene, camera);
}
</script>
</head>
<body>
<canvas id="myCanvas"></canvas>
</body>
</html>