|
@@ -1,22 +1,15 @@
|
|
|
module BABYLON {
|
|
|
|
|
|
export class GearVRController extends WebVRController {
|
|
|
- public static readonly MODEL_BASE_URL:string = 'https://controllers.babylonjs.com/generic/';
|
|
|
- public static readonly MODEL_FILENAME:string = 'generic.babylon';
|
|
|
+ public static MODEL_BASE_URL:string = 'https://controllers.babylonjs.com/generic/';
|
|
|
+ public static MODEL_FILENAME:string = 'generic.babylon';
|
|
|
|
|
|
public static readonly GAMEPAD_ID_PREFIX: string = 'Gear VR'; // id is 'Gear VR Controller'
|
|
|
|
|
|
- private readonly _mapping = {
|
|
|
- // Semantic button names
|
|
|
- buttons: ['trackpad', 'trigger'],
|
|
|
-
|
|
|
- // This mapping is used to translate from the controller to Babylon semantics
|
|
|
- buttonObservableNames: {
|
|
|
- 'trackpad': 'onTrackpadChangedObservable',
|
|
|
- 'trigger': 'onTriggerStateChangedObservable'
|
|
|
-
|
|
|
- }
|
|
|
- };
|
|
|
+ private readonly _buttonIndexToObservableNameMap = [
|
|
|
+ 'onTrackpadChangedObservable', // Trackpad
|
|
|
+ 'onTriggerStateChangedObservable' // Trigger
|
|
|
+ ]
|
|
|
|
|
|
constructor(vrGamepad: any) {
|
|
|
super(vrGamepad);
|
|
@@ -24,7 +17,7 @@ module BABYLON {
|
|
|
}
|
|
|
|
|
|
public initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void) {
|
|
|
- SceneLoader.ImportMesh("", GenericController.MODEL_BASE_URL, GenericController.MODEL_FILENAME, scene, (newMeshes) => {
|
|
|
+ SceneLoader.ImportMesh("", GearVRController.MODEL_BASE_URL, GearVRController.MODEL_FILENAME, scene, (newMeshes) => {
|
|
|
this._defaultModel = newMeshes[1];
|
|
|
this.attachToMesh(this._defaultModel);
|
|
|
if (meshLoaded) {
|
|
@@ -34,12 +27,11 @@ module BABYLON {
|
|
|
}
|
|
|
|
|
|
protected handleButtonChange(buttonIdx: number, state: ExtendedGamepadButton, changes: GamepadButtonChanges) {
|
|
|
-
|
|
|
- if (buttonIdx < this._mapping.buttons.length) {
|
|
|
- const buttonName : string = this._mapping.buttons[buttonIdx];
|
|
|
+ if (buttonIdx < this._buttonIndexToObservableNameMap.length) {
|
|
|
+ const observableName : string = this._buttonIndexToObservableNameMap[buttonIdx];
|
|
|
|
|
|
- // Only emit events for buttons that we know how to map from index to name
|
|
|
- let observable = (<any>this)[(<any>(this._mapping.buttonObservableNames))[buttonName]];
|
|
|
+ // Only emit events for buttons that we know how to map from index to observable
|
|
|
+ let observable = (<any>this)[observableName];
|
|
|
if (observable) {
|
|
|
observable.notifyObservers(state);
|
|
|
}
|