Table of Contents

Class XRServer

Server for AR and VR features.

Inheritance
XRServer

Remarks

The AR/VR server is the heart of our Advanced and Virtual Reality solution and handles all the processing.

See Also

Properties

camera_locked_to_origin

If set to true, the scene will be rendered as if the camera is locked to the XROrigin3D.

Note: This doesn't provide a very comfortable experience for users. This setting exists for doing benchmarking or automated testing, where you want to control what is rendered via code.

var camera_locked_to_origin : bool = false

Property Value

bool

Remarks

  • void set_camera_locked_to_origin(bool value)
  • bool is_camera_locked_to_origin

primary_interface

The primary XRInterface currently bound to the XRServer.

var primary_interface : XRInterface

Property Value

XRInterface

Remarks

world_origin

The current origin of our tracking space in the virtual world. This is used by the renderer to properly position the camera with new tracking data.

Note: This property is managed by the current XROrigin3D node. It is exposed for access from GDExtensions.

var world_origin : Transform3D = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)

Property Value

Transform3D

Remarks

world_scale

The scale of the game world compared to the real world. By default, most AR/VR platforms assume that 1 game unit corresponds to 1 real world meter.

var world_scale : float = 1.0

Property Value

float

Remarks

  • void set_world_scale(float value)
  • float get_world_scale

Methods

add_interface(XRInterface)

Registers an XRInterface object.

void add_interface(XRInterface interface)

Parameters

interface XRInterface

add_tracker(XRTracker)

Registers a new XRTracker that tracks a physical object.

void add_tracker(XRTracker tracker)

Parameters

tracker XRTracker

center_on_hmd(int, bool)

This is an important function to understand correctly. AR and VR platforms all handle positioning slightly differently.

For platforms that do not offer spatial tracking, our origin point (0, 0, 0) is the location of our HMD, but you have little control over the direction the player is facing in the real world.

For platforms that do offer spatial tracking, our origin point depends very much on the system. For OpenVR, our origin point is usually the center of the tracking space, on the ground. For other platforms, it's often the location of the tracking camera.

This method allows you to center your tracker on the location of the HMD. It will take the current location of the HMD and use that to adjust all your tracking data; in essence, realigning the real world to your player's current position in the game world.

For this method to produce usable results, tracking information must be available. This often takes a few frames after starting your game.

You should call this method after a few seconds have passed. For example, when the user requests a realignment of the display holding a designated button on a controller for a short period of time, or when implementing a teleport mechanism.

void center_on_hmd(int rotation_mode, bool keep_height)

Parameters

rotation_mode int
keep_height bool

clear_reference_frame

Clears the reference frame that was set by previous calls to XRServer.center_on_hmd.

void clear_reference_frame

find_interface(String)

Qualifiers: const

Finds an interface by its name. For example, if your project uses capabilities of an AR/VR platform, you can find the interface for that platform by name and initialize it.

XRInterface find_interface(String name)

Parameters

name String

get_hmd_transform

Returns the primary interface's transformation.

Transform3D get_hmd_transform

get_interface(int)

Qualifiers: const

Returns the interface registered at the given idx index in the list of interfaces.

XRInterface get_interface(int idx)

Parameters

idx int

get_interface_count

Qualifiers: const

Returns the number of interfaces currently registered with the AR/VR server. If your project supports multiple AR/VR platforms, you can look through the available interface, and either present the user with a selection or simply try to initialize each interface and use the first one that returns true.

int get_interface_count

get_interfaces

Qualifiers: const

Returns a list of available interfaces the ID and name of each interface.

Dictionary[] get_interfaces

get_reference_frame

Qualifiers: const

Returns the reference frame transform. Mostly used internally and exposed for GDExtension build interfaces.

Transform3D get_reference_frame

get_tracker(StringName)

Qualifiers: const

Returns the positional tracker with the given tracker_name.

XRTracker get_tracker(StringName tracker_name)

Parameters

tracker_name StringName

get_trackers(int)

Returns a dictionary of trackers for tracker_types.

Dictionary get_trackers(int tracker_types)

Parameters

tracker_types int

remove_interface(XRInterface)

Removes this interface.

void remove_interface(XRInterface interface)

Parameters

interface XRInterface

remove_tracker(XRTracker)

Removes this tracker.

void remove_tracker(XRTracker tracker)

Parameters

tracker XRTracker

Events

interface_added(StringName)

Emitted when a new interface has been added.

signal interface_added(StringName interface_name)

Parameters

interface_name StringName

interface_removed(StringName)

Emitted when an interface is removed.

signal interface_removed(StringName interface_name)

Parameters

interface_name StringName

reference_frame_changed

Emitted when the reference frame transform changes.

signal reference_frame_changed

tracker_added(StringName, int)

Emitted when a new tracker has been added. If you don't use a fixed number of controllers or if you're using XRAnchor3Ds for an AR solution, it is important to react to this signal to add the appropriate XRController3D or XRAnchor3D nodes related to this new tracker.

signal tracker_added(StringName tracker_name, int type)

Parameters

tracker_name StringName
type int

tracker_removed(StringName, int)

Emitted when a tracker is removed. You should remove any XRController3D or XRAnchor3D points if applicable. This is not mandatory, the nodes simply become inactive and will be made active again when a new tracker becomes available (i.e. a new controller is switched on that takes the place of the previous one).

signal tracker_removed(StringName tracker_name, int type)

Parameters

tracker_name StringName
type int

tracker_updated(StringName, int)

Emitted when an existing tracker has been updated. This can happen if the user switches controllers.

signal tracker_updated(StringName tracker_name, int type)

Parameters

tracker_name StringName
type int