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