Merge pull request #25630 from BastiaanOlij/arvr_positional_mesh
Added a mesh interface to the arvr positional trackers
This commit is contained in:
commit
35f06eb437
7 changed files with 90 additions and 4 deletions
|
@ -27,6 +27,13 @@
|
||||||
Returns true if the anchor is being tracked and false if no anchor with this id is currently known.
|
Returns true if the anchor is being tracked and false if no anchor with this id is currently known.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="get_mesh" qualifiers="const">
|
||||||
|
<return type="Mesh">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
If provided by the ARVR Interface this returns a mesh object for the anchor. For an anchor this can be a shape related to the object being tracked or it can be a mesh that provides topology related to the anchor and can be used to create shadows/reflections on surfaces or for generating collision shapes.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="get_plane" qualifiers="const">
|
<method name="get_plane" qualifiers="const">
|
||||||
<return type="Plane">
|
<return type="Plane">
|
||||||
</return>
|
</return>
|
||||||
|
@ -47,6 +54,15 @@
|
||||||
The anchor's id. You can set this before the anchor itself exists. The first anchor gets an id of [code]1[/code], the second an id of [code]2[/code], etc. When anchors get removed, the engine can then assign the corresponding id to new anchors. The most common situation where anchors 'disappear' is when the AR server identifies that two anchors represent different parts of the same plane and merges them.
|
The anchor's id. You can set this before the anchor itself exists. The first anchor gets an id of [code]1[/code], the second an id of [code]2[/code], etc. When anchors get removed, the engine can then assign the corresponding id to new anchors. The most common situation where anchors 'disappear' is when the AR server identifies that two anchors represent different parts of the same plane and merges them.
|
||||||
</member>
|
</member>
|
||||||
</members>
|
</members>
|
||||||
|
<signals>
|
||||||
|
<signal name="mesh_updated">
|
||||||
|
<argument index="0" name="mesh" type="Mesh">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Emitted when the mesh associated with the anchor changes or when one becomes available. This is especially important for topology that is constantly being mesh_updated.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
</signals>
|
||||||
<constants>
|
<constants>
|
||||||
</constants>
|
</constants>
|
||||||
</class>
|
</class>
|
||||||
|
|
|
@ -50,6 +50,13 @@
|
||||||
Returns the ID of the joystick object bound to this. Every controller tracked by the ARVR Server that has buttons and axis will also be registered as a joystick within Godot. This means that all the normal joystick tracking and input mapping will work for buttons and axis found on the AR/VR controllers. This ID is purely offered as information so you can link up the controller with its joystick entry.
|
Returns the ID of the joystick object bound to this. Every controller tracked by the ARVR Server that has buttons and axis will also be registered as a joystick within Godot. This means that all the normal joystick tracking and input mapping will work for buttons and axis found on the AR/VR controllers. This ID is purely offered as information so you can link up the controller with its joystick entry.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="get_mesh" qualifiers="const">
|
||||||
|
<return type="Mesh">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
If provided by the ARVR Interface this returns a mesh associated with the controller. This can be used to visualise the controller.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="is_button_pressed" qualifiers="const">
|
<method name="is_button_pressed" qualifiers="const">
|
||||||
<return type="int">
|
<return type="int">
|
||||||
</return>
|
</return>
|
||||||
|
@ -86,6 +93,13 @@
|
||||||
Emitted when a button on this controller is released.
|
Emitted when a button on this controller is released.
|
||||||
</description>
|
</description>
|
||||||
</signal>
|
</signal>
|
||||||
|
<signal name="mesh_updated">
|
||||||
|
<argument index="0" name="mesh" type="Mesh">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
Emitted when the mesh associated with the controller changes or when one becomes available. Generally speaking this will be a static mesh after becoming available.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
</signals>
|
</signals>
|
||||||
<constants>
|
<constants>
|
||||||
</constants>
|
</constants>
|
||||||
|
|
|
@ -27,6 +27,13 @@
|
||||||
If this is a controller that is being tracked the controller will also be represented by a joystick entry with this id.
|
If this is a controller that is being tracked the controller will also be represented by a joystick entry with this id.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="get_mesh" qualifiers="const">
|
||||||
|
<return type="Mesh">
|
||||||
|
</return>
|
||||||
|
<description>
|
||||||
|
Returns the mesh related to a controller or anchor point if one is available.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="get_name" qualifiers="const">
|
<method name="get_name" qualifiers="const">
|
||||||
<return type="String">
|
<return type="String">
|
||||||
</return>
|
</return>
|
||||||
|
|
|
@ -233,6 +233,13 @@ void ARVRController::_notification(int p_what) {
|
||||||
} else {
|
} else {
|
||||||
button_states = 0;
|
button_states = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// check for an updated mesh
|
||||||
|
Ref<Mesh> trackerMesh = tracker->get_mesh();
|
||||||
|
if (mesh != trackerMesh) {
|
||||||
|
mesh = trackerMesh;
|
||||||
|
emit_signal("mesh_updated", mesh);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}; break;
|
}; break;
|
||||||
default:
|
default:
|
||||||
|
@ -258,8 +265,11 @@ void ARVRController::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &ARVRController::set_rumble);
|
ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &ARVRController::set_rumble);
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rumble", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_rumble", "get_rumble");
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "rumble", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_rumble", "get_rumble");
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_mesh"), &ARVRController::get_mesh);
|
||||||
|
|
||||||
ADD_SIGNAL(MethodInfo("button_pressed", PropertyInfo(Variant::INT, "button")));
|
ADD_SIGNAL(MethodInfo("button_pressed", PropertyInfo(Variant::INT, "button")));
|
||||||
ADD_SIGNAL(MethodInfo("button_release", PropertyInfo(Variant::INT, "button")));
|
ADD_SIGNAL(MethodInfo("button_release", PropertyInfo(Variant::INT, "button")));
|
||||||
|
ADD_SIGNAL(MethodInfo("mesh_updated", PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh")));
|
||||||
};
|
};
|
||||||
|
|
||||||
void ARVRController::set_controller_id(int p_controller_id) {
|
void ARVRController::set_controller_id(int p_controller_id) {
|
||||||
|
@ -341,6 +351,10 @@ void ARVRController::set_rumble(real_t p_rumble) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Ref<Mesh> ARVRController::get_mesh() const {
|
||||||
|
return mesh;
|
||||||
|
}
|
||||||
|
|
||||||
bool ARVRController::get_is_active() const {
|
bool ARVRController::get_is_active() const {
|
||||||
return is_active;
|
return is_active;
|
||||||
};
|
};
|
||||||
|
@ -423,6 +437,13 @@ void ARVRAnchor::_notification(int p_what) {
|
||||||
|
|
||||||
// apply our reference frame and set our transform
|
// apply our reference frame and set our transform
|
||||||
set_transform(arvr_server->get_reference_frame() * transform);
|
set_transform(arvr_server->get_reference_frame() * transform);
|
||||||
|
|
||||||
|
// check for an updated mesh
|
||||||
|
Ref<Mesh> trackerMesh = tracker->get_mesh();
|
||||||
|
if (mesh != trackerMesh) {
|
||||||
|
mesh = trackerMesh;
|
||||||
|
emit_signal("mesh_updated", mesh);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}; break;
|
}; break;
|
||||||
default:
|
default:
|
||||||
|
@ -441,6 +462,9 @@ void ARVRAnchor::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_size"), &ARVRAnchor::get_size);
|
ClassDB::bind_method(D_METHOD("get_size"), &ARVRAnchor::get_size);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_plane"), &ARVRAnchor::get_plane);
|
ClassDB::bind_method(D_METHOD("get_plane"), &ARVRAnchor::get_plane);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_mesh"), &ARVRAnchor::get_mesh);
|
||||||
|
ADD_SIGNAL(MethodInfo("mesh_updated", PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh")));
|
||||||
};
|
};
|
||||||
|
|
||||||
void ARVRAnchor::set_anchor_id(int p_anchor_id) {
|
void ARVRAnchor::set_anchor_id(int p_anchor_id) {
|
||||||
|
@ -501,6 +525,10 @@ Plane ARVRAnchor::get_plane() const {
|
||||||
return plane;
|
return plane;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Ref<Mesh> ARVRAnchor::get_mesh() const {
|
||||||
|
return mesh;
|
||||||
|
}
|
||||||
|
|
||||||
ARVRAnchor::ARVRAnchor() {
|
ARVRAnchor::ARVRAnchor() {
|
||||||
anchor_id = 0;
|
anchor_id = 0;
|
||||||
is_active = true;
|
is_active = true;
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include "scene/3d/camera.h"
|
#include "scene/3d/camera.h"
|
||||||
#include "scene/3d/spatial.h"
|
#include "scene/3d/spatial.h"
|
||||||
|
#include "scene/resources/mesh.h"
|
||||||
#include "servers/arvr/arvr_positional_tracker.h"
|
#include "servers/arvr/arvr_positional_tracker.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,6 +76,7 @@ private:
|
||||||
int controller_id;
|
int controller_id;
|
||||||
bool is_active;
|
bool is_active;
|
||||||
int button_states;
|
int button_states;
|
||||||
|
Ref<Mesh> mesh;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
@ -95,6 +97,8 @@ public:
|
||||||
bool get_is_active() const;
|
bool get_is_active() const;
|
||||||
ARVRPositionalTracker::TrackerHand get_hand() const;
|
ARVRPositionalTracker::TrackerHand get_hand() const;
|
||||||
|
|
||||||
|
Ref<Mesh> get_mesh(void) const;
|
||||||
|
|
||||||
String get_configuration_warning() const;
|
String get_configuration_warning() const;
|
||||||
|
|
||||||
ARVRController();
|
ARVRController();
|
||||||
|
@ -113,6 +117,7 @@ private:
|
||||||
int anchor_id;
|
int anchor_id;
|
||||||
bool is_active;
|
bool is_active;
|
||||||
Vector3 size;
|
Vector3 size;
|
||||||
|
Ref<Mesh> mesh;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
@ -128,6 +133,8 @@ public:
|
||||||
|
|
||||||
Plane get_plane() const;
|
Plane get_plane() const;
|
||||||
|
|
||||||
|
Ref<Mesh> get_mesh(void) const;
|
||||||
|
|
||||||
String get_configuration_warning() const;
|
String get_configuration_warning() const;
|
||||||
|
|
||||||
ARVRAnchor();
|
ARVRAnchor();
|
||||||
|
|
|
@ -46,6 +46,7 @@ void ARVRPositionalTracker::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_position"), &ARVRPositionalTracker::get_position);
|
ClassDB::bind_method(D_METHOD("get_position"), &ARVRPositionalTracker::get_position);
|
||||||
ClassDB::bind_method(D_METHOD("get_hand"), &ARVRPositionalTracker::get_hand);
|
ClassDB::bind_method(D_METHOD("get_hand"), &ARVRPositionalTracker::get_hand);
|
||||||
ClassDB::bind_method(D_METHOD("get_transform", "adjust_by_reference_frame"), &ARVRPositionalTracker::get_transform);
|
ClassDB::bind_method(D_METHOD("get_transform", "adjust_by_reference_frame"), &ARVRPositionalTracker::get_transform);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_mesh"), &ARVRPositionalTracker::get_mesh);
|
||||||
|
|
||||||
// these functions we don't want to expose to normal users but do need to be callable from GDNative
|
// these functions we don't want to expose to normal users but do need to be callable from GDNative
|
||||||
ClassDB::bind_method(D_METHOD("_set_type", "type"), &ARVRPositionalTracker::set_type);
|
ClassDB::bind_method(D_METHOD("_set_type", "type"), &ARVRPositionalTracker::set_type);
|
||||||
|
@ -53,7 +54,7 @@ void ARVRPositionalTracker::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("_set_joy_id", "joy_id"), &ARVRPositionalTracker::set_joy_id);
|
ClassDB::bind_method(D_METHOD("_set_joy_id", "joy_id"), &ARVRPositionalTracker::set_joy_id);
|
||||||
ClassDB::bind_method(D_METHOD("_set_orientation", "orientation"), &ARVRPositionalTracker::set_orientation);
|
ClassDB::bind_method(D_METHOD("_set_orientation", "orientation"), &ARVRPositionalTracker::set_orientation);
|
||||||
ClassDB::bind_method(D_METHOD("_set_rw_position", "rw_position"), &ARVRPositionalTracker::set_rw_position);
|
ClassDB::bind_method(D_METHOD("_set_rw_position", "rw_position"), &ARVRPositionalTracker::set_rw_position);
|
||||||
|
ClassDB::bind_method(D_METHOD("_set_mesh", "mesh"), &ARVRPositionalTracker::set_mesh);
|
||||||
ClassDB::bind_method(D_METHOD("get_rumble"), &ARVRPositionalTracker::get_rumble);
|
ClassDB::bind_method(D_METHOD("get_rumble"), &ARVRPositionalTracker::get_rumble);
|
||||||
ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &ARVRPositionalTracker::set_rumble);
|
ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &ARVRPositionalTracker::set_rumble);
|
||||||
|
|
||||||
|
@ -154,6 +155,18 @@ Vector3 ARVRPositionalTracker::get_rw_position() const {
|
||||||
return rw_position;
|
return rw_position;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void ARVRPositionalTracker::set_mesh(const Ref<Mesh> &p_mesh) {
|
||||||
|
_THREAD_SAFE_METHOD_
|
||||||
|
|
||||||
|
mesh = p_mesh;
|
||||||
|
};
|
||||||
|
|
||||||
|
Ref<Mesh> ARVRPositionalTracker::get_mesh() const {
|
||||||
|
_THREAD_SAFE_METHOD_
|
||||||
|
|
||||||
|
return mesh;
|
||||||
|
};
|
||||||
|
|
||||||
ARVRPositionalTracker::TrackerHand ARVRPositionalTracker::get_hand() const {
|
ARVRPositionalTracker::TrackerHand ARVRPositionalTracker::get_hand() const {
|
||||||
return hand;
|
return hand;
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#define ARVR_POSITIONAL_TRACKER_H
|
#define ARVR_POSITIONAL_TRACKER_H
|
||||||
|
|
||||||
#include "core/os/thread_safe.h"
|
#include "core/os/thread_safe.h"
|
||||||
|
#include "scene/resources/mesh.h"
|
||||||
#include "servers/arvr_server.h"
|
#include "servers/arvr_server.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,9 +41,6 @@
|
||||||
The positional tracker object as an object that represents the position and orientation of a tracked object like a controller or headset.
|
The positional tracker object as an object that represents the position and orientation of a tracked object like a controller or headset.
|
||||||
An AR/VR Interface will registered the trackers it manages with our AR/VR server and update its position and orientation.
|
An AR/VR Interface will registered the trackers it manages with our AR/VR server and update its position and orientation.
|
||||||
This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking.
|
This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking.
|
||||||
|
|
||||||
@TODO:
|
|
||||||
- create subclass of spatial node that uses one of our positional trackers to automatically determine its position
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ARVRPositionalTracker : public Object {
|
class ARVRPositionalTracker : public Object {
|
||||||
|
@ -65,6 +63,7 @@ private:
|
||||||
Basis orientation; // our orientation
|
Basis orientation; // our orientation
|
||||||
bool tracks_position; // do we track position?
|
bool tracks_position; // do we track position?
|
||||||
Vector3 rw_position; // our position "in the real world, so without world_scale applied"
|
Vector3 rw_position; // our position "in the real world, so without world_scale applied"
|
||||||
|
Ref<Mesh> mesh; // when available, a mesh that can be used to render this tracker
|
||||||
TrackerHand hand; // if known, the hand this tracker is held in
|
TrackerHand hand; // if known, the hand this tracker is held in
|
||||||
real_t rumble; // rumble strength, 0.0 is off, 1.0 is maximum, note that we only record here, arvr_interface is responsible for execution
|
real_t rumble; // rumble strength, 0.0 is off, 1.0 is maximum, note that we only record here, arvr_interface is responsible for execution
|
||||||
|
|
||||||
|
@ -91,6 +90,8 @@ public:
|
||||||
void set_hand(const ARVRPositionalTracker::TrackerHand p_hand);
|
void set_hand(const ARVRPositionalTracker::TrackerHand p_hand);
|
||||||
real_t get_rumble() const;
|
real_t get_rumble() const;
|
||||||
void set_rumble(real_t p_rumble);
|
void set_rumble(real_t p_rumble);
|
||||||
|
void set_mesh(const Ref<Mesh> &p_mesh);
|
||||||
|
Ref<Mesh> get_mesh() const;
|
||||||
|
|
||||||
Transform get_transform(bool p_adjust_by_reference_frame) const;
|
Transform get_transform(bool p_adjust_by_reference_frame) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue