feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
Import("env_openxr")
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@
|
|||
#include "scene/3d/xr_nodes.h"
|
||||
#include "scene/main/viewport.h"
|
||||
|
||||
#include "platform/android/api/java_class_wrapper.h"
|
||||
|
||||
Vector<OpenXRCompositionLayer *> OpenXRCompositionLayer::composition_layer_nodes;
|
||||
|
||||
static const char *HOLE_PUNCH_SHADER_CODE =
|
||||
|
|
@ -47,10 +49,17 @@ static const char *HOLE_PUNCH_SHADER_CODE =
|
|||
"\tALBEDO = vec3(0.0, 0.0, 0.0);\n"
|
||||
"}\n";
|
||||
|
||||
OpenXRCompositionLayer::OpenXRCompositionLayer() {
|
||||
OpenXRCompositionLayer::OpenXRCompositionLayer(XrCompositionLayerBaseHeader *p_composition_layer) {
|
||||
composition_layer_base_header = p_composition_layer;
|
||||
openxr_layer_provider = memnew(OpenXRViewportCompositionLayerProvider(composition_layer_base_header));
|
||||
|
||||
openxr_api = OpenXRAPI::get_singleton();
|
||||
composition_layer_extension = OpenXRCompositionLayerExtension::get_singleton();
|
||||
|
||||
if (openxr_api) {
|
||||
openxr_session_running = openxr_api->is_running();
|
||||
}
|
||||
|
||||
Ref<OpenXRInterface> openxr_interface = XRServer::get_singleton()->find_interface("OpenXR");
|
||||
if (openxr_interface.is_valid()) {
|
||||
openxr_interface->connect("session_begun", callable_mp(this, &OpenXRCompositionLayer::_on_openxr_session_begun));
|
||||
|
|
@ -76,6 +85,7 @@ OpenXRCompositionLayer::~OpenXRCompositionLayer() {
|
|||
composition_layer_nodes.erase(this);
|
||||
|
||||
if (openxr_layer_provider != nullptr) {
|
||||
_clear_composition_layer_provider();
|
||||
memdelete(openxr_layer_provider);
|
||||
openxr_layer_provider = nullptr;
|
||||
}
|
||||
|
|
@ -85,6 +95,12 @@ void OpenXRCompositionLayer::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_layer_viewport", "viewport"), &OpenXRCompositionLayer::set_layer_viewport);
|
||||
ClassDB::bind_method(D_METHOD("get_layer_viewport"), &OpenXRCompositionLayer::get_layer_viewport);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_use_android_surface", "enable"), &OpenXRCompositionLayer::set_use_android_surface);
|
||||
ClassDB::bind_method(D_METHOD("get_use_android_surface"), &OpenXRCompositionLayer::get_use_android_surface);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_android_surface_size", "size"), &OpenXRCompositionLayer::set_android_surface_size);
|
||||
ClassDB::bind_method(D_METHOD("get_android_surface_size"), &OpenXRCompositionLayer::get_android_surface_size);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_enable_hole_punch", "enable"), &OpenXRCompositionLayer::set_enable_hole_punch);
|
||||
ClassDB::bind_method(D_METHOD("get_enable_hole_punch"), &OpenXRCompositionLayer::get_enable_hole_punch);
|
||||
|
||||
|
|
@ -94,11 +110,14 @@ void OpenXRCompositionLayer::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_alpha_blend", "enabled"), &OpenXRCompositionLayer::set_alpha_blend);
|
||||
ClassDB::bind_method(D_METHOD("get_alpha_blend"), &OpenXRCompositionLayer::get_alpha_blend);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_android_surface"), &OpenXRCompositionLayer::get_android_surface);
|
||||
ClassDB::bind_method(D_METHOD("is_natively_supported"), &OpenXRCompositionLayer::is_natively_supported);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("intersects_ray", "origin", "direction"), &OpenXRCompositionLayer::intersects_ray);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "layer_viewport", PROPERTY_HINT_NODE_TYPE, "SubViewport"), "set_layer_viewport", "get_layer_viewport");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_android_surface", PROPERTY_HINT_NONE, ""), "set_use_android_surface", "get_use_android_surface");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "android_surface_size", PROPERTY_HINT_NONE, ""), "set_android_surface_size", "get_android_surface_size");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "sort_order", PROPERTY_HINT_NONE, ""), "set_sort_order", "get_sort_order");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alpha_blend", PROPERTY_HINT_NONE, ""), "set_alpha_blend", "get_alpha_blend");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enable_hole_punch", PROPERTY_HINT_NONE, ""), "set_enable_hole_punch", "get_enable_hole_punch");
|
||||
|
|
@ -108,7 +127,7 @@ bool OpenXRCompositionLayer::_should_use_fallback_node() {
|
|||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return true;
|
||||
} else if (openxr_session_running) {
|
||||
return enable_hole_punch || !is_natively_supported();
|
||||
return enable_hole_punch || (!is_natively_supported() && !use_android_surface);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -128,10 +147,36 @@ void OpenXRCompositionLayer::_remove_fallback_node() {
|
|||
fallback = nullptr;
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayer::_setup_composition_layer_provider() {
|
||||
if (use_android_surface || layer_viewport) {
|
||||
if (composition_layer_extension) {
|
||||
composition_layer_extension->register_viewport_composition_layer_provider(openxr_layer_provider);
|
||||
}
|
||||
|
||||
// NOTE: We don't setup/clear when using Android surfaces, so we don't destroy the surface unexpectedly.
|
||||
if (layer_viewport) {
|
||||
// Set our properties on the layer provider, which will create all the necessary resources (ex swap chains).
|
||||
openxr_layer_provider->set_viewport(layer_viewport->get_viewport_rid(), layer_viewport->get_size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayer::_clear_composition_layer_provider() {
|
||||
if (composition_layer_extension) {
|
||||
composition_layer_extension->unregister_viewport_composition_layer_provider(openxr_layer_provider);
|
||||
}
|
||||
|
||||
// NOTE: We don't setup/clear when using Android surfaces, so we don't destroy the surface unexpectedly.
|
||||
if (!use_android_surface) {
|
||||
// This will reset the viewport and free all the resources (ex swap chains) used by the layer.
|
||||
openxr_layer_provider->set_viewport(RID(), Size2i());
|
||||
}
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayer::_on_openxr_session_begun() {
|
||||
openxr_session_running = true;
|
||||
if (layer_viewport && is_natively_supported() && is_visible() && is_inside_tree()) {
|
||||
openxr_layer_provider->set_viewport(layer_viewport->get_viewport_rid(), layer_viewport->get_size());
|
||||
if (is_natively_supported() && is_visible() && is_inside_tree()) {
|
||||
_setup_composition_layer_provider();
|
||||
}
|
||||
if (!fallback && _should_use_fallback_node()) {
|
||||
_create_fallback_node();
|
||||
|
|
@ -142,9 +187,8 @@ void OpenXRCompositionLayer::_on_openxr_session_stopping() {
|
|||
openxr_session_running = false;
|
||||
if (fallback && !_should_use_fallback_node()) {
|
||||
_remove_fallback_node();
|
||||
} else {
|
||||
openxr_layer_provider->set_viewport(RID(), Size2i());
|
||||
}
|
||||
_clear_composition_layer_provider();
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayer::update_fallback_mesh() {
|
||||
|
|
@ -162,6 +206,7 @@ XrPosef OpenXRCompositionLayer::get_openxr_pose() {
|
|||
}
|
||||
|
||||
bool OpenXRCompositionLayer::is_viewport_in_use(SubViewport *p_viewport) {
|
||||
ERR_FAIL_NULL_V(p_viewport, false);
|
||||
for (const OpenXRCompositionLayer *other_composition_layer : composition_layer_nodes) {
|
||||
if (other_composition_layer != this && other_composition_layer->is_inside_tree() && other_composition_layer->get_layer_viewport() == p_viewport) {
|
||||
return true;
|
||||
|
|
@ -178,6 +223,9 @@ void OpenXRCompositionLayer::set_layer_viewport(SubViewport *p_viewport) {
|
|||
if (p_viewport != nullptr) {
|
||||
ERR_FAIL_COND_EDMSG(is_viewport_in_use(p_viewport), RTR("Cannot use the same SubViewport with multiple OpenXR composition layers. Clear it from its current layer first."));
|
||||
}
|
||||
if (use_android_surface) {
|
||||
ERR_FAIL_COND_MSG(p_viewport != nullptr, RTR("Cannot set SubViewport on an OpenXR composition layer when using an Android surface."));
|
||||
}
|
||||
|
||||
layer_viewport = p_viewport;
|
||||
|
||||
|
|
@ -200,6 +248,41 @@ void OpenXRCompositionLayer::set_layer_viewport(SubViewport *p_viewport) {
|
|||
}
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayer::set_use_android_surface(bool p_use_android_surface) {
|
||||
if (use_android_surface == p_use_android_surface) {
|
||||
return;
|
||||
}
|
||||
|
||||
use_android_surface = p_use_android_surface;
|
||||
if (use_android_surface) {
|
||||
set_layer_viewport(nullptr);
|
||||
openxr_layer_provider->set_use_android_surface(true, android_surface_size);
|
||||
} else {
|
||||
openxr_layer_provider->set_use_android_surface(false, Size2i());
|
||||
}
|
||||
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
||||
bool OpenXRCompositionLayer::get_use_android_surface() const {
|
||||
return use_android_surface;
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayer::set_android_surface_size(Size2i p_size) {
|
||||
if (android_surface_size == p_size) {
|
||||
return;
|
||||
}
|
||||
|
||||
android_surface_size = p_size;
|
||||
if (use_android_surface) {
|
||||
openxr_layer_provider->set_use_android_surface(true, android_surface_size);
|
||||
}
|
||||
}
|
||||
|
||||
Size2i OpenXRCompositionLayer::get_android_surface_size() const {
|
||||
return android_surface_size;
|
||||
}
|
||||
|
||||
SubViewport *OpenXRCompositionLayer::get_layer_viewport() const {
|
||||
return layer_viewport;
|
||||
}
|
||||
|
|
@ -228,33 +311,23 @@ bool OpenXRCompositionLayer::get_enable_hole_punch() const {
|
|||
}
|
||||
|
||||
void OpenXRCompositionLayer::set_sort_order(int p_order) {
|
||||
if (openxr_layer_provider) {
|
||||
openxr_layer_provider->set_sort_order(p_order);
|
||||
update_configuration_warnings();
|
||||
}
|
||||
openxr_layer_provider->set_sort_order(p_order);
|
||||
update_configuration_warnings();
|
||||
}
|
||||
|
||||
int OpenXRCompositionLayer::get_sort_order() const {
|
||||
if (openxr_layer_provider) {
|
||||
return openxr_layer_provider->get_sort_order();
|
||||
}
|
||||
return 1;
|
||||
return openxr_layer_provider->get_sort_order();
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayer::set_alpha_blend(bool p_alpha_blend) {
|
||||
if (openxr_layer_provider) {
|
||||
openxr_layer_provider->set_alpha_blend(p_alpha_blend);
|
||||
if (fallback) {
|
||||
_reset_fallback_material();
|
||||
}
|
||||
openxr_layer_provider->set_alpha_blend(p_alpha_blend);
|
||||
if (fallback) {
|
||||
_reset_fallback_material();
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenXRCompositionLayer::get_alpha_blend() const {
|
||||
if (openxr_layer_provider) {
|
||||
return openxr_layer_provider->get_alpha_blend();
|
||||
}
|
||||
return false;
|
||||
return openxr_layer_provider->get_alpha_blend();
|
||||
}
|
||||
|
||||
bool OpenXRCompositionLayer::is_natively_supported() const {
|
||||
|
|
@ -264,6 +337,10 @@ bool OpenXRCompositionLayer::is_natively_supported() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
Ref<JavaObject> OpenXRCompositionLayer::get_android_surface() {
|
||||
return openxr_layer_provider->get_android_surface();
|
||||
}
|
||||
|
||||
Vector2 OpenXRCompositionLayer::intersects_ray(const Vector3 &p_origin, const Vector3 &p_direction) const {
|
||||
return Vector2(-1.0, -1.0);
|
||||
}
|
||||
|
|
@ -298,19 +375,7 @@ void OpenXRCompositionLayer::_reset_fallback_material() {
|
|||
|
||||
material->set_flag(StandardMaterial3D::FLAG_DISABLE_DEPTH_TEST, !enable_hole_punch);
|
||||
material->set_transparency(get_alpha_blend() ? StandardMaterial3D::TRANSPARENCY_ALPHA : StandardMaterial3D::TRANSPARENCY_DISABLED);
|
||||
|
||||
Ref<ViewportTexture> texture = material->get_texture(StandardMaterial3D::TEXTURE_ALBEDO);
|
||||
if (texture.is_null()) {
|
||||
texture.instantiate();
|
||||
// ViewportTexture can't be configured without a local scene, so use this hack to set it.
|
||||
HashMap<Ref<Resource>, Ref<Resource>> remap_cache;
|
||||
texture->configure_for_local_scene(this, remap_cache);
|
||||
}
|
||||
|
||||
Node *loc_scene = texture->get_local_scene();
|
||||
NodePath viewport_path = loc_scene->get_path_to(layer_viewport);
|
||||
texture->set_viewport_path_in_scene(viewport_path);
|
||||
material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, texture);
|
||||
material->set_texture(StandardMaterial3D::TEXTURE_ALBEDO, layer_viewport->get_texture());
|
||||
} else {
|
||||
fallback->set_surface_override_material(0, Ref<Material>());
|
||||
}
|
||||
|
|
@ -321,12 +386,10 @@ void OpenXRCompositionLayer::_notification(int p_what) {
|
|||
case NOTIFICATION_POSTINITIALIZE: {
|
||||
composition_layer_nodes.push_back(this);
|
||||
|
||||
if (openxr_layer_provider) {
|
||||
for (OpenXRExtensionWrapper *extension : OpenXRAPI::get_registered_extension_wrappers()) {
|
||||
extension_property_values.merge(extension->get_viewport_composition_layer_extension_property_defaults());
|
||||
}
|
||||
openxr_layer_provider->set_extension_property_values(extension_property_values);
|
||||
for (OpenXRExtensionWrapper *extension : OpenXRAPI::get_registered_extension_wrappers()) {
|
||||
extension_property_values.merge(extension->get_viewport_composition_layer_extension_property_defaults());
|
||||
}
|
||||
openxr_layer_provider->set_extension_property_values(extension_property_values);
|
||||
} break;
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
if (fallback) {
|
||||
|
|
@ -338,11 +401,11 @@ void OpenXRCompositionLayer::_notification(int p_what) {
|
|||
}
|
||||
} break;
|
||||
case NOTIFICATION_VISIBILITY_CHANGED: {
|
||||
if (!fallback && openxr_session_running && is_inside_tree()) {
|
||||
if (layer_viewport && is_visible()) {
|
||||
openxr_layer_provider->set_viewport(layer_viewport->get_viewport_rid(), layer_viewport->get_size());
|
||||
if (is_natively_supported() && openxr_session_running && is_inside_tree()) {
|
||||
if (is_visible()) {
|
||||
_setup_composition_layer_provider();
|
||||
} else {
|
||||
openxr_layer_provider->set_viewport(RID(), Size2i());
|
||||
_clear_composition_layer_provider();
|
||||
}
|
||||
}
|
||||
update_configuration_warnings();
|
||||
|
|
@ -351,25 +414,15 @@ void OpenXRCompositionLayer::_notification(int p_what) {
|
|||
update_configuration_warnings();
|
||||
} break;
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
if (composition_layer_extension) {
|
||||
composition_layer_extension->register_viewport_composition_layer_provider(openxr_layer_provider);
|
||||
}
|
||||
|
||||
if (is_viewport_in_use(layer_viewport)) {
|
||||
set_layer_viewport(nullptr);
|
||||
} else if (!fallback && layer_viewport && openxr_session_running && is_visible()) {
|
||||
openxr_layer_provider->set_viewport(layer_viewport->get_viewport_rid(), layer_viewport->get_size());
|
||||
if (layer_viewport && is_viewport_in_use(layer_viewport)) {
|
||||
_clear_composition_layer_provider();
|
||||
} else if (openxr_session_running && is_visible()) {
|
||||
_setup_composition_layer_provider();
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
if (composition_layer_extension) {
|
||||
composition_layer_extension->unregister_viewport_composition_layer_provider(openxr_layer_provider);
|
||||
}
|
||||
|
||||
if (!fallback) {
|
||||
// This will clean up existing resources.
|
||||
openxr_layer_provider->set_viewport(RID(), Size2i());
|
||||
}
|
||||
// This will clean up existing resources.
|
||||
_clear_composition_layer_provider();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
|
@ -382,7 +435,7 @@ void OpenXRCompositionLayer::_get_property_list(List<PropertyInfo> *p_property_l
|
|||
|
||||
for (const PropertyInfo &pinfo : extension_properties) {
|
||||
StringName prop_name = pinfo.name;
|
||||
if (!String(prop_name).contains("/")) {
|
||||
if (!String(prop_name).contains_char('/')) {
|
||||
WARN_PRINT_ONCE(vformat("Discarding OpenXRCompositionLayer property name '%s' from extension because it doesn't contain a '/'."));
|
||||
continue;
|
||||
}
|
||||
|
|
@ -401,13 +454,27 @@ bool OpenXRCompositionLayer::_get(const StringName &p_property, Variant &r_value
|
|||
bool OpenXRCompositionLayer::_set(const StringName &p_property, const Variant &p_value) {
|
||||
extension_property_values[p_property] = p_value;
|
||||
|
||||
if (openxr_layer_provider) {
|
||||
openxr_layer_provider->set_extension_property_values(extension_property_values);
|
||||
}
|
||||
openxr_layer_provider->set_extension_property_values(extension_property_values);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenXRCompositionLayer::_validate_property(PropertyInfo &p_property) const {
|
||||
if (p_property.name == "layer_viewport") {
|
||||
if (use_android_surface) {
|
||||
p_property.usage &= ~PROPERTY_USAGE_EDITOR;
|
||||
} else {
|
||||
p_property.usage |= PROPERTY_USAGE_EDITOR;
|
||||
}
|
||||
} else if (p_property.name == "android_surface_size") {
|
||||
if (use_android_surface) {
|
||||
p_property.usage |= PROPERTY_USAGE_EDITOR;
|
||||
} else {
|
||||
p_property.usage &= ~PROPERTY_USAGE_EDITOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PackedStringArray OpenXRCompositionLayer::get_configuration_warnings() const {
|
||||
PackedStringArray warnings = Node3D::get_configuration_warnings();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
#include "scene/3d/node_3d.h"
|
||||
|
||||
class JavaObject;
|
||||
class MeshInstance3D;
|
||||
class Mesh;
|
||||
class OpenXRAPI;
|
||||
|
|
@ -45,7 +46,12 @@ class SubViewport;
|
|||
class OpenXRCompositionLayer : public Node3D {
|
||||
GDCLASS(OpenXRCompositionLayer, Node3D);
|
||||
|
||||
XrCompositionLayerBaseHeader *composition_layer_base_header = nullptr;
|
||||
OpenXRViewportCompositionLayerProvider *openxr_layer_provider = nullptr;
|
||||
|
||||
SubViewport *layer_viewport = nullptr;
|
||||
bool use_android_surface = false;
|
||||
Size2i android_surface_size = Size2i(1024, 1024);
|
||||
bool enable_hole_punch = false;
|
||||
MeshInstance3D *fallback = nullptr;
|
||||
bool should_update_fallback_mesh = false;
|
||||
|
|
@ -58,10 +64,12 @@ class OpenXRCompositionLayer : public Node3D {
|
|||
void _reset_fallback_material();
|
||||
void _remove_fallback_node();
|
||||
|
||||
void _setup_composition_layer_provider();
|
||||
void _clear_composition_layer_provider();
|
||||
|
||||
protected:
|
||||
OpenXRAPI *openxr_api = nullptr;
|
||||
OpenXRCompositionLayerExtension *composition_layer_extension = nullptr;
|
||||
OpenXRViewportCompositionLayerProvider *openxr_layer_provider = nullptr;
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
|
|
@ -69,6 +77,7 @@ protected:
|
|||
void _get_property_list(List<PropertyInfo> *p_property_list) const;
|
||||
bool _get(const StringName &p_property, Variant &r_value) const;
|
||||
bool _set(const StringName &p_property, const Variant &p_value);
|
||||
void _validate_property(PropertyInfo &p_property) const;
|
||||
|
||||
virtual void _on_openxr_session_begun();
|
||||
virtual void _on_openxr_session_stopping();
|
||||
|
|
@ -82,10 +91,18 @@ protected:
|
|||
static Vector<OpenXRCompositionLayer *> composition_layer_nodes;
|
||||
bool is_viewport_in_use(SubViewport *p_viewport);
|
||||
|
||||
OpenXRCompositionLayer(XrCompositionLayerBaseHeader *p_composition_layer);
|
||||
|
||||
public:
|
||||
void set_layer_viewport(SubViewport *p_viewport);
|
||||
SubViewport *get_layer_viewport() const;
|
||||
|
||||
void set_use_android_surface(bool p_use_android_surface);
|
||||
bool get_use_android_surface() const;
|
||||
|
||||
void set_android_surface_size(Size2i p_size);
|
||||
Size2i get_android_surface_size() const;
|
||||
|
||||
void set_enable_hole_punch(bool p_enable);
|
||||
bool get_enable_hole_punch() const;
|
||||
|
||||
|
|
@ -95,13 +112,13 @@ public:
|
|||
void set_alpha_blend(bool p_alpha_blend);
|
||||
bool get_alpha_blend() const;
|
||||
|
||||
Ref<JavaObject> get_android_surface();
|
||||
bool is_natively_supported() const;
|
||||
|
||||
virtual PackedStringArray get_configuration_warnings() const override;
|
||||
|
||||
virtual Vector2 intersects_ray(const Vector3 &p_origin, const Vector3 &p_direction) const;
|
||||
|
||||
OpenXRCompositionLayer();
|
||||
~OpenXRCompositionLayer();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -30,28 +30,12 @@
|
|||
|
||||
#include "openxr_composition_layer_cylinder.h"
|
||||
|
||||
#include "../extensions/openxr_composition_layer_extension.h"
|
||||
#include "../openxr_api.h"
|
||||
#include "../openxr_interface.h"
|
||||
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
|
||||
OpenXRCompositionLayerCylinder::OpenXRCompositionLayerCylinder() {
|
||||
composition_layer = {
|
||||
XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR, // type
|
||||
nullptr, // next
|
||||
0, // layerFlags
|
||||
XR_NULL_HANDLE, // space
|
||||
XR_EYE_VISIBILITY_BOTH, // eyeVisibility
|
||||
{}, // subImage
|
||||
{ { 0, 0, 0, 0 }, { 0, 0, 0 } }, // pose
|
||||
radius, // radius
|
||||
central_angle, // centralAngle
|
||||
aspect_ratio, // aspectRatio
|
||||
};
|
||||
openxr_layer_provider = memnew(OpenXRViewportCompositionLayerProvider((XrCompositionLayerBaseHeader *)&composition_layer));
|
||||
OpenXRCompositionLayerCylinder::OpenXRCompositionLayerCylinder() :
|
||||
OpenXRCompositionLayer((XrCompositionLayerBaseHeader *)&composition_layer) {
|
||||
XRServer::get_singleton()->connect("reference_frame_changed", callable_mp(this, &OpenXRCompositionLayerCylinder::update_transform));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,18 @@
|
|||
class OpenXRCompositionLayerCylinder : public OpenXRCompositionLayer {
|
||||
GDCLASS(OpenXRCompositionLayerCylinder, OpenXRCompositionLayer);
|
||||
|
||||
XrCompositionLayerCylinderKHR composition_layer;
|
||||
XrCompositionLayerCylinderKHR composition_layer = {
|
||||
XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR, // type
|
||||
nullptr, // next
|
||||
0, // layerFlags
|
||||
XR_NULL_HANDLE, // space
|
||||
XR_EYE_VISIBILITY_BOTH, // eyeVisibility
|
||||
{}, // subImage
|
||||
{ { 0, 0, 0, 0 }, { 0, 0, 0 } }, // pose
|
||||
1.0, // radius
|
||||
Math_PI / 2.0, // centralAngle
|
||||
1.0, // aspectRatio
|
||||
};
|
||||
|
||||
float radius = 1.0;
|
||||
float aspect_ratio = 1.0;
|
||||
|
|
|
|||
|
|
@ -30,29 +30,12 @@
|
|||
|
||||
#include "openxr_composition_layer_equirect.h"
|
||||
|
||||
#include "../extensions/openxr_composition_layer_extension.h"
|
||||
#include "../openxr_api.h"
|
||||
#include "../openxr_interface.h"
|
||||
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
|
||||
OpenXRCompositionLayerEquirect::OpenXRCompositionLayerEquirect() {
|
||||
composition_layer = {
|
||||
XR_TYPE_COMPOSITION_LAYER_EQUIRECT2_KHR, // type
|
||||
nullptr, // next
|
||||
0, // layerFlags
|
||||
XR_NULL_HANDLE, // space
|
||||
XR_EYE_VISIBILITY_BOTH, // eyeVisibility
|
||||
{}, // subImage
|
||||
{ { 0, 0, 0, 0 }, { 0, 0, 0 } }, // pose
|
||||
radius, // radius
|
||||
central_horizontal_angle, // centralHorizontalAngle
|
||||
upper_vertical_angle, // upperVerticalAngle
|
||||
-lower_vertical_angle, // lowerVerticalAngle
|
||||
};
|
||||
openxr_layer_provider = memnew(OpenXRViewportCompositionLayerProvider((XrCompositionLayerBaseHeader *)&composition_layer));
|
||||
OpenXRCompositionLayerEquirect::OpenXRCompositionLayerEquirect() :
|
||||
OpenXRCompositionLayer((XrCompositionLayerBaseHeader *)&composition_layer) {
|
||||
XRServer::get_singleton()->connect("reference_frame_changed", callable_mp(this, &OpenXRCompositionLayerEquirect::update_transform));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,19 @@
|
|||
class OpenXRCompositionLayerEquirect : public OpenXRCompositionLayer {
|
||||
GDCLASS(OpenXRCompositionLayerEquirect, OpenXRCompositionLayer);
|
||||
|
||||
XrCompositionLayerEquirect2KHR composition_layer;
|
||||
XrCompositionLayerEquirect2KHR composition_layer = {
|
||||
XR_TYPE_COMPOSITION_LAYER_EQUIRECT2_KHR, // type
|
||||
nullptr, // next
|
||||
0, // layerFlags
|
||||
XR_NULL_HANDLE, // space
|
||||
XR_EYE_VISIBILITY_BOTH, // eyeVisibility
|
||||
{}, // subImage
|
||||
{ { 0, 0, 0, 0 }, { 0, 0, 0 } }, // pose
|
||||
1.0, // radius
|
||||
Math_PI / 2.0, // centralHorizontalAngle
|
||||
Math_PI / 4.0, // upperVerticalAngle
|
||||
-Math_PI / 4.0, // lowerVerticalAngle
|
||||
};
|
||||
|
||||
float radius = 1.0;
|
||||
float central_horizontal_angle = Math_PI / 2.0;
|
||||
|
|
|
|||
|
|
@ -30,26 +30,12 @@
|
|||
|
||||
#include "openxr_composition_layer_quad.h"
|
||||
|
||||
#include "../extensions/openxr_composition_layer_extension.h"
|
||||
#include "../openxr_api.h"
|
||||
#include "../openxr_interface.h"
|
||||
|
||||
#include "scene/3d/mesh_instance_3d.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "scene/resources/3d/primitive_meshes.h"
|
||||
|
||||
OpenXRCompositionLayerQuad::OpenXRCompositionLayerQuad() {
|
||||
composition_layer = {
|
||||
XR_TYPE_COMPOSITION_LAYER_QUAD, // type
|
||||
nullptr, // next
|
||||
0, // layerFlags
|
||||
XR_NULL_HANDLE, // space
|
||||
XR_EYE_VISIBILITY_BOTH, // eyeVisibility
|
||||
{}, // subImage
|
||||
{ { 0, 0, 0, 0 }, { 0, 0, 0 } }, // pose
|
||||
{ (float)quad_size.x, (float)quad_size.y }, // size
|
||||
};
|
||||
openxr_layer_provider = memnew(OpenXRViewportCompositionLayerProvider((XrCompositionLayerBaseHeader *)&composition_layer));
|
||||
OpenXRCompositionLayerQuad::OpenXRCompositionLayerQuad() :
|
||||
OpenXRCompositionLayer((XrCompositionLayerBaseHeader *)&composition_layer) {
|
||||
XRServer::get_singleton()->connect("reference_frame_changed", callable_mp(this, &OpenXRCompositionLayerQuad::update_transform));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,16 @@
|
|||
class OpenXRCompositionLayerQuad : public OpenXRCompositionLayer {
|
||||
GDCLASS(OpenXRCompositionLayerQuad, OpenXRCompositionLayer);
|
||||
|
||||
XrCompositionLayerQuad composition_layer;
|
||||
XrCompositionLayerQuad composition_layer = {
|
||||
XR_TYPE_COMPOSITION_LAYER_QUAD, // type
|
||||
nullptr, // next
|
||||
0, // layerFlags
|
||||
XR_NULL_HANDLE, // space
|
||||
XR_EYE_VISIBILITY_BOTH, // eyeVisibility
|
||||
{}, // subImage
|
||||
{ { 0, 0, 0, 0 }, { 0, 0, 0 } }, // pose
|
||||
{ 1.0, 1.0 }, // size
|
||||
};
|
||||
|
||||
Size2 quad_size = Size2(1.0, 1.0);
|
||||
|
||||
|
|
|
|||
106
engine/modules/openxr/scene/openxr_visibility_mask.cpp
Normal file
106
engine/modules/openxr/scene/openxr_visibility_mask.cpp
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/**************************************************************************/
|
||||
/* openxr_visibility_mask.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "openxr_visibility_mask.h"
|
||||
|
||||
#include "../extensions/openxr_visibility_mask_extension.h"
|
||||
#include "../openxr_interface.h"
|
||||
#include "scene/3d/xr_nodes.h"
|
||||
|
||||
void OpenXRVisibilityMask::_bind_methods() {
|
||||
}
|
||||
|
||||
void OpenXRVisibilityMask::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
OpenXRVisibilityMaskExtension *vis_mask_ext = OpenXRVisibilityMaskExtension::get_singleton();
|
||||
if (vis_mask_ext && vis_mask_ext->is_available()) {
|
||||
set_base(vis_mask_ext->get_mesh());
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
set_base(RID());
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenXRVisibilityMask::_on_openxr_session_begun() {
|
||||
if (is_inside_tree()) {
|
||||
OpenXRVisibilityMaskExtension *vis_mask_ext = OpenXRVisibilityMaskExtension::get_singleton();
|
||||
if (vis_mask_ext && vis_mask_ext->is_available()) {
|
||||
set_base(vis_mask_ext->get_mesh());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OpenXRVisibilityMask::_on_openxr_session_stopping() {
|
||||
set_base(RID());
|
||||
}
|
||||
|
||||
PackedStringArray OpenXRVisibilityMask::get_configuration_warnings() const {
|
||||
PackedStringArray warnings = VisualInstance3D::get_configuration_warnings();
|
||||
|
||||
if (is_visible() && is_inside_tree()) {
|
||||
XRCamera3D *camera = Object::cast_to<XRCamera3D>(get_parent());
|
||||
if (camera == nullptr) {
|
||||
warnings.push_back(RTR("OpenXR visibility mask must have an XRCamera3D node as their parent."));
|
||||
}
|
||||
}
|
||||
|
||||
return warnings;
|
||||
}
|
||||
|
||||
AABB OpenXRVisibilityMask::get_aabb() const {
|
||||
AABB ret;
|
||||
|
||||
// Make sure it's always visible, this is positioned through its shader.
|
||||
ret.position = Vector3(-1000.0, -1000.0, -1000.0);
|
||||
ret.size = Vector3(2000.0, 2000.0, 2000.0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
OpenXRVisibilityMask::OpenXRVisibilityMask() {
|
||||
Ref<OpenXRInterface> openxr_interface = XRServer::get_singleton()->find_interface("OpenXR");
|
||||
if (openxr_interface.is_valid()) {
|
||||
openxr_interface->connect("session_begun", callable_mp(this, &OpenXRVisibilityMask::_on_openxr_session_begun));
|
||||
openxr_interface->connect("session_stopping", callable_mp(this, &OpenXRVisibilityMask::_on_openxr_session_stopping));
|
||||
}
|
||||
|
||||
RS::get_singleton()->instance_geometry_set_cast_shadows_setting(get_instance(), RS::SHADOW_CASTING_SETTING_OFF);
|
||||
}
|
||||
|
||||
OpenXRVisibilityMask::~OpenXRVisibilityMask() {
|
||||
Ref<OpenXRInterface> openxr_interface = XRServer::get_singleton()->find_interface("OpenXR");
|
||||
if (openxr_interface.is_valid()) {
|
||||
openxr_interface->disconnect("session_begun", callable_mp(this, &OpenXRVisibilityMask::_on_openxr_session_begun));
|
||||
openxr_interface->disconnect("session_stopping", callable_mp(this, &OpenXRVisibilityMask::_on_openxr_session_stopping));
|
||||
}
|
||||
}
|
||||
56
engine/modules/openxr/scene/openxr_visibility_mask.h
Normal file
56
engine/modules/openxr/scene/openxr_visibility_mask.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/**************************************************************************/
|
||||
/* openxr_visibility_mask.h */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef OPENXR_VISIBILITY_MASK_H
|
||||
#define OPENXR_VISIBILITY_MASK_H
|
||||
|
||||
#include "scene/3d/visual_instance_3d.h"
|
||||
|
||||
class OpenXRVisibilityMask : public VisualInstance3D {
|
||||
GDCLASS(OpenXRVisibilityMask, VisualInstance3D);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
void _notification(int p_what);
|
||||
|
||||
void _on_openxr_session_begun();
|
||||
void _on_openxr_session_stopping();
|
||||
|
||||
public:
|
||||
virtual PackedStringArray get_configuration_warnings() const override;
|
||||
|
||||
virtual AABB get_aabb() const override;
|
||||
|
||||
OpenXRVisibilityMask();
|
||||
~OpenXRVisibilityMask();
|
||||
};
|
||||
|
||||
#endif // OPENXR_VISIBILITY_MASK_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue