-
Notifications
You must be signed in to change notification settings - Fork 97
/
spotlight.html
75 lines (62 loc) · 2.47 KB
/
spotlight.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
/>
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Spotlight</title>
<link rel="stylesheet" href="/css/examples.css?ver=1.0.0" />
<script src="/js/examples.js?ver=1.1.1"></script>
<script src="/lib/enable3d/enable3d.framework.0.25.4.min.js"></script>
</head>
<body>
<script>
const { Project, Scene3D, PhysicsLoader, THREE } = ENABLE3D
class MainScene extends Scene3D {
createSpotlight(color) {
var spot = this.lights.spotLight({ color, intensity: 2, distance: 40, angle: 0.3, penumbra: 0.2, decay: 2 })
// castShadow is true by default
// spot.castShadow = true
return spot
}
create() {
this.warpSpeed('-sky', '-light', '-ground')
this.camera.position.set(20, 20, 20)
this.camera.lookAt(0, 0, 0)
this.box = this.add.box({ y: 2 }, { phong: {} })
this.add.ground({ width: 50, height: 50 }, { phong: { color: 0xaaaaaa } })
// makes the shadows sharper
const adjustShadowSize = light => {
light.shadow.mapSize.width = 1024
light.shadow.mapSize.height = 1024
}
const ambient = this.lights.ambientLight({ color: 0x444444 })
const spotLight1 = this.createSpotlight(0xff7f00)
const spotLight2 = this.createSpotlight(0x00ff7f)
const spotLight3 = this.createSpotlight(0x7f00ff)
adjustShadowSize(spotLight1)
adjustShadowSize(spotLight2)
adjustShadowSize(spotLight3)
spotLight1.position.set(5, 20, 22)
spotLight2.position.set(0, 20, -15)
spotLight3.position.set(-8, 20, 2)
// the target is where the spot light should shine to
spotLight1.target.position.set(2, 0, 5)
spotLight1.target.updateMatrixWorld()
this.lights.helper.spotLightHelper(spotLight1)
this.lights.helper.spotLightHelper(spotLight2)
this.lights.helper.spotLightHelper(spotLight3)
}
update(time, delta) {
this.box.rotation.x += 0.01
this.box.rotation.y += 0.01
this.box.position.y += Math.sin(time) / 50
}
}
new Project({ scenes: [MainScene] })
</script>
</body>
</html>