-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget-marker.js
More file actions
27 lines (23 loc) · 900 Bytes
/
target-marker.js
File metadata and controls
27 lines (23 loc) · 900 Bytes
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
AFRAME.registerComponent('target-marker', {
init: function() {
let el = this.el;
this.addMarker = function(e) {
let p = e.detail.intersection.point;
let scene = document.querySelector('a-scene');
console.log('adding marker', el.object3D.worldToLocal(p));
let newMark = document.createElement('a-entity');
newMark.setAttribute('geometry', {
primitive: 'sphere'
});
newMark.setAttribute('material', 'color: red');
newMark.setAttribute('scale', '.2 .2 .2');
newMark.setAttribute('position', el.object3D.worldToLocal(p));
newMark.setAttribute('target-marker', {});
el.appendChild(newMark);
}
this.el.addEventListener('click', this.addMarker);
},
remove: function() {
this.el.removeEventListener('click', this.addMarker);
}
});