-
Notifications
You must be signed in to change notification settings - Fork 66
/
light_ambient.html
68 lines (58 loc) · 1.82 KB
/
light_ambient.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
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js"
}
}
</script>
<script type="module">
import * as THREE from "three";
// サイズを指定
const width = 960;
const height = 540;
// レンダラーを作成
const renderer = new THREE.WebGLRenderer({
canvas: document.querySelector("#myCanvas"),
});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(width, height);
// シーンを作成
const scene = new THREE.Scene();
// カメラを作成
const camera = new THREE.PerspectiveCamera(45, width / height);
camera.position.set(20, 20, 20);
camera.lookAt(new THREE.Vector3(0, 0, 0));
// 床を作成
const meshFloor = new THREE.Mesh(
new THREE.BoxGeometry(2000, 0.1, 2000),
new THREE.MeshStandardMaterial({ color: 0x808080, roughness: 0.0 }),
);
scene.add(meshFloor);
// オブジェクトを作成
const meshKnot = new THREE.Mesh(
new THREE.TorusKnotGeometry(3, 1, 100, 16),
new THREE.MeshStandardMaterial({ color: 0xaa0000, roughness: 0.0 }),
);
meshKnot.position.set(0, 5, 0);
scene.add(meshKnot);
// 環境光源を作成
// new THREE.AmbientLight(色, 光の強さ)
const light = new THREE.AmbientLight(0xffffff, 1.0);
scene.add(light);
tick();
// 毎フレーム時に実行されるループイベントです
function tick() {
// レンダリング
renderer.render(scene, camera);
requestAnimationFrame(tick);
}
</script>
</head>
<body>
<canvas id="myCanvas"></canvas>
</body>
</html>