Debian Codegraph @

modules/openxr/scene/openxr_visibility_mask.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* openxr_visibility_mask.cpp */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #include "openxr_visibility_mask.h"
32
33 #include "../extensions/openxr_visibility_mask_extension.h"
34 #include "../openxr_interface.h"
35 #include "scene/3d/xr/xr_nodes.h"
36
37 void OpenXRVisibilityMask::_bind_methods() {
38 }
39
40 void OpenXRVisibilityMask::_notification(int p_what) {
41 switch (p_what) {
42 case NOTIFICATION_ENTER_TREE: {
43 OpenXRVisibilityMaskExtension *vis_mask_ext = OpenXRVisibilityMaskExtension::get_singleton();
44 if (vis_mask_ext && vis_mask_ext->is_available()) {
45 set_base(vis_mask_ext->get_mesh());
46 }
47 } break;
48 case NOTIFICATION_EXIT_TREE: {
49 set_base(RID());
50 } break;
51 }
52 }
53
54 void OpenXRVisibilityMask::_on_openxr_session_begun() {
55 if (is_inside_tree()) {
56 OpenXRVisibilityMaskExtension *vis_mask_ext = OpenXRVisibilityMaskExtension::get_singleton();
57 if (vis_mask_ext && vis_mask_ext->is_available()) {
58 set_base(vis_mask_ext->get_mesh());
59 }
60 }
61 }
62
63 void OpenXRVisibilityMask::_on_openxr_session_stopping() {
64 set_base(RID());
65 }
66
67 PackedStringArray OpenXRVisibilityMask::get_configuration_warnings() const {
68 PackedStringArray warnings = VisualInstance3D::get_configuration_warnings();
69
70 if (is_visible() && is_inside_tree()) {
71 XRCamera3D *camera = Object::cast_to<XRCamera3D>(get_parent());
72 if (camera == nullptr) {
73 warnings.push_back(RTR("OpenXR visibility mask must have an XRCamera3D node as their parent."));
74 }
75 }
76
77 return warnings;
78 }
79
80 AABB OpenXRVisibilityMask::get_aabb() const {
81 AABB ret;
82
83 // Make sure it's always visible, this is positioned through its shader.
84 ret.position = Vector3(-1000.0, -1000.0, -1000.0);
85 ret.size = Vector3(2000.0, 2000.0, 2000.0);
86
87 return ret;
88 }
89
90 OpenXRVisibilityMask::OpenXRVisibilityMask() {
91 Ref<OpenXRInterface> openxr_interface = XRServer::get_singleton()->find_interface("OpenXR");
92 if (openxr_interface.is_valid()) {
93 openxr_interface->connect("session_begun", callable_mp(this, &OpenXRVisibilityMask::_on_openxr_session_begun));
94 openxr_interface->connect("session_stopping", callable_mp(this, &OpenXRVisibilityMask::_on_openxr_session_stopping));
95 }
96
97 RS::get_singleton()->instance_geometry_set_cast_shadows_setting(get_instance(), RS::SHADOW_CASTING_SETTING_OFF);
98 }
99
100 OpenXRVisibilityMask::~OpenXRVisibilityMask() {
101 Ref<OpenXRInterface> openxr_interface = XRServer::get_singleton()->find_interface("OpenXR");
102 if (openxr_interface.is_valid()) {
103 openxr_interface->disconnect("session_begun", callable_mp(this, &OpenXRVisibilityMask::_on_openxr_session_begun));
104 openxr_interface->disconnect("session_stopping", callable_mp(this, &OpenXRVisibilityMask::_on_openxr_session_stopping));
105 }
106 }