@vrspace/babylonjs
Version:
vrspace.org babylonjs client
234 lines (233 loc) • 7.87 kB
TypeScript
/**
Wrapper around BabylonJS XR/VR classes, whatever is available in current browser, if any.
Attached to a World, uses World floor meshes and camera.
Tracks available VR controllers and gamepad, and updates state variables.
As Babylon.js in XR mode doesn't make use of the gamepad, this implements necessary methods to make it useful,
ones that pass gamepad events to HUD and scene.
While this is mandatory to use gamepad in XR, it is also useful outside of XR, and is quite handy on mobiles.
CHECKME: SoC?
*/
export class VRHelper {
static instances: {};
static activeInstance: any;
static getInstance(sessionMode?: string): any;
constructor(sessionMode?: string);
/** Underlying babylon VR (obsolete) or XR helper (WebXRDefaultExperience) component */
vrHelper: any;
/** @type {World} */
world: World;
/** Function that tracks XR devices (headeset, controllers), calls this.trackXrDevices() */
xrDeviceTracker: () => void;
tracking: boolean;
controller: {
left: any;
right: any;
};
/** Function that tracks enter/exit VR */
stateChangeObserver: (state: any) => void;
/** Function that tracks turning XR controllers on/off */
controllerObserver: (xrController: any) => void;
/** left and right trigger, if available */
trigger: {
left: any;
right: any;
};
/** left and right squeeze, if available */
squeeze: {
left: any;
right: any;
};
/** left and right thumbstick, if available */
thumbstick: {
left: any;
right: any;
};
/** left and right touchpad, if available */
touchpad: {
left: any;
right: any;
};
/** left and right buttons. */
buttons: {
left: any[];
right: any[];
};
squeezeConsumers: any[];
triggerListeners: any[];
activeController: string;
teleporting: boolean;
sessionMode: string;
userHeight: number;
/** or NONE, or SLIDE */
movementMode: string;
/**
@param {World} world attaches the control to the World
*/
initXR(world: World): Promise<void>;
movementObserver: () => void;
initialPoseObserver: (xrCamera: any) => void;
touchTimestamp: number;
isSelectableMesh(mesh: any): boolean;
gamepadTrigger(state: any): void;
trackGamepad(): void;
teleportTarget: any;
enableBackground(enabled: any): void;
/**
* Rotates the WebXRCamera by given angle
*/
changeRotation(angle: any): void;
/**
* Change position of WebXRCamera by given distance, i.e. moves forward or back
*/
changePosition(distance: any): void;
teleportForward(): void;
/**
* Start of teleportation, when gampad stick is pressed forward.
* Installs a ray caster into rendering loop, that moves teleportation destination marker around.
*/
teleportStart(): void;
caster: () => void;
/**
* End of teleportation: moves the camera to the destination (this.teleportTarget) and cleans up.
*/
teleportEnd(): void;
trackMotionController(controller: any, side: any): void;
/**
* Track thumbsticks on VR controllers. Thumbsticks are used for teleporatation by default,
* so this may be useful when teleporation is disabled.
* @param callback function to call when thumbsticks change, passed position (x,y) and side (left/right)
*/
trackThumbsticks(callback: any): void;
/**
* Used internally to track squeeze buttons of VR controllers. Disables the teleporation if a button is pressed.
* Calls squeeze listeners, passing the them the value (0-1) and side (left/right);
*/
squeezeTracker(component: any, side: any): void;
/**
* Adds given callback to the list of XR controller squeeze button consumer.
* Consumer is passed value(0-1) and side (left/right) of the event.
* If it consumes the event, returns false.
* @param callback returns true if processing should continue
*/
addSqueezeConsumer(callback: any): void;
/** Remove squeeze listener */
removeSqueezeConsumer(callback: any): void;
/**
* Used internally to track triggers of VR controllers. Disables the teleporation if a trigger is pressed.
* Calls trigger listeners, passing the them the value (0-1) and side (left/right);
*/
triggerTracker(component: any, side: any): void;
/**
* Adds given callback to the list of XR controller trigger listeners
* CHECKME: include gamepad trigger?
*/
addTriggerListener(callback: any): void;
/** Remove trigger listener */
removeTriggerListener(callback: any): void;
/**
* Called after teleoportation to update non-VR world camera and dynamic terrain if needed
*/
afterTeleportation(): void;
/**
* Creates pointer ray and intersection mesh.
*/
createPointer(): void;
pointerTarget: any;
pointerLines: any;
/**
* Removes pointer ray and target
*/
clearPointer(): void;
/**
* Called from render loop to set internal state variables, and implements XR pointer for mobile devices.
* When XR controllers are unavailable, it renders a ray pointing forward, and moves pointer mesh to
* ray intersection with scene meshes.
* Calls World.trackXrDevices()
*/
trackXrDevices(): void;
pickInfo: any;
/**
* Start XR device tracking: prepare pointer ray and mesh, and register tracking function (trackXrDevices) to scene render loop.
*/
startTracking(): void;
/**
* Stop XR device tracking: clean up
*/
stopTracking(): void;
/**
* Returns the absolute position of left or right controller grip
* @param side left or right
*/
armPos(side: any): any;
/**
* Returns the absolute position of left controller grip
*/
leftArmPos(): any;
/**
* Returns the absolute position of right controller grip
*/
rightArmPos(): any;
/**
* Returns the rotation quaternion of left or right controller grip
* @param side left or right
*/
armRot(side: any): any;
/**
* Returns the rotation quaternion of left controller grip
*/
leftArmRot(): any;
/**
* Returns the rotation quaternion of right controller grip
*/
rightArmRot(): any;
/**
* Returns the height of the user, as defined by WebXRCamera
*/
realWorldHeight(): number;
/**
* Returns the current WebXRCamera
*/
camera(): any;
/**
* Internally used to add teleportation mesh
*/
addFloorMesh(mesh: any): void;
/**
* Internally used to remove teleportation mesh
*/
removeFloorMesh(mesh: any): void;
/**
* Returns the current ray selection predicate, and optionally installs a new one
*/
raySelectionPredicate(predicate: any): any;
/**
* Removes all current teleportation meshes
*/
clearFloors(): void;
/**
* Adds all world floor meshes to teleportation
*/
addFloors(): void;
/**
* Disable sliding movement and enable teleportation.
*/
enableTeleportation(): void;
/**
* Experimental, quite limited.
* Disable teleportation and enable sliding movement.
* Movement then ignores collisions, i.e. camera flies through everything.
* Correctly implementing this will require collision calculation using a collider mesh,
* mesh.moveWithCollisions(), then setting camera positon - much like AvatarMovement.moveAvatar().
*/
enableSliding(): void;
/**
* Disable both teleportation and sliding.
*/
disableMovement(): void;
/**
* Enable movement in given mode
* @param {string} mode TELEPORT or SLIDE
*/
enableMovement(mode: string): void;
}
import { World } from '../world/world.js';