-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathlaser-controls.js
122 lines (101 loc) · 4.12 KB
/
laser-controls.js
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
import { registerComponent } from '../core/component.js';
import * as utils from '../utils/index.js';
registerComponent('laser-controls', {
schema: {
hand: {default: 'right'},
model: {default: true},
defaultModelColor: {type: 'color', default: 'grey'}
},
init: function () {
var config = this.config;
var data = this.data;
var el = this.el;
var self = this;
var controlsConfiguration = {hand: data.hand, model: data.model};
// Set all controller models.
el.setAttribute('hp-mixed-reality-controls', controlsConfiguration);
el.setAttribute('magicleap-controls', controlsConfiguration);
el.setAttribute('oculus-go-controls', controlsConfiguration);
el.setAttribute('meta-touch-controls', controlsConfiguration);
el.setAttribute('pico-controls', controlsConfiguration);
el.setAttribute('valve-index-controls', controlsConfiguration);
el.setAttribute('vive-controls', controlsConfiguration);
el.setAttribute('vive-focus-controls', controlsConfiguration);
el.setAttribute('windows-motion-controls', controlsConfiguration);
el.setAttribute('generic-tracked-controller-controls', {hand: controlsConfiguration.hand});
// Wait for controller to connect, or have a valid pointing pose, before creating ray
el.addEventListener('controllerconnected', createRay);
el.addEventListener('controllerdisconnected', hideRay);
el.addEventListener('controllermodelready', function (evt) {
createRay(evt);
self.modelReady = true;
});
function createRay (evt) {
var controllerConfig = config[evt.detail.name];
if (!controllerConfig) { return; }
// Show the line unless a particular config opts to hide it, until a controllermodelready
// event comes through.
var raycasterConfig = utils.extend({
showLine: true
}, controllerConfig.raycaster || {});
// The controllermodelready event contains a rayOrigin that takes into account
// offsets specific to the loaded model.
if (evt.detail.rayOrigin) {
raycasterConfig.origin = evt.detail.rayOrigin.origin;
raycasterConfig.direction = evt.detail.rayOrigin.direction;
raycasterConfig.showLine = true;
}
// Only apply a default raycaster if it does not yet exist. This prevents it overwriting
// config applied from a controllermodelready event.
if (evt.detail.rayOrigin || !self.modelReady) {
el.setAttribute('raycaster', raycasterConfig);
} else {
el.setAttribute('raycaster', 'showLine', true);
}
el.setAttribute('cursor', utils.extend({
fuse: false
}, controllerConfig.cursor));
}
function hideRay (evt) {
var controllerConfig = config[evt.detail.name];
if (!controllerConfig) { return; }
el.setAttribute('raycaster', 'showLine', false);
}
},
config: {
'generic-tracked-controller-controls': {
cursor: {downEvents: ['triggerdown'], upEvents: ['triggerup']}
},
'hp-mixed-reality-controls': {
cursor: {downEvents: ['triggerdown'], upEvents: ['triggerup']},
raycaster: {origin: {x: 0, y: 0, z: 0}}
},
'magicleap-controls': {
cursor: {downEvents: ['trackpaddown', 'triggerdown'], upEvents: ['trackpadup', 'triggerup']}
},
'oculus-go-controls': {
cursor: {downEvents: ['triggerdown'], upEvents: ['triggerup']},
raycaster: {origin: {x: 0, y: 0.0005, z: 0}}
},
'meta-touch-controls': {
cursor: {downEvents: ['triggerdown'], upEvents: ['triggerup']},
raycaster: {origin: {x: 0, y: 0, z: 0}}
},
'pico-controls': {
cursor: {downEvents: ['triggerdown'], upEvents: ['triggerup']}
},
'valve-index-controls': {
cursor: {downEvents: ['triggerdown'], upEvents: ['triggerup']}
},
'vive-controls': {
cursor: {downEvents: ['triggerdown'], upEvents: ['triggerup']}
},
'vive-focus-controls': {
cursor: {downEvents: ['trackpaddown', 'triggerdown'], upEvents: ['trackpadup', 'triggerup']}
},
'windows-motion-controls': {
cursor: {downEvents: ['triggerdown'], upEvents: ['triggerup']},
raycaster: {showLine: false}
}
}
});