Class: VRHelper

VRHelper()

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?

Constructor

new VRHelper()

Source:

Classes

VRHelper

Members

buttons

left and right buttons.
Source:

controllerObserver

Function that tracks turning XR controllers on/off
Source:

squeeze

left and right squeeze, if available
Source:

stateChangeObserver

Function that tracks enter/exit VR
Source:

thumbstick

left and right thumbstick, if available
Source:

touchpad

left and right touchpad, if available
Source:

trigger

left and right trigger, if available
Source:

vrHelper

Underlying babylon VR (obsolete) or XR helper (WebXRDefaultExperience) component
Source:

Methods

addFloorMesh()

Internally used to add teleportation mesh
Source:

addFloors()

Adds all world floor meshes to teleportation
Source:

addSqueezeConsumer(callback)

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.
Parameters:
Name Type Description
callback returns true if processing should continue
Source:

addTriggerListener()

Adds given callback to the list of XR controller trigger listeners CHECKME: include gamepad trigger?
Source:

afterTeleportation()

Called after teleoportation to update non-VR world camera and dynamic terrain if needed
Source:

armPos(side)

Returns the absolute position of left or right controller grip
Parameters:
Name Type Description
side left or right
Source:

armRot(side)

Returns the rotation quaternion of left or right controller grip
Parameters:
Name Type Description
side left or right
Source:

camera()

Returns the current WebXRCamera
Source:

changePosition()

Change position of WebXRCamera by given distance, i.e. moves forward or back
Source:

changeRotation()

Rotates the WebXRCamera by given angle
Source:

clearFloors()

Removes all current teleportation meshes
Source:

clearPointer()

Removes pointer ray and target
Source:

createPointer()

Creates pointer ray and intersection mesh.
Source:

gamepadButton(index, state)

Gamepad button event handler. Buttons left/right/up/down are forwarded to the HUD. Trigger button and select button events are forwarded either to HUD, or to the scene, as appropriate.
Parameters:
Name Type Description
index button index, see https://github.com/alvaromontoro/gamecontroller.js/blob/master/public/gamepad.svg
state true/false for pressed/released
Source:

(async) initXR(world)

Parameters:
Name Type Description
world attaches the control to the World
Source:

leftArmPos()

Returns the absolute position of left controller grip
Source:

leftArmRot()

Returns the rotation quaternion of left controller grip
Source:

raySelectionPredicate()

Returns the current ray selection predicate, and optionally installs a new one
Source:

realWorldHeight()

Returns the height of the user, as defined by WebXRCamera
Source:

removeFloorMesh()

Internally used to remove teleportation mesh
Source:

removeSqueezeConsumer()

Remove squeeze listener
Source:

removeTriggerListener()

Remove trigger listener
Source:

rightArmPos()

Returns the absolute position of right controller grip
Source:

rightArmRot()

Returns the rotation quaternion of right controller grip
Source:

squeezeTracker()

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);
Source:

startTracking()

Start XR device tracking: prepare pointer ray and mesh, and register tracking function (trackXrDevices) to scene render loop.
Source:

stopTracking()

Stop XR device tracking: clean up
Source:

teleportEnd()

End of teleportation: moves the camera to the destination (this.teleportTarget) and cleans up.
Source:

teleportStart()

Start of teleportation, when gampad stick is pressed forward. Installs a ray caster into rendering loop, that moves teleportation destination marker around.
Source:

trackGamepad()

Main point of gamepad support. Once the browser emits gamepadconnected event, installs tracker function into main rendering loop, to track states that rotate the camera, teleport, and fire gamepad button events.
Source:

trackThumbsticks(callback)

Track thumbsticks on VR controllers. Thumbsticks are used for teleporatation by default, so this may be useful when teleporation is disabled.
Parameters:
Name Type Description
callback function to call when thumbsticks change, passed position (x,y) and side (left/right)
Source:

trackXrDevices()

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()
Source:

triggerTracker()

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);
Source:

xrDeviceTracker()

Function that tracks XR devices (headeset, controllers), calls this.trackXrDevices()
Source: