Class XRServerInstance
- Namespace
- Godot
- Assembly
- GodotSharp.dll
The AR/VR server is the heart of our Advanced and Virtual Reality solution and handles all the processing.
[GodotClassName("XRServer")]
public class XRServerInstance : GodotObject, IDisposable
- Inheritance
-
XRServerInstance
- Implements
- Inherited Members
Properties
PrimaryInterface
The primary XRInterface currently bound to the XRServer.
public XRInterface PrimaryInterface { get; set; }
Property Value
WorldOrigin
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.
public Transform3D WorldOrigin { get; set; }
Property Value
WorldScale
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.
public double WorldScale { get; set; }
Property Value
Methods
AddInterface(XRInterface)
Registers an XRInterface object.
public void AddInterface(XRInterface @interface)
Parameters
interface
XRInterface
AddTracker(XRPositionalTracker)
Registers a new XRPositionalTracker that tracks a spatial location in real space.
public void AddTracker(XRPositionalTracker tracker)
Parameters
tracker
XRPositionalTracker
CenterOnHmd(RotationMode, 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.
public void CenterOnHmd(XRServer.RotationMode rotationMode, bool keepHeight)
Parameters
rotationMode
XRServer.RotationModekeepHeight
bool
FindInterface(string)
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.
public XRInterface FindInterface(string name)
Parameters
name
string
Returns
GetHmdTransform()
Returns the primary interface's transformation.
public Transform3D GetHmdTransform()
Returns
GetInterface(int)
Returns the interface registered at the given idx
index in the list of interfaces.
public XRInterface GetInterface(int idx)
Parameters
idx
int
Returns
GetInterfaceCount()
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
.
public int GetInterfaceCount()
Returns
GetInterfaces()
Returns a list of available interfaces the ID and name of each interface.
public Array<Dictionary> GetInterfaces()
Returns
GetReferenceFrame()
Returns the reference frame transform. Mostly used internally and exposed for GDExtension build interfaces.
public Transform3D GetReferenceFrame()
Returns
GetTracker(StringName)
Returns the positional tracker with the given trackerName
.
public XRPositionalTracker GetTracker(StringName trackerName)
Parameters
trackerName
StringName
Returns
GetTrackers(int)
Returns a dictionary of trackers for trackerTypes
.
public Dictionary GetTrackers(int trackerTypes)
Parameters
trackerTypes
int
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
RemoveInterface(XRInterface)
Removes this interface
.
public void RemoveInterface(XRInterface @interface)
Parameters
interface
XRInterface
RemoveTracker(XRPositionalTracker)
Removes this positional tracker
.
public void RemoveTracker(XRPositionalTracker tracker)
Parameters
tracker
XRPositionalTracker
Events
InterfaceAdded
Emitted when a new interface has been added.
public event XRServerInstance.InterfaceAddedEventHandler InterfaceAdded
Event Type
InterfaceRemoved
Emitted when an interface is removed.
public event XRServerInstance.InterfaceRemovedEventHandler InterfaceRemoved
Event Type
TrackerAdded
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.
public event XRServerInstance.TrackerAddedEventHandler TrackerAdded
Event Type
TrackerRemoved
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).
public event XRServerInstance.TrackerRemovedEventHandler TrackerRemoved
Event Type
TrackerUpdated
Emitted when an existing tracker has been updated. This can happen if the user switches controllers.
public event XRServerInstance.TrackerUpdatedEventHandler TrackerUpdated