Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
XRServer
繼承: Object
用於 AR 和 VR 功能的服務。
說明
AR/VR 伺服器是我們“高級虛擬實境”解決方案的核心,負責執行所有處理。
教學
屬性
|
||
|
||
|
方法
void |
add_interface(interface: XRInterface) |
void |
add_tracker(tracker: XRTracker) |
void |
center_on_hmd(rotation_mode: RotationMode, keep_height: bool) |
void |
|
find_interface(name: String) const |
|
get_interface(idx: int) const |
|
get_interface_count() const |
|
get_interfaces() const |
|
get_reference_frame() const |
|
get_tracker(tracker_name: StringName) const |
|
get_trackers(tracker_types: int) |
|
void |
remove_interface(interface: XRInterface) |
void |
remove_tracker(tracker: XRTracker) |
訊號
interface_added(interface_name: StringName) 🔗
新增新介面時觸發。
interface_removed(interface_name: StringName) 🔗
當介面被移除時觸發。
reference_frame_changed() 🔗
Emitted when the reference frame transform changes.
tracker_added(tracker_name: StringName, type: int) 🔗
當一個新的追蹤器被新增時發出。如果你不使用一個固定數量的控制器,或者如果你將 XRAnchor3D 用於一個 AR 解決方案,請務必對此訊號做出反應,以新增與該新追蹤器相適的 XRController3D 或 XRAnchor3D 節點 。
tracker_removed(tracker_name: StringName, type: int) 🔗
當一個追蹤器被移除時發出。如此,你應該移除任何 XRController3D 或 XRAnchor3D 點。這不是強制性的,這些節點只是變得不活動,並且當一個新的追蹤器可用時,將再次啟動(即打開一個新的控制器,來代替前一個控制器)。
tracker_updated(tracker_name: StringName, type: int) 🔗
當現有追蹤器被更新時發出。如果使用者切換控制器,則可能會發生這種情況。
world_origin_changed() 🔗
Emitted when the world origin transform changes.
列舉
enum TrackerType: 🔗
TrackerType TRACKER_HEAD = 1
The tracker tracks the location of the player's head. This is usually a location centered between the player's eyes. Note that for handheld AR devices this can be the current location of the device.
TrackerType TRACKER_CONTROLLER = 2
追蹤器追蹤控制器的位置。
TrackerType TRACKER_BASESTATION = 4
追蹤器追蹤基站的位置。
TrackerType TRACKER_ANCHOR = 8
追蹤器追蹤 AR 錨的位置和大小。
TrackerType TRACKER_HAND = 16
The tracker tracks the location and joints of a hand.
TrackerType TRACKER_BODY = 32
The tracker tracks the location and joints of a body.
TrackerType TRACKER_FACE = 64
The tracker tracks the expressions of a face.
TrackerType TRACKER_ANY_KNOWN = 127
內部用於篩選任何已知型別的追蹤器。
TrackerType TRACKER_UNKNOWN = 128
如果我們尚未設定追蹤器型別,則在內部使用。
TrackerType TRACKER_ANY = 255
在內部用於選擇所有追蹤器。
enum RotationMode: 🔗
RotationMode RESET_FULL_ROTATION = 0
完全重設 HMD 的方向。無論使用者在現實世界中看向哪個方向。將在虛擬世界中鎖定視角。
RotationMode RESET_BUT_KEEP_TILT = 1
重設方向,但保持裝置的傾斜度。因此,如果我們正在往下看,會繼續往下看,但航向會被重設。
RotationMode DONT_RESET_ROTATION = 2
不重設 HMD 的方向,只讓玩家的位置居中。
屬性說明
bool camera_locked_to_origin = false 🔗
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.
XRInterface primary_interface 🔗
void set_primary_interface(value: XRInterface)
XRInterface get_primary_interface()
目前綁定到 XRServer 的主 XRInterface。
Transform3D world_origin = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0) 🔗
void set_world_origin(value: Transform3D)
Transform3D get_world_origin()
我們的追蹤空間在虛擬世界中的原點。算繪器會用到這個資訊,根據新的追蹤資料來正確放置相機。
注意:這個屬性由目前的 XROrigin3D 節點管理。暴露的目的是方便在 GDExtension 使用。
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.
方法說明
void add_interface(interface: XRInterface) 🔗
註冊一個 XRInterface 物件。
void add_tracker(tracker: XRTracker) 🔗
Registers a new XRTracker that tracks a physical object.
void center_on_hmd(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.
void clear_reference_frame() 🔗
Clears the reference frame that was set by previous calls to center_on_hmd().
XRInterface find_interface(name: String) const 🔗
通過名稱 name 搜尋介面。例如,如果你的專案使用 AR/VR 平臺的功能,你可以通過名稱找到該平臺的介面並初始化。
Transform3D get_hmd_transform() 🔗
返回主介面的變換。
XRInterface get_interface(idx: int) const 🔗
返回在介面列表中給定 idx 索引處註冊的介面。
int get_interface_count() const 🔗
返回目前在AR/VR服務上註冊的介面數量。如果你的專案支援多個AR/VR平臺,你可以查看可用的介面,並向使用者展示一個選擇,或者簡單地嘗試初始化每個介面,並使用第一個返回 true的介面。
Array[Dictionary] get_interfaces() const 🔗
返回可用介面的列表,每個介面的ID和名稱。
Transform3D get_reference_frame() const 🔗
返回引用影格的變換。主要在內部使用,並公開以用於 GDExtension 建構介面。
XRTracker get_tracker(tracker_name: StringName) const 🔗
返回具有給定 tracker_name 的位置追蹤器。
Dictionary get_trackers(tracker_types: int) 🔗
返回 tracker_types 的追蹤器字典。
void remove_interface(interface: XRInterface) 🔗
移除該 interface。
void remove_tracker(tracker: XRTracker) 🔗
Removes this tracker.