diff options
Diffstat (limited to 'servers/arvr')
-rw-r--r-- | servers/arvr/arvr_interface.cpp | 68 | ||||
-rw-r--r-- | servers/arvr/arvr_interface.h | 51 | ||||
-rw-r--r-- | servers/arvr/arvr_script_interface.cpp | 127 | ||||
-rw-r--r-- | servers/arvr/arvr_script_interface.h | 47 |
4 files changed, 101 insertions, 192 deletions
diff --git a/servers/arvr/arvr_interface.cpp b/servers/arvr/arvr_interface.cpp index 0705df17b1..55707def7c 100644 --- a/servers/arvr/arvr_interface.cpp +++ b/servers/arvr/arvr_interface.cpp @@ -31,29 +31,49 @@ void ARVRInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("get_name"), &ARVRInterface::get_name); + ClassDB::bind_method(D_METHOD("get_capabilities"), &ARVRInterface::get_capabilities); ClassDB::bind_method(D_METHOD("is_primary"), &ARVRInterface::is_primary); ClassDB::bind_method(D_METHOD("set_is_primary", "enable"), &ARVRInterface::set_is_primary); - ClassDB::bind_method(D_METHOD("is_installed"), &ARVRInterface::is_installed); - ClassDB::bind_method(D_METHOD("hmd_is_present"), &ARVRInterface::hmd_is_present); - ClassDB::bind_method(D_METHOD("supports_hmd"), &ARVRInterface::supports_hmd); ClassDB::bind_method(D_METHOD("is_initialized"), &ARVRInterface::is_initialized); + ClassDB::bind_method(D_METHOD("set_is_initialized", "initialized"), &ARVRInterface::set_is_initialized); ClassDB::bind_method(D_METHOD("initialize"), &ARVRInterface::initialize); ClassDB::bind_method(D_METHOD("uninitialize"), &ARVRInterface::uninitialize); + ClassDB::bind_method(D_METHOD("get_tracking_status"), &ARVRInterface::get_tracking_status); + ClassDB::bind_method(D_METHOD("get_recommended_render_targetsize"), &ARVRInterface::get_recommended_render_targetsize); + ClassDB::bind_method(D_METHOD("is_stereo"), &ARVRInterface::is_stereo); + + ADD_GROUP("Interface", "interface_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_primary"), "set_is_primary", "is_primary"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_initialized"), "set_is_initialized", "is_initialized"); + + // we don't have any properties specific to VR yet.... - // These are now purely used internally, we may expose them again if we expose CameraMatrix through Variant but reduz is not a fan for good reasons :) - // ClassDB::bind_method(D_METHOD("get_transform_for_eye", "eye", "cam_transform"), &ARVRInterface::get_transform_for_eye); - // ClassDB::bind_method(D_METHOD("get_projection_for_eye", "eye"), &ARVRInterface::get_projection_for_eye); - // ClassDB::bind_method(D_METHOD("commit_for_eye", "node:viewport"), &ARVRInterface::commit_for_eye); + // but we do have properties specific to AR.... + ClassDB::bind_method(D_METHOD("get_anchor_detection_is_enabled"), &ARVRInterface::get_anchor_detection_is_enabled); + ClassDB::bind_method(D_METHOD("set_anchor_detection_is_enabled", "enable"), &ARVRInterface::set_anchor_detection_is_enabled); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "primary"), "set_is_primary", "is_primary"); + ADD_GROUP("AR", "ar_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ar_is_anchor_detection_enabled"), "set_anchor_detection_is_enabled", "get_anchor_detection_is_enabled"); + + BIND_ENUM_CONSTANT(ARVR_NONE); + BIND_ENUM_CONSTANT(ARVR_MONO); + BIND_ENUM_CONSTANT(ARVR_STEREO); + BIND_ENUM_CONSTANT(ARVR_AR); + BIND_ENUM_CONSTANT(ARVR_EXTERNAL); BIND_ENUM_CONSTANT(EYE_MONO); BIND_ENUM_CONSTANT(EYE_LEFT); BIND_ENUM_CONSTANT(EYE_RIGHT); + + BIND_ENUM_CONSTANT(ARVR_NORMAL_TRACKING); + BIND_ENUM_CONSTANT(ARVR_EXCESSIVE_MOTION); + BIND_ENUM_CONSTANT(ARVR_INSUFFICIENT_FEATURES); + BIND_ENUM_CONSTANT(ARVR_UNKNOWN_TRACKING); + BIND_ENUM_CONSTANT(ARVR_NOT_TRACKING); }; StringName ARVRInterface::get_name() const { @@ -73,10 +93,40 @@ void ARVRInterface::set_is_primary(bool p_is_primary) { if (p_is_primary) { ERR_FAIL_COND(!is_initialized()); - ERR_FAIL_COND(!supports_hmd()); arvr_server->set_primary_interface(this); } else { arvr_server->clear_primary_interface_if(this); }; }; + +void ARVRInterface::set_is_initialized(bool p_initialized) { + if (p_initialized) { + if (!is_initialized()) { + initialize(); + }; + } else { + if (is_initialized()) { + uninitialize(); + }; + }; +}; + +ARVRInterface::Tracking_status ARVRInterface::get_tracking_status() const { + return tracking_state; +}; + +ARVRInterface::ARVRInterface() { + tracking_state = ARVR_UNKNOWN_TRACKING; +}; + +ARVRInterface::~ARVRInterface(){}; + +/** these will only be implemented on AR interfaces, so we want dummies for VR **/ +bool ARVRInterface::get_anchor_detection_is_enabled() const { + return false; +}; + +void ARVRInterface::set_anchor_detection_is_enabled(bool p_enable){ + // don't do anything here, this needs to be implemented on AR interface to enable/disable things like plane detection etc. +}; diff --git a/servers/arvr/arvr_interface.h b/servers/arvr/arvr_interface.h index d4fb383bbc..880f6e4595 100644 --- a/servers/arvr/arvr_interface.h +++ b/servers/arvr/arvr_interface.h @@ -50,31 +50,59 @@ class ARVRInterface : public Reference { GDCLASS(ARVRInterface, Reference); -protected: - _THREAD_SAFE_CLASS_ - - static void _bind_methods(); - public: + enum Capabilities { /* purely meta data, provides some info about what this interface supports */ + ARVR_NONE = 0, /* no capabilities */ + ARVR_MONO = 1, /* can be used with mono output */ + ARVR_STEREO = 2, /* can be used with stereo output */ + ARVR_AR = 4, /* offers a camera feed for AR */ + ARVR_EXTERNAL = 8 /* renders to external device */ + }; + enum Eyes { EYE_MONO, /* my son says we should call this EYE_CYCLOPS */ EYE_LEFT, EYE_RIGHT }; + enum Tracking_status { /* tracking status currently based on AR but we can start doing more with this for VR as well */ + ARVR_NORMAL_TRACKING, + ARVR_EXCESSIVE_MOTION, + ARVR_INSUFFICIENT_FEATURES, + ARVR_UNKNOWN_TRACKING, + ARVR_NOT_TRACKING + }; + +protected: + _THREAD_SAFE_CLASS_ + + Tracking_status tracking_state; + static void _bind_methods(); + +public: + /** general interface information **/ virtual StringName get_name() const; + virtual int get_capabilities() const = 0; bool is_primary(); void set_is_primary(bool p_is_primary); - virtual bool is_installed() = 0; /* returns true if the middle ware related to this interface has been installed */ - virtual bool hmd_is_present() = 0; /* returns true if our HMD is connected */ - virtual bool supports_hmd() = 0; /* returns true is this interface handles output to an HMD or only handles positioning */ - virtual bool is_initialized() = 0; /* returns true if we've initialized this interface */ + void set_is_initialized(bool p_initialized); /* helper function, will call initialize or uninitialize */ virtual bool initialize() = 0; /* initialize this interface, if this has an HMD it becomes the primary interface */ virtual void uninitialize() = 0; /* deinitialize this interface */ + Tracking_status get_tracking_status() const; /* get the status of our current tracking */ + + /** specific to VR **/ + // nothing yet + + /** specific to AR **/ + virtual bool get_anchor_detection_is_enabled() const; + virtual void set_anchor_detection_is_enabled(bool p_enable); + + /** rendering and internal **/ + virtual Size2 get_recommended_render_targetsize() = 0; /* returns the recommended render target size per eye for this device */ virtual bool is_stereo() = 0; /* returns true if this interface requires stereo rendering (for VR HMDs) or mono rendering (for mobile AR) */ virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform) = 0; /* get each eyes camera transform, also implement EYE_MONO */ @@ -82,8 +110,13 @@ public: virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) = 0; /* output the left or right eye */ virtual void process() = 0; + + ARVRInterface(); + ~ARVRInterface(); }; +VARIANT_ENUM_CAST(ARVRInterface::Capabilities); VARIANT_ENUM_CAST(ARVRInterface::Eyes); +VARIANT_ENUM_CAST(ARVRInterface::Tracking_status); #endif diff --git a/servers/arvr/arvr_script_interface.cpp b/servers/arvr/arvr_script_interface.cpp deleted file mode 100644 index 16e607920e..0000000000 --- a/servers/arvr/arvr_script_interface.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include "arvr_script_interface.h" - -ARVRScriptInterface::ARVRScriptInterface() { - // testing - printf("Construct script interface"); -} - -ARVRScriptInterface::~ARVRScriptInterface() { - if (is_initialized()) { - uninitialize(); - }; - - // testing - printf("Destruct script interface"); -} - -StringName ARVRScriptInterface::get_name() const { - if (get_script_instance() && get_script_instance()->has_method("get_name")) { - return get_script_instance()->call("get_name"); - } else { - // just return something for now - return "ARVR Script interface"; - } -} - -bool ARVRScriptInterface::is_installed() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("is_installed")), false); - return get_script_instance()->call("is_installed"); -} - -bool ARVRScriptInterface::hmd_is_present() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("hmd_is_present")), false); - return get_script_instance()->call("hmd_is_present"); -} - -bool ARVRScriptInterface::supports_hmd() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("supports_hmd")), false); - return get_script_instance()->call("supports_hmd"); -} - -bool ARVRScriptInterface::is_stereo() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("is_stereo")), false); - return get_script_instance()->call("is_stereo"); -} - -bool ARVRScriptInterface::is_initialized() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("is_initialized")), false); - return get_script_instance()->call("is_initialized"); -} - -bool ARVRScriptInterface::initialize() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("initialize")), false); - return get_script_instance()->call("initialize"); -} - -void ARVRScriptInterface::uninitialize() { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - if (arvr_server != NULL) { - // Whatever happens, make sure this is no longer our primary interface - arvr_server->clear_primary_interface_if(this); - } - - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("uninitialize"))); - get_script_instance()->call("uninitialize"); -} - -Size2 ARVRScriptInterface::get_recommended_render_targetsize() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_recommended_render_targetsize")), Size2()); - return get_script_instance()->call("get_recommended_render_targetsize"); -} - -Transform ARVRScriptInterface::get_transform_for_eye(Eyes p_eye, const Transform &p_cam_transform) { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_transform_for_eye")), Transform()); - return get_script_instance()->call("get_transform_for_eye", p_eye, p_cam_transform); -} - -// Suggestion from Reduz, as we can't return a CameraMatrix, return a PoolVector with our 16 floats -PoolVector<float> ARVRScriptInterface::_get_projection_for_eye(Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_projection_for_eye")), PoolVector<float>()); - return get_script_instance()->call("_get_projection_for_eye", p_eye, p_aspect, p_z_near, p_z_far); -} - -CameraMatrix ARVRScriptInterface::get_projection_for_eye(Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { - CameraMatrix cm; - int i = 0; - int j = 0; - - PoolVector<float> cm_as_floats = _get_projection_for_eye(p_eye, p_aspect, p_z_near, p_z_far); - - for (int k = 0; k < cm_as_floats.size() && i < 4; k++) { - cm.matrix[i][j] = cm_as_floats[k]; - j++; - if (j == 4) { - j = 0; - i++; - }; - }; - - return cm; -} - -void ARVRScriptInterface::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("commit_for_eye"))); - get_script_instance()->call("commit_for_eye"); -} - -void ARVRScriptInterface::process() { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("process"))); - get_script_instance()->call("process"); -} - -void ARVRScriptInterface::_bind_methods() { - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "is_installed")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "hmd_is_present")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "supports_hmd")); - - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "is_initialized")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "initialize")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("uninitialize")); - - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "is_stereo")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::VECTOR2, "get_recommended_render_targetsize")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::TRANSFORM, "get_transform_for_eye", PropertyInfo(Variant::INT, "eye"), PropertyInfo(Variant::TRANSFORM, "cam_transform"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("_get_projection_for_eye")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("commit_for_eye", PropertyInfo(Variant::INT, "eye"), PropertyInfo(Variant::_RID, "render_target"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("process")); -} diff --git a/servers/arvr/arvr_script_interface.h b/servers/arvr/arvr_script_interface.h deleted file mode 100644 index 04ca33901a..0000000000 --- a/servers/arvr/arvr_script_interface.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef SCRIPT_INTERFACE_H -#define SCRIPT_INTERFACE_H - -#include "arvr_interface.h" - -/** - @authors Hinsbart & Karroffel - - This subclass of our AR/VR interface forms a bridge to GDNative. -*/ - -class ARVRScriptInterface : public ARVRInterface { - GDCLASS(ARVRScriptInterface, ARVRInterface); - -protected: - static void _bind_methods(); - -public: - ARVRScriptInterface(); - ~ARVRScriptInterface(); - - virtual StringName get_name() const; - - virtual bool is_installed(); - virtual bool hmd_is_present(); - virtual bool supports_hmd(); - - virtual bool is_initialized(); - virtual bool initialize(); - virtual void uninitialize(); - - virtual Size2 get_recommended_render_targetsize(); - virtual bool is_stereo(); - virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform); - - // we expose a PoolVector<float> version of this function to GDNative - PoolVector<float> _get_projection_for_eye(Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); - - // and a CameraMatrix version to ARVRServer - virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); - - virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect); - - virtual void process(); -}; - -#endif // SCRIPT_INTERFACE_H |