Skip to content

Commit b7a65d0

Browse files
DigiTecdmarcos
authored andcommitted
Quest controller prep (#4073)
* Factor oculus-touch-controls to support gen 2 Quest controllers * Remove model URL debugging (separate change) * Use Oculus Touch models and adjust laser position * Fix Firefox test launcher
1 parent 5c3aaf0 commit b7a65d0

File tree

4 files changed

+61
-15
lines changed

4 files changed

+61
-15
lines changed

‎.travis.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ addons:
1010
- google-chrome-stable
1111

1212
node_js:
13-
- '4.6'
13+
- '11.6'
1414

1515
install:
1616
- npm install

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"karma-chrome-launcher": "^2.0.0",
7777
"karma-coverage": "^1.1.1",
7878
"karma-env-preprocessor": "^0.1.1",
79-
"karma-firefox-launcher": "^1.0.0",
79+
"karma-firefox-launcher": "^1.2.0",
8080
"karma-mocha": "^1.1.1",
8181
"karma-mocha-reporter": "^2.1.0",
8282
"karma-sinon-chai": "1.2.4",

‎src/components/oculus-touch-controls.js‎

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,43 @@ var checkControllerPresentAndSetup = trackedControlsUtils.checkControllerPresent
77
var emitIfAxesChanged = trackedControlsUtils.emitIfAxesChanged;
88
var onButtonEvent = trackedControlsUtils.onButtonEvent;
99

10-
var TOUCH_CONTROLLER_MODEL_BASE_URL = 'https://cdn.aframe.io/controllers/oculus/oculus-touch-controller-';
11-
var TOUCH_CONTROLLER_MODEL_URL = {
12-
left: TOUCH_CONTROLLER_MODEL_BASE_URL + 'left.gltf',
13-
right: TOUCH_CONTROLLER_MODEL_BASE_URL + 'right.gltf'
14-
};
15-
10+
// Prefix for Gen1 and Gen2 Oculus Touch Controllers.
1611
var GAMEPAD_ID_PREFIX = 'Oculus Touch';
12+
// First generation model URL.
13+
var TOUCH_CONTROLLER_MODEL_BASE_URL = 'https://cdn.aframe.io/controllers/oculus/oculus-touch-controller-';
14+
// For now the generation 2 model is the same as the original until a new one is prepared for upload.
15+
var TOUCH_GEN2_CONTROLLER_MODEL_BASE_URL = TOUCH_CONTROLLER_MODEL_BASE_URL;
1716

18-
var DEFAULT_MODEL_PIVOT_OFFSET = new THREE.Vector3(0, 0, -0.053);
19-
var RAY_ORIGIN = {
20-
left: {origin: {x: 0.008, y: -0.004, z: 0}, direction: {x: 0, y: -0.8, z: -1}},
21-
right: {origin: {x: -0.008, y: -0.004, z: 0}, direction: {x: 0, y: -0.8, z: -1}}
17+
var CONTROLLER_DEFAULT = 'oculusTouchGen1';
18+
var CONTROLLER_PROPERTIES = {
19+
oculusTouchGen1: {
20+
left: {
21+
modelUrl: TOUCH_CONTROLLER_MODEL_BASE_URL + 'left.gltf',
22+
rayOrigin: {origin: {x: 0.008, y: -0.01, z: 0}, direction: {x: 0, y: -0.8, z: -1}},
23+
modelPivotOffset: new THREE.Vector3(0, 0, -0.053),
24+
modelPivotRotation: new THREE.Euler(0, 0, 0)
25+
},
26+
right: {
27+
modelUrl: TOUCH_CONTROLLER_MODEL_BASE_URL + 'right.gltf',
28+
rayOrigin: {origin: {x: -0.008, y: -0.01, z: 0}, direction: {x: 0, y: -0.8, z: -1}},
29+
modelPivotOffset: new THREE.Vector3(0, 0, -0.053),
30+
modelPivotRotation: new THREE.Euler(0, 0, 0)
31+
}
32+
},
33+
oculusTouchGen2: {
34+
left: {
35+
modelUrl: TOUCH_GEN2_CONTROLLER_MODEL_BASE_URL + 'gen2-left.gltf',
36+
rayOrigin: {origin: {x: -0.01, y: 0, z: 0}, direction: {x: 0, y: -0.8, z: -1}},
37+
modelPivotOffset: new THREE.Vector3(0, 0.012, 0),
38+
modelPivotRotation: new THREE.Euler(-Math.PI / 4, 0, 0)
39+
},
40+
right: {
41+
modelUrl: TOUCH_GEN2_CONTROLLER_MODEL_BASE_URL + 'gen2-right.gltf',
42+
rayOrigin: {origin: {x: 0.01, y: 0, z: 0}, direction: {x: 0, y: -0.8, z: -1}},
43+
modelPivotOffset: new THREE.Vector3(0, 0.012, 0),
44+
modelPivotRotation: new THREE.Euler(-Math.PI / 4, 0, 0)
45+
}
46+
}
2247
};
2348

2449
/**
@@ -34,6 +59,7 @@ module.exports.Component = registerComponent('oculus-touch-controls', {
3459
buttonTouchColor: {type: 'color', default: '#8AB'},
3560
buttonHighlightColor: {type: 'color', default: '#2DF'}, // Light blue.
3661
model: {default: true},
62+
controllerType: {default: 'auto', oneOf: ['auto', 'oculus_touch_gen1', 'oculus_touch_gen2']},
3763
orientationOffset: {type: 'vec3', default: {x: 43, y: 0, z: 0}}
3864
},
3965

@@ -121,7 +147,24 @@ module.exports.Component = registerComponent('oculus-touch-controls', {
121147
loadModel: function () {
122148
var data = this.data;
123149
if (!data.model) { return; }
124-
this.el.setAttribute('gltf-model', 'url(' + TOUCH_CONTROLLER_MODEL_URL[data.hand] + ')');
150+
151+
// Set the controller display model based on the data passed in.
152+
this.displayModel = CONTROLLER_PROPERTIES[data.controllerType] || CONTROLLER_PROPERTIES[CONTROLLER_DEFAULT];
153+
// If the developer is asking for auto-detection, see if the displayName can be retrieved to identify the specific unit.
154+
// This only works for WebVR currently.
155+
if (data.controllerType === 'auto') {
156+
var trackedControlsSystem = this.el.sceneEl.systems['tracked-controls-webvr'];
157+
if (trackedControlsSystem && trackedControlsSystem.vrDisplay) {
158+
var displayName = trackedControlsSystem.vrDisplay.displayName;
159+
// The Oculus Quest uses the updated generation 2 inside-out tracked controllers so update the displayModel.
160+
if (/^Oculus Quest$/.test(displayName)) {
161+
this.displayModel = CONTROLLER_PROPERTIES['oculusTouchGen2'];
162+
}
163+
}
164+
}
165+
166+
var modelUrl = this.displayModel[data.hand].modelUrl;
167+
this.el.setAttribute('gltf-model', 'url(' + modelUrl + ')');
125168
},
126169

127170
injectTrackedControls: function () {
@@ -174,6 +217,7 @@ module.exports.Component = registerComponent('oculus-touch-controls', {
174217
onModelLoaded: function (evt) {
175218
var controllerObject3D = evt.detail.model;
176219
var buttonMeshes;
220+
177221
if (!this.data.model) { return; }
178222

179223
buttonMeshes = this.buttonMeshes = {};
@@ -189,12 +233,13 @@ module.exports.Component = registerComponent('oculus-touch-controls', {
189233
buttonMeshes.bbutton = controllerObject3D.getObjectByName('buttonB');
190234

191235
// Offset pivot point
192-
controllerObject3D.position.copy(DEFAULT_MODEL_PIVOT_OFFSET);
236+
controllerObject3D.position.copy(this.displayModel[this.data.hand].modelPivotOffset);
237+
controllerObject3D.rotation.copy(this.displayModel[this.data.hand].modelPivotRotation);
193238

194239
this.el.emit('controllermodelready', {
195240
name: 'oculus-touch-controls',
196241
model: this.data.model,
197-
rayOrigin: RAY_ORIGIN[this.data.hand]
242+
rayOrigin: this.displayModel[this.data.hand].rayOrigin
198243
});
199244
},
200245

‎tests/__init.test.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ setup(function () {
3232
AScene.prototype.renderer = {
3333
vr: {
3434
getDevice: function () { return {requestPresent: function () {}}; },
35+
isPresenting: function () { return true; },
3536
setDevice: function () {},
3637
setPoseTarget: function () {},
3738
enabled: false

0 commit comments

Comments
 (0)