-
Notifications
You must be signed in to change notification settings - Fork 69
/
laser-controls.html
133 lines (104 loc) · 2.81 KB
/
laser-controls.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html>
<head>
<title>A-Frame - Laser Controls</title>
<script src="js/aframe-master.min.js"></script>
<script src="js/aframe-extras.min.js"></script>
</head>
<body>
<script>
AFRAME.registerComponent('mousey', {
init: function()
{
let mesh = this.el.getObject3D("mesh");
this.el.addEventListener("mouseenter", function(event)
{
mesh.material.color.set("red");
});
this.el.addEventListener("mousedown", function(event)
{
mesh.material.color.set("yellow");
});
this.el.addEventListener("mouseleave", function(event)
{
mesh.material.color.set("blue");
});
}
});
AFRAME.registerComponent('pointer', {
init: function()
{
let mesh = document.querySelector("#intersection-signal").getObject3D("mesh");
this.el.addEventListener("raycaster-intersection", function(event)
{
this.setAttribute("line", "color", "#FFFFFF");
mesh.material.color.set("#CCCCCC");
});
this.el.addEventListener("raycaster-intersection-cleared", function(event)
{
this.setAttribute("line", "color", "#CCCCCC");
mesh.material.color.set("#444444");
});
}
});
</script>
<a-scene antialias="true">
<a-assets>
<img id="grid" src="images/border.png" crossorigin="anonymous" />
<img id="sky" src="images/stars.jpg" crossorigin="anonymous" />
</a-assets>
<a-sphere
id = "intersection-signal"
radius = "0.25"
position = "0.00 2 -3.00"
color = "#444444"
material = "src: #grid; repeat: 16 8;">
</a-sphere>
<!-- in the a-entity tag below, add
movement-controls="speed: 0.1; fly: false;"
to move the camera/laser-controls with the oculus go trackpad -->
<a-entity position="0 0 0">
<a-entity camera position="0 1.5 1" look-controls></a-entity>
<a-entity id="leftHand" laser-controls="hand: left" raycaster="objects: .collidable; far: 5;" line="color: #CCCCCC" pointer></a-entity>
<a-entity id="rightHand" laser-controls="hand: right" raycaster="objects: .collidable; far: 5;" line="color: #CCCCCC" pointer></a-entity>
</a-entity>
<a-sky
rotation = "0 0 0"
color = "#FFFFFF"
material = "src: #sky">
</a-sky>
<a-plane
width="100" height="100"
position=" 0.00 0.00 0.00"
rotation="-90 0 0"
color="#888888"
material="src: #grid; repeat:100 100; transparent: true; opacity: 0.75"
shadow="cast: false; receive: true">
</a-plane>
<a-box
width = "1" height = "1" depth = "1"
position = "-2.0 0.5 -3.0"
color = "blue"
material = "src: #grid"
class = "collidable"
mousey>
</a-box>
<a-box
width = "1" height = "1" depth = "1"
position = "0.0 0.5 -3.0"
color = "blue"
material = "src: #grid"
class = "collidable"
mousey>
</a-box>
<a-box
width = "1" height = "1" depth = "1"
position = "2.0 0.5 -3.0"
color = "blue"
material = "src: #grid"
class = "collidable"
mousey>
</a-box>
</a-scene>
</body>
</html>