Class: HUD

HUD(camera)

HUD stands for head-up display - a UI container mounted on users head. Typically we have some buttons around 50 cm front, 10-20 cm below line of sight. This is common UI supposed to be usefull on VR devices, PC and mobiles, but likely to be suboptimal - UI specifically designed for a device should be more ergonomic. By default it tracks active camera, and binds to new camera whenever active camera changes, e.g. upon entering/exiting VR. Constructed with a camera parameter, it does not rebind to a new one. This allows to have multiple HUDs attached to different cameras, e.g. switching from first-person view to god mode activates a different HUD. But in XR, it can be attached to left or right controller instead of camera: just grab any hud element and squeeze, i.e. use squeeze button. Press both squeeze buttons to attach hud back to the camera. Typically HUD is just a collection of buttons, but it can also contain different UI elements, e.g. sliders, and even forms. It takes input from mouse, touch screen, VR controllers and even gamepad, and delegates it to underlying UI elements as appropriate. It can contain multiple rows, each containing multiple buttons, but a row can contain only one Form.

Constructor

new HUD(camera)

Parameters:
Name Type Description
camera to track, by default tracks active camera
Source:

Classes

HUD

Members

vrHelper

set by World.InitXR()
Source:

Methods

activate()

Input delegate method, activates the current control (as if clicked on)
Source:

activateButton()

Activates given button, if it's visible
Source:

addAttachment()

Add an attachment mesh. It will be used for XR controller manipulation as other hud elements. However, mesh parent isn't changed, it has to be set by caller to hud root.
Source:

addButton(text, imageUrl, onPointerDown, shareMaterial)

Create a button with given text and image and add it to the HUD
Parameters:
Name Type Default Description
text description to display
imageUrl image to display
onPointerDown callback function activated when pressed
shareMaterial true optional, defaults to true, use shared material for all buttons or create a new one
Source:
Returns:
a BabylonJS HolographicButton

addColorPicker()

Adds color picker to the HUD.
Source:
Returns:
babylon ColorPicker object

addForm(form, textureWidth, textureHeight)

Adds a Form to the hud. Creates and returns AdvancedDynamicTexture to render the form.
Parameters:
Name Type Description
form to add
textureWidth width in pixels
textureHeight height in pixels
Source:

addSlider()

Adds a slider to the HUD.
Source:
Returns:
babylon Slider object

attachedController()

Returns VR controller this HUD is attached to, or null
Source:

attachToCamera()

Attach HUD to camera it was created with.
Source:

attachToLeftController()

Attach hud to left hand
Source:

attachToRightController()

Attach hud to right hand
Source:

clearControls()

Clears and disposes of all controls in the current row
Source:

clearRow()

Clears the current row. Previous row is scaled back to original size and brought back into position.
Source:

currentRow()

Returns the current row
Source:

distance()

Returns distance of the HUD from the camera
Source:

down()

Input delegate method, process a gamepad up button event: go back to previous row, or forward to the Form.
Source:

enableSpeech(enable)

Enable/disable speech input.
Parameters:
Name Type Description
enable true/false to enable/disable
Source:

getActiveControl()

Input delegate method, returns active control current in row or form.
Source:

getControlIndex()

Input delegate method, returns index of control current in row or form.
Source:

getControls()

Input delegate method, returns controls available in the current row or form.
Source:

initXR(vrHelper)

Initialize XR - allows to grab hud in left or right hand
Parameters:
Name Type Description
vrHelper VRHelper
Source:

intersects()

Returns true if mesh intersects any of hud elements. Allows to 'grab' the hud with a VR controller.
Source:

inXR()

Returns true if XR mode is active (current camera is WebXRCamera)
Source:

isActive()

Returns true if button color matches colorActive
Source:

isEnabled()

Returns true if button color matches colorEnabled
Source:

isSelectableMesh()

Used XR pointer selection predicate, returns true if selection is allowed and given mesh is one of HUD elements.
Source:

left()

Activates previous element (gamepad left button)
Source:

makeRoomForMore()

Called before adding a new button to reposition existing ones
Source:

markActive()

Helper method to set button color to green, note that button needs it's own material.
Source:

markButton()

Common code for markEnabled/Disabled/Active
Source:

markDisabled()

Helper method to set button color to red, note that button needs it's own material.
Source:

markEnabled()

Helper method to set button color, note that button needs it's own material.
Source:

newRow()

Creates a new empty row. Current row is scaled down and moved a bit down.
Source:

next(increment)

Input delegate method, internal state management. Activates next or previous element, ignoring invisible ones.
Parameters:
Name Type Description
increment 1 or 1 for previous/next
Source:

otherController()

If attached to a hand, returns the other hand, or null otherwise
Source:

removeAttachment()

Detach an attached mesh. Parent is not changed here.
Source:

rescaleHUD()

Window.resize event handler, rescales the HUD if aspect ratio is too small for all buttons to fit.
Source:
Activates next element (gamepad right button)
Source:

scaling()

Returns scaling of the HUD
Source:

selectControl()

Input delegate method, selects the control at given index, keeps track of bounds and wraps around.
Source:

selectCurrent()

Input delegate method, selects current control (button or Form element) at given index.
Source:

setActiveControl()

Input delegate method, sets active control current in row or form.
Source:

showButtons(show, …except)

Show or hide all HUD elements (buttons)
Parameters:
Name Type Attributes Description
show show or hide
except <repeatable>
optional element(s) to skip
Source:

trackCamera()

Handles camera change events, typically while entering/exiting VR.
Source:

unselectCurrent()

Input delegate method, deselects current control.
Source:

up()

Input delegate method, process a gamepad up button event: activate a button or delegate it to the Form.
Source:

vertical()

Returns vertical position of the HUD
Source: