-
Notifications
You must be signed in to change notification settings - Fork 0
/
dual.html
49 lines (49 loc) · 1.42 KB
/
dual.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
<!DOCTYPE html><html><head><meta charset="utf-8"/>
<title>dual-drawline-VR for Oculus Quest</title>
<script src="https://aframe.io/releases/0.9.2/aframe.min.js"></script>
<script>'use strict'
const list = []
AFRAME.registerComponent('input-listen', {
init: function() {
this.line = null
this.bkp = null
const scene = document.querySelector('a-scene')
const self = this
this.el.addEventListener('triggerdown', function(evt) {
if (!self.line) {
self.line = document.createElement('a-entity')
scene.appendChild(self.line)
list.push(self.line)
self.bkp = this.object3D.getWorldPosition()
}
})
this.el.addEventListener('triggerup', function(evt) {
self.line = null
})
const removeLine = function() {
const line = list.pop()
if (line)
scene.removeChild(line)
return line
}
this.el.addEventListener('gripdown', function(evt) {
removeLine()
self.line = null
})
this.el.addEventListener('bbuttondown', function(evt) {
while (removeLine());
})
},
tick: function() {
if (this.line) {
const p = this.el.object3D.getWorldPosition()
this.line.setAttribute('line', { start: this.bkp, end: p, color: "#F00" })
}
}
})
</script></head><body><a-scene>
<a-sky color="#000"></a-sky>
<a-entity id='handright' oculus-touch-controls='hand: right' input-listen></a-entity>
<a-entity id='handleft' oculus-touch-controls='hand: left' input-listen></a-entity>
</a-scene>
</body></html>