@@ -7,18 +7,43 @@ var checkControllerPresentAndSetup = trackedControlsUtils.checkControllerPresent
77var emitIfAxesChanged = trackedControlsUtils . emitIfAxesChanged ;
88var 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.
1611var 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 ( / ^ O c u l u s Q u e s t $ / . 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
0 commit comments