Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

XRInterface

Inherits: RefCounted < Object

Inherited By: MobileVRInterface, OpenXRInterface, WebXRInterface, XRInterfaceExtension

Base class for an XR interface implementation.

Description

This class needs to be implemented to make an AR or VR platform available to Godot and these should be implemented as C++ modules or GDExtension modules. Part of the interface is exposed to GDScript so you can detect, enable and configure an AR or VR platform.

Interfaces should be written in such a way that simply enabling them will give us a working setup. You can query the available interfaces through XRServer.

Tutorials

Properties

bool

ar_is_anchor_detection_enabled

false

EnvironmentBlendMode

environment_blend_mode

0

bool

interface_is_primary

false

PlayAreaMode

xr_play_area_mode

0

Methods

int

get_camera_feed_id ( )

int

get_capabilities ( ) const

StringName

get_name ( ) const

PackedVector3Array

get_play_area ( ) const

Projection

get_projection_for_view ( int view, float aspect, float near, float far )

Vector2

get_render_target_size ( )

Array

get_supported_environment_blend_modes ( )

Dictionary

get_system_info ( )

TrackingStatus

get_tracking_status ( ) const

Transform3D

get_transform_for_view ( int view, Transform3D cam_transform )

int

get_view_count ( )

bool

initialize ( )

bool

is_initialized ( ) const

bool

is_passthrough_enabled ( )

bool

is_passthrough_supported ( )

bool

set_environment_blend_mode ( EnvironmentBlendMode mode )

bool

set_play_area_mode ( PlayAreaMode mode )

bool

start_passthrough ( )

void

stop_passthrough ( )

bool

supports_play_area_mode ( PlayAreaMode mode )

void

trigger_haptic_pulse ( String action_name, StringName tracker_name, float frequency, float amplitude, float duration_sec, float delay_sec )

void

uninitialize ( )


Signals

play_area_changed ( int mode )

Emitted when the play area is changed. This can be a result of the player resetting the boundary or entering a new play area, the player changing the play area mode, the world scale changing or the player resetting their headset orientation.


Enumerations

enum Capabilities:

Capabilities XR_NONE = 0

No XR capabilities.

Capabilities XR_MONO = 1

This interface can work with normal rendering output (non-HMD based AR).

Capabilities XR_STEREO = 2

This interface supports stereoscopic rendering.

Capabilities XR_QUAD = 4

This interface supports quad rendering (not yet supported by Godot).

Capabilities XR_VR = 8

This interface supports VR.

Capabilities XR_AR = 16

This interface supports AR (video background and real world tracking).

Capabilities XR_EXTERNAL = 32

This interface outputs to an external device. If the main viewport is used, the on screen output is an unmodified buffer of either the left or right eye (stretched if the viewport size is not changed to the same aspect ratio of get_render_target_size). Using a separate viewport node frees up the main viewport for other purposes.


enum TrackingStatus:

TrackingStatus XR_NORMAL_TRACKING = 0

Tracking is behaving as expected.

TrackingStatus XR_EXCESSIVE_MOTION = 1

Tracking is hindered by excessive motion (the player is moving faster than tracking can keep up).

TrackingStatus XR_INSUFFICIENT_FEATURES = 2

Tracking is hindered by insufficient features, it's too dark (for camera-based tracking), player is blocked, etc.

TrackingStatus XR_UNKNOWN_TRACKING = 3

We don't know the status of the tracking or this interface does not provide feedback.

TrackingStatus XR_NOT_TRACKING = 4

Tracking is not functional (camera not plugged in or obscured, lighthouses turned off, etc.).


enum PlayAreaMode:

PlayAreaMode XR_PLAY_AREA_UNKNOWN = 0

Play area mode not set or not available.

PlayAreaMode XR_PLAY_AREA_3DOF = 1

Play area only supports orientation tracking, no positional tracking, area will center around player.

PlayAreaMode XR_PLAY_AREA_SITTING = 2

Player is in seated position, limited positional tracking, fixed guardian around player.

PlayAreaMode XR_PLAY_AREA_ROOMSCALE = 3

Player is free to move around, full positional tracking.

PlayAreaMode XR_PLAY_AREA_STAGE = 4

Same as XR_PLAY_AREA_ROOMSCALE but origin point is fixed to the center of the physical space, XRServer.center_on_hmd disabled.


enum EnvironmentBlendMode:

EnvironmentBlendMode XR_ENV_BLEND_MODE_OPAQUE = 0

Opaque blend mode. This is typically used for VR devices.

EnvironmentBlendMode XR_ENV_BLEND_MODE_ADDITIVE = 1

Additive blend mode. This is typically used for AR devices or VR devices with passthrough.

EnvironmentBlendMode XR_ENV_BLEND_MODE_ALPHA_BLEND = 2

Alpha blend mode. This is typically used for AR or VR devices with passthrough capabilities. The alpha channel controls how much of the passthrough is visible. Alpha of 0.0 means the passthrough is visible and this pixel works in ADDITIVE mode. Alpha of 1.0 means that the passthrough is not visible and this pixel works in OPAQUE mode.


Property Descriptions

bool ar_is_anchor_detection_enabled = false

  • void set_anchor_detection_is_enabled ( bool value )

  • bool get_anchor_detection_is_enabled ( )

On an AR interface, true if anchor detection is enabled.


EnvironmentBlendMode environment_blend_mode = 0

Specify how XR should blend in the environment. This is specific to certain AR and passthrough devices where camera images are blended in by the XR compositor.


bool interface_is_primary = false

  • void set_primary ( bool value )

  • bool is_primary ( )

true if this is the primary interface.


PlayAreaMode xr_play_area_mode = 0

The play area mode for this interface.


Method Descriptions

int get_camera_feed_id ( )

If this is an AR interface that requires displaying a camera feed as the background, this method returns the feed ID in the CameraServer for this interface.


int get_capabilities ( ) const

Returns a combination of Capabilities flags providing information about the capabilities of this interface.


StringName get_name ( ) const

Returns the name of this interface (OpenXR, OpenVR, OpenHMD, ARKit, etc).


PackedVector3Array get_play_area ( ) const

Returns an array of vectors that denotes the physical play area mapped to the virtual space around the XROrigin3D point. The points form a convex polygon that can be used to react to or visualize the play area. This returns an empty array if this feature is not supported or if the information is not yet available.


Projection get_projection_for_view ( int view, float aspect, float near, float far )

Returns the projection matrix for a view/eye.


Vector2 get_render_target_size ( )

Returns the resolution at which we should render our intermediate results before things like lens distortion are applied by the VR platform.


Array get_supported_environment_blend_modes ( )

Returns the an array of supported environment blend modes, see EnvironmentBlendMode.


Dictionary get_system_info ( )

Returns a Dictionary with extra system info. Interfaces are expected to return