1/**************************************************************************/
2/* visible_on_screen_notifier_3d.h */
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#ifndef VISIBLE_ON_SCREEN_NOTIFIER_3D_H
32#define VISIBLE_ON_SCREEN_NOTIFIER_3D_H
33
34#include "scene/3d/visual_instance_3d.h"
35
36class World3D;
37class Camera3D;
38class VisibleOnScreenNotifier3D : public VisualInstance3D {
39 GDCLASS(VisibleOnScreenNotifier3D, VisualInstance3D);
40
41 AABB aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));
42
43private:
44 bool on_screen = false;
45 void _visibility_enter();
46 void _visibility_exit();
47
48protected:
49 virtual void _screen_enter() {}
50 virtual void _screen_exit() {}
51
52 void _notification(int p_what);
53 static void _bind_methods();
54
55public:
56 void set_aabb(const AABB &p_aabb);
57 virtual AABB get_aabb() const override;
58 bool is_on_screen() const;
59
60 virtual PackedStringArray get_configuration_warnings() const override;
61
62 VisibleOnScreenNotifier3D();
63 ~VisibleOnScreenNotifier3D();
64};
65
66class VisibleOnScreenEnabler3D : public VisibleOnScreenNotifier3D {
67 GDCLASS(VisibleOnScreenEnabler3D, VisibleOnScreenNotifier3D);
68
69public:
70 enum EnableMode {
71 ENABLE_MODE_INHERIT,
72 ENABLE_MODE_ALWAYS,
73 ENABLE_MODE_WHEN_PAUSED,
74 };
75
76protected:
77 ObjectID node_id;
78 virtual void _screen_enter() override;
79 virtual void _screen_exit() override;
80
81 EnableMode enable_mode = ENABLE_MODE_INHERIT;
82 NodePath enable_node_path = NodePath("..");
83
84 void _notification(int p_what);
85 static void _bind_methods();
86
87 void _update_enable_mode(bool p_enable);
88
89public:
90 void set_enable_mode(EnableMode p_mode);
91 EnableMode get_enable_mode();
92
93 void set_enable_node_path(NodePath p_path);
94 NodePath get_enable_node_path();
95
96 VisibleOnScreenEnabler3D();
97};
98
99VARIANT_ENUM_CAST(VisibleOnScreenEnabler3D::EnableMode);
100
101#endif // VISIBLE_ON_SCREEN_NOTIFIER_3D_H
102