JavaScript Components
8thwall-camera
Sets up the 8thwall pipeline and retrieves tracking events to place an object at the location of the tracked AR camera / mobile device.
Use this for SLAM tracking based on 8thwall.
Make sure to enable 8thwall in “Project Settings” > “AR”. See also the AR Getting Started Guide.
Param | Type | Description |
---|---|---|
camera | Enum | Choose front/back camera |
cursor-target
Click/hover/move/button target for cursor.
To trigger code when clicking, hovering, unhovering, moving cursor, pressing
cursor button or releasing cursor button, use .addClickFunction(f)
,
.addHoverFunction(f)
, .addUnHoverFunction(f)
,
.addMoveFunction(f)
, .addDownFunction(f)
and
.addUpFunction(f)
respectively with any function f() {}
.
To call members on a different component, you can set up a cursor target like so:
Functions:
1callback = function(object, cursorComponent) {};
2
3addHoverFunction(callback);
4removeHoverFunction(callback);
5
6addUnHoverFunction(callback);
7removeUnHoverFunction(callback);
8
9addClickFunction(callback);
10removeClickFunction(callback);
11
12addMoveFunction(callback);
13removeMoveFunction(callback);
14
15addDownFunction(callback);
16removeDownFunction(callback);
17
18addUpFunction(callback);
19removeUpFunction(callback);
Requirements:
- a
collision
component to be attached to the same object.
See Animation Example.
cursor
3D cursor for desktop/mobile/VR.
Implements a ray-casting cursor into the scene. To react to clicking/hover/unhover/cursor down/cursor up/move use a cursor-target.
For VR, the ray is cast in direction of this.object.getForward(). For desktop and mobile, the forward vector is inverse-projected to account for where on screen the user clicked.
.globalTarget
can be used to call callbacks for all objects, even those that
do not have a cursor target attached, but match the collision group.
See Animation Example.
Param | Type | Description |
---|---|---|
collisionGroup | Int | Collision group for the ray cast. Only objects in this group will be affected by this cursor. |
cursorRayObject | Object | (optional) Object that visualizes the cursor’s ray. |
cursorRayScalingAxis | Enum | Axis along which to scale the cursorRayObject . |
cursorObject | Object | (optional) Object that visualizes the cursor’s hit location. |
handedness | Enum | Handedness for VR cursors to accept trigger events only from respective controller. |
rayCastMode | Enum | Mode for raycasting, whether to use PhysX or simple collision components |
styleCursor | Bool | Whether to set the CSS style of the mouse cursor on desktop |
debug-object
Prints some limited debug information about the object.
Information consists of: This object’s name, an object parameter’s name, the object’s world translation, world transform and local transform.
Mainly used by engine developers for debug purposes or as example code.
Param | Type | Description |
---|---|---|
obj | Object | A second object to print the name of |
device-orientation-look
Retrieve device orientation from a mobile device and set the object’s orientation accordingly.
Useful for magic window experiences.
finger-cursor
0.8.5+Enables interaction with cursor-targets through collision overlaps, e.g. on the tip of a finger on a tracked hand.
Requirements:
- A collision component (usually a sphere with
0.05
radius) on the same object
fixed-foveation
Applies fixed foveation once a WebXR session is started
Fixed foveation reduces shading cost at the periphery by rendering at lower resolutions at the edges of the users vision.
Param | Type | Description |
---|---|---|
fixedFoveation | Float | Amount to apply from 0 (none) to 1 (full) |
hand-tracking
Easy hand tracking through the WebXR Device API “Hand Input” API.
Allows displaying hands either as sphere-joints or skinned mesh.
To react to grabbing, use this.isGrabbing()
. For other gestures, refer
to this.joints
- an array of WL.Object and use the joint
indices listed in the WebXR Hand Input specification.
It is often desired to use either hand tracking or controllers, not both.
This component provides deactivateChildrenWithoutPose
to hide the hand
tracking visualization if no pose is available and controllerToDeactivate
for disabling another object once a hand tracking pose is available.
Outside of XR sessions, tracking or controllers are neither enabled nor disabled
to play well with the vr-mode-active-switch component.
Requirements:
- To use hand-tracking, enable “joint tracking” in
chrome://flags
on Oculus Browser for Oculus Quest/Oculus Quest 2.
Param | Type | Description |
---|---|---|
handedness | Enum | Handedness determining whether to receive tracking input from right or left hand |
jointMesh | Mesh | (optional) Mesh to use to visualize joints |
jointMaterial | Material | Material to use for display. Applied to either the spawned skinned mesh or the joint spheres. |
handSkin | Skin | (optional) Skin to apply tracked joint poses to. If not present, joint spheres will be used for display instead. |
deactivateChildrenWithoutPose | Bool | Deactivate children if no pose was tracked |
controllerToDeactivate | Object | Controller objects to activate including children if no pose is available |
hit-test-location
Sets up a WebXR Device API “Hit Test” and places the object to the hit location.
Requirements:
- Specify
'hit-test'
in the required or optional features on the AR button in your html file. See Wastepaperbin AR as an example.
howler-audio-listener
(Spatial) audio listener based on Howler.js.
Retrieves the location and orientation of the object and passes it to Howler.pos() and Howler.orientation().
Param | Type | Description |
---|---|---|
spatial | Bool | Whether audio should be spatialized/positional. |
howler-audio-source
(Spatial) audio source based on Howler.js.
Creates a Howler audio source, plays an audio file on it and updates its position.
Optimizes the position update to only update if the difference to last
position is larger than half a centimeter. To force updates (e.g. if
the sound source is very close to the listener),
use .updatePosition()
.
Param | Type | Description |
---|---|---|
volume | Float | Volume |
spatial | Bool | Whether audio should be spatialized/positional |
loop | Bool | Whether to loop the sound |
autoplay | Bool | Whether to start playing automatically |
src | String | URL to a sound file to play |
image-texture
Downloads an image from URL and applies it as diffuseTexture
or flatTexture
to an attached mesh component.
Only “Phong Opaque Textured” and “Flat Opaque Textured” materials are supported.
Warning: This component will soon be changed to be consistent with
video-texture and change a material rather than mesh.
To make sure your code keeps working in future versions of the engine,
please use material
rather than meshIndex
.
Param | Type | Description |
---|---|---|
url | String | URL to download the image from |
meshIndex | Int | 0-based mesh component index on this object (e.g. 1 for “second mesh”). Deprecated: Please use material instead. |
material | Material | Material to apply the video texture to (if null , tries to apply to the mesh with meshIndex ) |
input-profile
Dynamically load and map input profiles for XR controllers.
Property | Type | Description |
---|---|---|
handedness | Enum | The index representing the handedness of the controller (0 for left, 1 for right). |
defaultBasePath | String | The url for base path where XR input profiles are stored.By default fallbacks to https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@latest/dist/profiles/ |
customBasePath | String | An optional folder path for loading custom XR input profiles. You can put your custom profile model and profile.json in a folder inside static and reference it here. If not empty this overrides defaultBasePath. |
defaultController | Object3D | The default 3D controller model used when a custom model fails to load. Fallback to first child object |
trackedHand | Object3D | The object which has the HandTracking component added to it. Fallback to its sibling with name HandLeft or HandRight w.r.t the handedness. |
mapToDefaultController | Boolean | If true, the input profile will be mapped to the default controller, and no dynamic 3D model of the controller will be loaded. |
addVrModeSwitch | Boolean | If true, adds a VR mode switch component to the loaded controller model. |
onModelLoaded
: Emitter which triggers on model loaded event.toFilter
: A set of components to filter during default controller component retrieval.
mouse-look
Controls the camera through mouse movement.
Efficiently implemented to affect object orientation only when the mouse moves.
Param | Type | Description |
---|---|---|
sensitity | Float | Mouse look sensitivity |
requireMouseDown | Bool | Require a mouse button to be pressed to control view. Otherwise view will allways follow mouse movement |
mouseButtonIndex | Int | If “moveOnClick” is enabled, mouse button which should be held down to control view |
pointerLockOnClick | Bool | Enables pointer lock on “mousedown” event on WL.canvas |
player-height
Set player height for a Y-offset above the ground for
’local’ and ‘viewer’ WebXR.refSpace
.
Param | Type | Description |
---|---|---|
height | Float |
target-framerate
Sets the target framerate
Updates the target framerate
to the closest supported target framerate
to the given framerate
.
The target framerate is used for the device’s VR compositor as an indication of how often to refresh the screen with new images. This means the app will be asked to produce frames in more regular intervals, potentially spending less time on frames that are likely to be dropped.
For apps with heavy load, setting a well matching target framerate can improve the apps rendering stability and reduce stutter.
Likewise, the target framerate can be used to enable 120Hz refresh rates on Oculus Quest 2 on simpler apps.
Param | Type | Description |
---|---|---|
framerate | Float |
teleport
Teleport VR locomotion.
See Teleport Example.
Param | Type | Description |
---|---|---|
teleportIndicatorMeshObject | Object | Object that will be placed as indiciation forwhere the player will teleport to. |
camRoot | Object | Root of the player, the object that will be positioned on teleportation. |
cam | Object | Non-vr camera for use outside of VR |
eyeLeft | Object | Left eye for use in VR |
eyeRight | Object | Right eye for use in VR |
handedness | Enum | Handedness for VR cursors to accept trigger events only from respective controller. |
floorGroup | Int | Collision group of valid “floor” objects that can be teleported on |
thumbstickActivationThreshhold | Float | How far the thumbstick needs to be pushed to have the teleport target indicator show up |
thumbstickDeactivationThreshhold | Float | How far the thumbstick needs to be released to execute the teleport |
indicatorYOffset | Float | Offset to apply to the indicator object, e.g. to avoid it from Z-fighting with the floor |
rayCastMode | Enum | Mode for raycasting, whether to use PhysX or simple collision components |
maxDistance | Float | Max distance for PhysX raycast |
two-joint-ik-solver
Inverse Kinematics for two-joint chains (e.g. knees or ellbows)
Param | Type | Description |
---|---|---|
root | Object | Root bone, never moves |
middle | Object | Bone attached to the root |
end | Object | Bone attached to the middle |
target | Object | Target the joins should reach for |
helper | Object | Helper object to use to determine joint rotation axis |
video-texture
Downloads a video from URL and applies it as diffuseTexture
or flatTexture
on given material.
Video textures need to be updated regularly whenever a new frame is available. This component handles the detection of a new frame and updates the texture to reflect the video’s current frame. Only “Phong Opaque Textured” and “Flat Opaque Textured” materials are supported.
The video can be accessed through this.video
:
See Video Example.
Param | Type | Description |
---|---|---|
url | String | URL to download video from |
material | Material | Material to apply the video texture to |
loop | Bool | Whether to loop the video |
autoplay | Bool | Whether to automatically start playing the video |
muted | Bool | Whether to mute sound |
vr-mode-active-switch
Allows switching all other components on an object to active/inactive depending on whether a VR/AR session is active.
Useful for hiding controllers until the user enters VR for example.
Param | Type | Description |
---|---|---|
activateComponents | Enum | When components should be active: In VR or when not in VR |
affectChildren | Bool | Whether child object’s components should be affected |
vrm
Component for loading and handling VRM 1.0 models.
Posing of the model should be done exclusively by rotating the bones. These can be
accessed using the .bones
property and follow the VRM bone naming. Note that not
all VRM models will have all possible bones. The rest pose (T-pose) is captured in
the .restPose
property. Resetting a bone to its rest pose can be done as follows:
1vrmComponent.bones[vrmBoneName].rotationLocal = vrmComponent.restPose[vrmBoneName];
Moving the model through the world should be done by moving the object this component is attached to. In other words, by moving the root of the VRM model. The bones and any descendant objects should not be used to move the VRM model.
The core extension VRMC_vrm
as well as theVRMC_springBone
and VRMC_node_constraint
extensions are supported.
Limitations:
- No support for
VRMC_material_mtoon
- Expressions aren’t supported
- Expression based lookAt isn’t supported
- Mesh annotation mode
auto
is not supported (first person mode)
Param | Type | Description |
---|---|---|
src | String | URL to a VRM file to load |
lookAtTarget | Object | Object the VRM is looking at |
wasd-controls
Basic movement with W/A/S/D keys.
Param | Type | Description |
---|---|---|
speed | Float | Movement speed in m/s. |
headObject | Object | Object of which the orientation is used to determine forward direction |