XRServer

package
v0.0.0-...-357ca8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddInterface

func AddInterface(intf XRInterface.Instance)

Registers an XRInterface object.

func AddTracker

func AddTracker(tracker XRTracker.Instance)

Registers a new XRTracker that tracks a physical object.

func Advanced

func Advanced() class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

func CameraLockedToOrigin

func CameraLockedToOrigin() bool

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.

func CenterOnHmd

func CenterOnHmd(rotation_mode RotationMode, keep_height 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.

func ClearReferenceFrame

func ClearReferenceFrame()

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

func FindInterface

func FindInterface(name string) XRInterface.Instance

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.

func GetHmdTransform

func GetHmdTransform() Transform3D.BasisOrigin

Returns the primary interface's transformation.

func GetInterface

func GetInterface(idx int) XRInterface.Instance

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

func GetInterfaceCount

func GetInterfaceCount() int

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.

func GetInterfaces

func GetInterfaces() []map[int]string

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

func GetReferenceFrame

func GetReferenceFrame() Transform3D.BasisOrigin

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

func GetTracker

func GetTracker(tracker_name string) XRTracker.Instance

Returns the positional tracker with the given 'tracker_name'.

func GetTrackers

func GetTrackers(tracker_types int) map[interface{}]interface{}

Returns a dictionary of trackers for 'tracker_types'.

func OnInterfaceAdded

func OnInterfaceAdded(cb func(interface_name string), flags ...Signal.Flags)

Emitted when a new interface has been added.

func OnInterfaceRemoved

func OnInterfaceRemoved(cb func(interface_name string), flags ...Signal.Flags)

Emitted when an interface is removed.

func OnReferenceFrameChanged

func OnReferenceFrameChanged(cb func(), flags ...Signal.Flags)

Emitted when the reference frame transform changes.

func OnTrackerAdded

func OnTrackerAdded(cb func(tracker_name string, atype int), flags ...Signal.Flags)

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.

func OnTrackerRemoved

func OnTrackerRemoved(cb func(tracker_name string, atype int), flags ...Signal.Flags)

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).

func OnTrackerUpdated

func OnTrackerUpdated(cb func(tracker_name string, atype int), flags ...Signal.Flags)

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

func PrimaryInterface

func PrimaryInterface() XRInterface.Instance

The primary XRInterface currently bound to the XRServer.

func RemoveInterface

func RemoveInterface(intf XRInterface.Instance)

Removes this 'interface'.

func RemoveTracker

func RemoveTracker(tracker XRTracker.Instance)

Removes this 'tracker'.

func SetCameraLockedToOrigin

func SetCameraLockedToOrigin(value bool)

SetCameraLockedToOrigin sets the property returned by [IsCameraLockedToOrigin].

func SetPrimaryInterface

func SetPrimaryInterface(value XRInterface.Instance)

SetPrimaryInterface sets the property returned by [GetPrimaryInterface].

func SetWorldOrigin

func SetWorldOrigin(value Transform3D.BasisOrigin)

SetWorldOrigin sets the property returned by [GetWorldOrigin].

func SetWorldScale

func SetWorldScale(value Float.X)

SetWorldScale sets the property returned by [GetWorldScale].

func WorldOrigin

func WorldOrigin() Transform3D.BasisOrigin

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.

func WorldScale

func WorldScale() Float.X

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.

Types

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.XRServer

Instance of the class with convieniently typed arguments and results.

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type RotationMode

type RotationMode int //gd:XRServer.RotationMode
const (
	// Fully reset the orientation of the HMD. Regardless of what direction the user is looking to in the real world. The user will look dead ahead in the virtual world.
	ResetFullRotation RotationMode = 0
	// Resets the orientation but keeps the tilt of the device. So if we're looking down, we keep looking down but heading will be reset.
	ResetButKeepTilt RotationMode = 1
	// Does not reset the orientation of the HMD, only the position of the player gets centered.
	DontResetRotation RotationMode = 2
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL