| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import {
- WebXRAbstractMotionController,
- IMinimalMotionControllerObject,
- MotionControllerHandness,
- IMotionControllerLayoutMap
- } from "./webXRAbstractMotionController";
- import { AbstractMesh } from '../../Meshes/abstractMesh';
- import { Scene } from '../../scene';
- import { Mesh } from '../../Meshes/mesh';
- import { Quaternion } from '../../Maths/math.vector';
- /**
- * A generic trigger-only motion controller for WebXR
- */
- export class WebXRGenericTriggerMotionController extends WebXRAbstractMotionController {
- /**
- * Static version of the profile id of this controller
- */
- public static ProfileId = "generic-trigger";
- public profileId = WebXRGenericTriggerMotionController.ProfileId;
- constructor(scene: Scene, gamepadObject: IMinimalMotionControllerObject, handness: MotionControllerHandness) {
- super(scene, GenericTriggerLayout[handness], gamepadObject, handness);
- }
- protected _processLoadedModel(meshes: AbstractMesh[]): void {
- // nothing to do
- }
- protected _updateModel(): void {
- // no-op
- }
- protected _getFilenameAndPath(): { filename: string; path: string; } {
- return {
- filename: "generic.babylon",
- path: "https://controllers.babylonjs.com/generic/"
- };
- }
- protected _setRootMesh(meshes: AbstractMesh[]): void {
- this.rootMesh = new Mesh(this.profileId + " " + this.handness, this.scene);
- meshes.forEach((mesh) => {
- mesh.isPickable = false;
- if (!mesh.parent) {
- mesh.setParent(this.rootMesh);
- }
- });
- this.rootMesh.rotationQuaternion = Quaternion.FromEulerAngles(0, Math.PI, 0);
- }
- protected _getModelLoadingConstraints(): boolean {
- return true;
- }
- }
- // https://github.com/immersive-web/webxr-input-profiles/blob/master/packages/registry/profiles/generic/generic-trigger-touchpad-thumbstick.json
- const GenericTriggerLayout: IMotionControllerLayoutMap = {
- "left": {
- "selectComponentId": "xr-standard-trigger",
- "components": {
- "xr-standard-trigger": {
- "type": "trigger",
- "gamepadIndices": {
- "button": 0
- },
- "rootNodeName": "xr_standard_trigger",
- "visualResponses": {}
- }
- },
- "gamepadMapping": "xr-standard",
- "rootNodeName": "generic-trigger-left",
- "assetPath": "left.glb"
- },
- "right": {
- "selectComponentId": "xr-standard-trigger",
- "components": {
- "xr-standard-trigger": {
- "type": "trigger",
- "gamepadIndices": {
- "button": 0
- },
- "rootNodeName": "xr_standard_trigger",
- "visualResponses": {}
- }
- },
- "gamepadMapping": "xr-standard",
- "rootNodeName": "generic-trigger-right",
- "assetPath": "right.glb"
- },
- "none": {
- "selectComponentId": "xr-standard-trigger",
- "components": {
- "xr-standard-trigger": {
- "type": "trigger",
- "gamepadIndices": {
- "button": 0
- },
- "rootNodeName": "xr_standard_trigger",
- "visualResponses": {}
- }
- },
- "gamepadMapping": "xr-standard",
- "rootNodeName": "generic-trigger-none",
- "assetPath": "none.glb"
- }
- };
|