123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- import {
- IMotionControllerLayoutMap,
- IMinimalMotionControllerObject,
- MotionControllerHandness,
- WebXRAbstractMotionController
- } from "./webXRAbstractController";
- import { Scene } from '../../../scene';
- import { AbstractMesh } from '../../../Meshes/abstractMesh';
- import { Mesh } from '../../../Meshes/mesh';
- import { Quaternion } from '../../../Maths/math.vector';
- import { WebXRMotionControllerManager } from './webXRMotionControllerManager';
- const HTCViveLayout: IMotionControllerLayoutMap = {
- "left": {
- "selectComponentId": "xr-standard-trigger",
- "components": {
- "xr-standard-trigger": {
- "type": "trigger",
- "gamepadIndices": {
- "button": 0
- },
- "rootNodeName": "xr_standard_trigger",
- "visualResponses": {
- }
- },
- "xr-standard-squeeze": {
- "type": "squeeze",
- "gamepadIndices": {
- "button": 1
- },
- "rootNodeName": "xr_standard_squeeze",
- "visualResponses": {
- }
- },
- "xr-standard-touchpad": {
- "type": "touchpad",
- "gamepadIndices": {
- "button": 2,
- "xAxis": 0,
- "yAxis": 1
- },
- "rootNodeName": "xr_standard_touchpad",
- "visualResponses": {
- },
- },
- "menu": {
- "type": "button",
- "gamepadIndices": {
- "button": 4
- },
- "rootNodeName": "menu",
- "visualResponses": {
- }
- }
- },
- "gamepadMapping": "xr-standard",
- "rootNodeName": "htc_vive_none",
- "assetPath": "none.glb"
- },
- "right": {
- "selectComponentId": "xr-standard-trigger",
- "components": {
- "xr-standard-trigger": {
- "type": "trigger",
- "gamepadIndices": {
- "button": 0
- },
- "rootNodeName": "xr_standard_trigger",
- "visualResponses": {
- }
- },
- "xr-standard-squeeze": {
- "type": "squeeze",
- "gamepadIndices": {
- "button": 1
- },
- "rootNodeName": "xr_standard_squeeze",
- "visualResponses": {
- }
- },
- "xr-standard-touchpad": {
- "type": "touchpad",
- "gamepadIndices": {
- "button": 2,
- "xAxis": 0,
- "yAxis": 1
- },
- "rootNodeName": "xr_standard_touchpad",
- "visualResponses": {
- },
- },
- "menu": {
- "type": "button",
- "gamepadIndices": {
- "button": 4
- },
- "rootNodeName": "menu",
- "visualResponses": {
- }
- }
- },
- "gamepadMapping": "xr-standard",
- "rootNodeName": "htc_vive_none",
- "assetPath": "none.glb"
- },
- "none": {
- "selectComponentId": "xr-standard-trigger",
- "components": {
- "xr-standard-trigger": {
- "type": "trigger",
- "gamepadIndices": {
- "button": 0
- },
- "rootNodeName": "xr_standard_trigger",
- "visualResponses": {
- }
- },
- "xr-standard-squeeze": {
- "type": "squeeze",
- "gamepadIndices": {
- "button": 1
- },
- "rootNodeName": "xr_standard_squeeze",
- "visualResponses": {
- }
- },
- "xr-standard-touchpad": {
- "type": "touchpad",
- "gamepadIndices": {
- "button": 2,
- "xAxis": 0,
- "yAxis": 1
- },
- "rootNodeName": "xr_standard_touchpad",
- "visualResponses": {
- },
- },
- "menu": {
- "type": "button",
- "gamepadIndices": {
- "button": 4
- },
- "rootNodeName": "menu",
- "visualResponses": {
- }
- }
- },
- "gamepadMapping": "xr-standard",
- "rootNodeName": "htc-vive-none",
- "assetPath": "none.glb"
- }
- };
- // const HTCViveLegacyLayout: IMotionControllerLayoutMap = {
- // "left-right-none": {
- // "selectComponentId": "xr-standard-trigger",
- // "components": {
- // "xr-standard-trigger": { "type": "trigger" },
- // "xr-standard-squeeze": { "type": "squeeze" },
- // "xr-standard-touchpad": { "type": "touchpad" }
- // },
- // "gamepad": {
- // "mapping": "",
- // "buttons": [
- // "xr-standard-touchpad",
- // "xr-standard-trigger",
- // "xr-standard-squeeze"
- // ],
- // "axes": [
- // { "componentId": "xr-standard-touchpad", "axis": "x-axis" },
- // { "componentId": "xr-standard-touchpad", "axis": "y-axis" }
- // ]
- // }
- // }
- // };
- /**
- * The motion controller class for the standard HTC-Vive controllers
- */
- export class WebXRHTCViveMotionController extends WebXRAbstractMotionController {
- /**
- * The base url used to load the left and right controller models
- */
- public static MODEL_BASE_URL: string = 'https://controllers.babylonjs.com/vive/';
- /**
- * File name for the controller model.
- */
- public static MODEL_FILENAME: string = 'wand.babylon';
- public profileId = "htc-vive";
- private _modelRootNode: AbstractMesh;
- constructor(scene: Scene,
- gamepadObject: IMinimalMotionControllerObject,
- handness: MotionControllerHandness/*,
- private _legacyMapping: boolean = false*/) {
- super(scene, HTCViveLayout[handness], gamepadObject, handness);
- }
- protected _processLoadedModel(_meshes: AbstractMesh[]): void {
- // this.layout.gamepad!.buttons.forEach((buttonName) => {
- // const comp = buttonName && this.getComponent(buttonName);
- // if (comp) {
- // comp.onButtonStateChanged.add((component) => {
- // if (!this.rootMesh) { return; }
- // switch (buttonName) {
- // case "xr-standard-trigger":
- // (<AbstractMesh>(this._modelRootNode.getChildren()[6])).rotation.x = -component.value * 0.15;
- // return;
- // case "xr-standard-touchpad":
- // return;
- // case "xr-standard-squeeze":
- // return;
- // }
- // }, undefined, true);
- // }
- // });
- }
- protected _getFilenameAndPath(): { filename: string; path: string; } {
- let filename = WebXRHTCViveMotionController.MODEL_FILENAME;
- let path = WebXRHTCViveMotionController.MODEL_BASE_URL;
- return {
- filename,
- path
- };
- }
- protected _updateModel(): void {
- // no-op. model is updated using observables.
- }
- protected _getModelLoadingConstraints(): boolean {
- return true;
- }
- protected _setRootMesh(meshes: AbstractMesh[]): void {
- this.rootMesh = new Mesh(this.profileId + " " + this.handness, this.scene);
- meshes.forEach((mesh) => { mesh.isPickable = false; });
- this._modelRootNode = meshes[1];
- this._modelRootNode.parent = this.rootMesh;
- this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);
- }
- }
- // register the profile
- WebXRMotionControllerManager.RegisterController("htc-vive", (xrInput: XRInputSource, scene: Scene) => {
- return new WebXRHTCViveMotionController(scene, <any>(xrInput.gamepad), xrInput.handedness);
- });
- // WebXRMotionControllerManager.RegisterController("htc-vive-legacy", (xrInput: XRInputSource, scene: Scene) => {
- // return new WebXRHTCViveMotionController(scene, <any>(xrInput.gamepad), xrInput.handedness, true);
- // });
|