diff --git a/doc/classes/VisibilityEnabler3D.xml b/doc/classes/VisibilityEnabler3D.xml deleted file mode 100644 index 4614859a44..0000000000 --- a/doc/classes/VisibilityEnabler3D.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - Enables certain nodes only when approximately visible. - - - The VisibilityEnabler3D will disable [RigidBody3D] and [AnimationPlayer] nodes when they are not visible. It will only affect other nodes within the same scene as the VisibilityEnabler3D itself. - If you just want to receive notifications, use [VisibilityNotifier3D] instead. - [b]Note:[/b] VisibilityEnabler3D uses an approximate heuristic for performance reasons. It doesn't take walls and other occlusion into account. The heuristic is an implementation detail and may change in future versions. If you need precise visibility checking, use another method such as adding an [Area3D] node as a child of a [Camera3D] node and/or [method Vector3.dot]. - [b]Note:[/b] VisibilityEnabler3D will not affect nodes added after scene initialization. - - - - - - - - - - - - - - - - - - - - diff --git a/doc/classes/VisibilityEnabler2D.xml b/doc/classes/VisibleOnScreenEnabler2D.xml similarity index 80% rename from doc/classes/VisibilityEnabler2D.xml rename to doc/classes/VisibleOnScreenEnabler2D.xml index 8eb16ba075..c6ae8227d2 100644 --- a/doc/classes/VisibilityEnabler2D.xml +++ b/doc/classes/VisibleOnScreenEnabler2D.xml @@ -1,5 +1,5 @@ - + @@ -9,7 +9,7 @@ - + diff --git a/doc/classes/VisibleOnScreenEnabler3D.xml b/doc/classes/VisibleOnScreenEnabler3D.xml new file mode 100644 index 0000000000..3205d6b415 --- /dev/null +++ b/doc/classes/VisibleOnScreenEnabler3D.xml @@ -0,0 +1,30 @@ + + + + Enables certain nodes only when approximately visible. + + + The VisibleOnScreenEnabler3D will disable [RigidBody3D] and [AnimationPlayer] nodes when they are not visible. It will only affect other nodes within the same scene as the VisibleOnScreenEnabler3D itself. + If you just want to receive notifications, use [VisibleOnScreenNotifier3D] instead. + [b]Note:[/b] VisibleOnScreenEnabler3D uses an approximate heuristic for performance reasons. It doesn't take walls and other occlusion into account. The heuristic is an implementation detail and may change in future versions. If you need precise visibility checking, use another method such as adding an [Area3D] node as a child of a [Camera3D] node and/or [method Vector3.dot]. + [b]Note:[/b] VisibleOnScreenEnabler3D will not affect nodes added after scene initialization. + + + + + + + + + + + + + + + + + + + + diff --git a/doc/classes/VisibilityNotifier2D.xml b/doc/classes/VisibleOnScreenNotifier2D.xml similarity index 71% rename from doc/classes/VisibilityNotifier2D.xml rename to doc/classes/VisibleOnScreenNotifier2D.xml index 78983e74ee..f2f3bc9144 100644 --- a/doc/classes/VisibilityNotifier2D.xml +++ b/doc/classes/VisibleOnScreenNotifier2D.xml @@ -1,11 +1,11 @@ - + Detects when the node extents are visible on screen. - The VisibilityNotifier2D detects when it is visible on the screen. It also notifies when its bounding rectangle enters or exits the screen or a viewport. - If you want nodes to be disabled automatically when they exit the screen, use [VisibilityEnabler2D] instead. + The VisibleOnScreenNotifier2D detects when it is visible on the screen. It also notifies when its bounding rectangle enters or exits the screen or a viewport. + If you want nodes to be disabled automatically when they exit the screen, use [VisibleOnScreenEnabler2D] instead. https://godotengine.org/asset-library/asset/515 @@ -22,18 +22,18 @@ - The VisibilityNotifier2D's bounding rectangle. + The VisibleOnScreenNotifier2D's bounding rectangle. - Emitted when the VisibilityNotifier2D enters the screen. + Emitted when the VisibleOnScreenNotifier2D enters the screen. - Emitted when the VisibilityNotifier2D exits the screen. + Emitted when the VisibleOnScreenNotifier2D exits the screen. diff --git a/doc/classes/VisibilityNotifier3D.xml b/doc/classes/VisibleOnScreenNotifier3D.xml similarity index 55% rename from doc/classes/VisibilityNotifier3D.xml rename to doc/classes/VisibleOnScreenNotifier3D.xml index bd6c03ea20..859dacd716 100644 --- a/doc/classes/VisibilityNotifier3D.xml +++ b/doc/classes/VisibleOnScreenNotifier3D.xml @@ -1,12 +1,12 @@ - + Detects approximately when the node is visible on screen. - The VisibilityNotifier3D detects when it is visible on the screen. It also notifies when its bounding rectangle enters or exits the screen or a [Camera3D]'s view. - If you want nodes to be disabled automatically when they exit the screen, use [VisibilityEnabler3D] instead. - [b]Note:[/b] VisibilityNotifier3D uses an approximate heuristic for performance reasons. It doesn't take walls and other occlusion into account. The heuristic is an implementation detail and may change in future versions. If you need precise visibility checking, use another method such as adding an [Area3D] node as a child of a [Camera3D] node and/or [method Vector3.dot]. + The VisibleOnScreenNotifier3D detects when it is visible on the screen. It also notifies when its bounding rectangle enters or exits the screen or a [Camera3D]'s view. + If you want nodes to be disabled automatically when they exit the screen, use [VisibleOnScreenEnabler3D] instead. + [b]Note:[/b] VisibleOnScreenNotifier3D uses an approximate heuristic for performance reasons. It doesn't take walls and other occlusion into account. The heuristic is an implementation detail and may change in future versions. If you need precise visibility checking, use another method such as adding an [Area3D] node as a child of a [Camera3D] node and/or [method Vector3.dot]. @@ -22,18 +22,18 @@ - The VisibilityNotifier3D's bounding box. + The VisibleOnScreenNotifier3D's bounding box. - Emitted when the VisibilityNotifier3D enters the screen. + Emitted when the VisibleOnScreenNotifier3D enters the screen. - Emitted when the VisibilityNotifier3D exits the screen. + Emitted when the VisibleOnScreenNotifier3D exits the screen. diff --git a/editor/icons/VisibilityEnabler2D.svg b/editor/icons/VisibleOnScreenEnabler2D.svg similarity index 100% rename from editor/icons/VisibilityEnabler2D.svg rename to editor/icons/VisibleOnScreenEnabler2D.svg diff --git a/editor/icons/VisibilityEnabler3D.svg b/editor/icons/VisibleOnScreenEnabler3D.svg similarity index 100% rename from editor/icons/VisibilityEnabler3D.svg rename to editor/icons/VisibleOnScreenEnabler3D.svg diff --git a/editor/icons/VisibilityNotifier2D.svg b/editor/icons/VisibleOnScreenNotifier2D.svg similarity index 100% rename from editor/icons/VisibilityNotifier2D.svg rename to editor/icons/VisibleOnScreenNotifier2D.svg diff --git a/editor/icons/VisibilityNotifier3D.svg b/editor/icons/VisibleOnScreenNotifier3D.svg similarity index 100% rename from editor/icons/VisibilityNotifier3D.svg rename to editor/icons/VisibleOnScreenNotifier3D.svg diff --git a/editor/node_3d_editor_gizmos.cpp b/editor/node_3d_editor_gizmos.cpp index 5c69a1e975..19663e46e1 100644 --- a/editor/node_3d_editor_gizmos.cpp +++ b/editor/node_3d_editor_gizmos.cpp @@ -55,7 +55,7 @@ #include "scene/3d/spring_arm_3d.h" #include "scene/3d/sprite_3d.h" #include "scene/3d/vehicle_body_3d.h" -#include "scene/3d/visibility_notifier_3d.h" +#include "scene/3d/visible_on_screen_notifier_3d.h" #include "scene/3d/voxel_gi.h" #include "scene/resources/box_shape_3d.h" #include "scene/resources/capsule_shape_3d.h" @@ -2127,7 +2127,7 @@ bool SoftBody3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_giz /////////// -VisibilityNotifier3DGizmoPlugin::VisibilityNotifier3DGizmoPlugin() { +VisibleOnScreenNotifier3DGizmoPlugin::VisibleOnScreenNotifier3DGizmoPlugin() { Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/visibility_notifier", Color(0.8, 0.5, 0.7)); create_material("visibility_notifier_material", gizmo_color); gizmo_color.a = 0.1; @@ -2135,19 +2135,19 @@ VisibilityNotifier3DGizmoPlugin::VisibilityNotifier3DGizmoPlugin() { create_handle_material("handles"); } -bool VisibilityNotifier3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { - return Object::cast_to(p_spatial) != nullptr; +bool VisibleOnScreenNotifier3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { + return Object::cast_to(p_spatial) != nullptr; } -String VisibilityNotifier3DGizmoPlugin::get_gizmo_name() const { - return "VisibilityNotifier3D"; +String VisibleOnScreenNotifier3DGizmoPlugin::get_gizmo_name() const { + return "VisibleOnScreenNotifier3D"; } -int VisibilityNotifier3DGizmoPlugin::get_priority() const { +int VisibleOnScreenNotifier3DGizmoPlugin::get_priority() const { return -1; } -String VisibilityNotifier3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { +String VisibleOnScreenNotifier3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { switch (p_idx) { case 0: return "Size X"; @@ -2166,13 +2166,13 @@ String VisibilityNotifier3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo return ""; } -Variant VisibilityNotifier3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { - VisibilityNotifier3D *notifier = Object::cast_to(p_gizmo->get_spatial_node()); +Variant VisibleOnScreenNotifier3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { + VisibleOnScreenNotifier3D *notifier = Object::cast_to(p_gizmo->get_spatial_node()); return notifier->get_aabb(); } -void VisibilityNotifier3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { - VisibilityNotifier3D *notifier = Object::cast_to(p_gizmo->get_spatial_node()); +void VisibleOnScreenNotifier3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { + VisibleOnScreenNotifier3D *notifier = Object::cast_to(p_gizmo->get_spatial_node()); Transform3D gt = notifier->get_global_transform(); @@ -2223,8 +2223,8 @@ void VisibilityNotifier3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int } } -void VisibilityNotifier3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { - VisibilityNotifier3D *notifier = Object::cast_to(p_gizmo->get_spatial_node()); +void VisibleOnScreenNotifier3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { + VisibleOnScreenNotifier3D *notifier = Object::cast_to(p_gizmo->get_spatial_node()); if (p_cancel) { notifier->set_aabb(p_restore); @@ -2238,8 +2238,8 @@ void VisibilityNotifier3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, ur->commit_action(); } -void VisibilityNotifier3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { - VisibilityNotifier3D *notifier = Object::cast_to(p_gizmo->get_spatial_node()); +void VisibleOnScreenNotifier3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { + VisibleOnScreenNotifier3D *notifier = Object::cast_to(p_gizmo->get_spatial_node()); p_gizmo->clear(); diff --git a/editor/node_3d_editor_gizmos.h b/editor/node_3d_editor_gizmos.h index 8a0e10241a..6f071859ec 100644 --- a/editor/node_3d_editor_gizmos.h +++ b/editor/node_3d_editor_gizmos.h @@ -218,8 +218,8 @@ public: SoftBody3DGizmoPlugin(); }; -class VisibilityNotifier3DGizmoPlugin : public EditorNode3DGizmoPlugin { - GDCLASS(VisibilityNotifier3DGizmoPlugin, EditorNode3DGizmoPlugin); +class VisibleOnScreenNotifier3DGizmoPlugin : public EditorNode3DGizmoPlugin { + GDCLASS(VisibleOnScreenNotifier3DGizmoPlugin, EditorNode3DGizmoPlugin); public: bool has_gizmo(Node3D *p_spatial) override; @@ -232,7 +232,7 @@ public: void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) override; - VisibilityNotifier3DGizmoPlugin(); + VisibleOnScreenNotifier3DGizmoPlugin(); }; class CPUParticles3DGizmoPlugin : public EditorNode3DGizmoPlugin { diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 60cc0a0a2a..726f74e67f 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -6492,7 +6492,7 @@ void Node3DEditor::_register_all_gizmos() { add_gizmo_plugin(Ref(memnew(RayCast3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(SpringArm3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(VehicleWheel3DGizmoPlugin))); - add_gizmo_plugin(Ref(memnew(VisibilityNotifier3DGizmoPlugin))); + add_gizmo_plugin(Ref(memnew(VisibleOnScreenNotifier3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(GPUParticles3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(GPUParticlesCollision3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(CPUParticles3DGizmoPlugin))); diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visible_on_screen_notifier_2d.cpp similarity index 72% rename from scene/2d/visibility_notifier_2d.cpp rename to scene/2d/visible_on_screen_notifier_2d.cpp index a73d60ada5..25237edacf 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visible_on_screen_notifier_2d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visibility_notifier_2d.cpp */ +/* visible_on_screen_notifier_2d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "visibility_notifier_2d.h" +#include "visible_on_screen_notifier_2d.h" #include "core/config/engine.h" #include "gpu_particles_2d.h" @@ -39,16 +39,16 @@ #include "scene/scene_string_names.h" #ifdef TOOLS_ENABLED -Rect2 VisibilityNotifier2D::_edit_get_rect() const { +Rect2 VisibleOnScreenNotifier2D::_edit_get_rect() const { return rect; } -bool VisibilityNotifier2D::_edit_use_rect() const { +bool VisibleOnScreenNotifier2D::_edit_use_rect() const { return true; } #endif -void VisibilityNotifier2D::_visibility_enter() { +void VisibleOnScreenNotifier2D::_visibility_enter() { if (!is_inside_tree() || Engine::get_singleton()->is_editor_hint()) { return; } @@ -57,7 +57,7 @@ void VisibilityNotifier2D::_visibility_enter() { emit_signal(SceneStringNames::get_singleton()->screen_entered); _screen_enter(); } -void VisibilityNotifier2D::_visibility_exit() { +void VisibleOnScreenNotifier2D::_visibility_exit() { if (!is_inside_tree() || Engine::get_singleton()->is_editor_hint()) { return; } @@ -67,23 +67,23 @@ void VisibilityNotifier2D::_visibility_exit() { _screen_exit(); } -void VisibilityNotifier2D::set_rect(const Rect2 &p_rect) { +void VisibleOnScreenNotifier2D::set_rect(const Rect2 &p_rect) { rect = p_rect; if (is_inside_tree()) { - RS::get_singleton()->canvas_item_set_visibility_notifier(get_canvas_item(), true, rect, callable_mp(this, &VisibilityNotifier2D::_visibility_enter), callable_mp(this, &VisibilityNotifier2D::_visibility_exit)); + RS::get_singleton()->canvas_item_set_visibility_notifier(get_canvas_item(), true, rect, callable_mp(this, &VisibleOnScreenNotifier2D::_visibility_enter), callable_mp(this, &VisibleOnScreenNotifier2D::_visibility_exit)); } } -Rect2 VisibilityNotifier2D::get_rect() const { +Rect2 VisibleOnScreenNotifier2D::get_rect() const { return rect; } -void VisibilityNotifier2D::_notification(int p_what) { +void VisibleOnScreenNotifier2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { //get_world_2d()-> on_screen = false; - RS::get_singleton()->canvas_item_set_visibility_notifier(get_canvas_item(), true, rect, callable_mp(this, &VisibilityNotifier2D::_visibility_enter), callable_mp(this, &VisibilityNotifier2D::_visibility_exit)); + RS::get_singleton()->canvas_item_set_visibility_notifier(get_canvas_item(), true, rect, callable_mp(this, &VisibleOnScreenNotifier2D::_visibility_enter), callable_mp(this, &VisibleOnScreenNotifier2D::_visibility_exit)); } break; case NOTIFICATION_DRAW: { if (Engine::get_singleton()->is_editor_hint()) { @@ -97,14 +97,14 @@ void VisibilityNotifier2D::_notification(int p_what) { } } -bool VisibilityNotifier2D::is_on_screen() const { +bool VisibleOnScreenNotifier2D::is_on_screen() const { return on_screen; } -void VisibilityNotifier2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_rect", "rect"), &VisibilityNotifier2D::set_rect); - ClassDB::bind_method(D_METHOD("get_rect"), &VisibilityNotifier2D::get_rect); - ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier2D::is_on_screen); +void VisibleOnScreenNotifier2D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_rect", "rect"), &VisibleOnScreenNotifier2D::set_rect); + ClassDB::bind_method(D_METHOD("get_rect"), &VisibleOnScreenNotifier2D::get_rect); + ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibleOnScreenNotifier2D::is_on_screen); ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect"), "set_rect", "get_rect"); @@ -112,31 +112,31 @@ void VisibilityNotifier2D::_bind_methods() { ADD_SIGNAL(MethodInfo("screen_exited")); } -VisibilityNotifier2D::VisibilityNotifier2D() { +VisibleOnScreenNotifier2D::VisibleOnScreenNotifier2D() { rect = Rect2(-10, -10, 20, 20); } ////////////////////////////////////// -void VisibilityEnabler2D::_screen_enter() { +void VisibleOnScreenEnabler2D::_screen_enter() { _update_enable_mode(true); } -void VisibilityEnabler2D::_screen_exit() { +void VisibleOnScreenEnabler2D::_screen_exit() { _update_enable_mode(false); } -void VisibilityEnabler2D::set_enable_mode(EnableMode p_mode) { +void VisibleOnScreenEnabler2D::set_enable_mode(EnableMode p_mode) { enable_mode = p_mode; if (is_inside_tree()) { _update_enable_mode(is_on_screen()); } } -VisibilityEnabler2D::EnableMode VisibilityEnabler2D::get_enable_mode() { +VisibleOnScreenEnabler2D::EnableMode VisibleOnScreenEnabler2D::get_enable_mode() { return enable_mode; } -void VisibilityEnabler2D::set_enable_node_path(NodePath p_path) { +void VisibleOnScreenEnabler2D::set_enable_node_path(NodePath p_path) { if (enable_node_path == p_path) { return; } @@ -150,11 +150,11 @@ void VisibilityEnabler2D::set_enable_node_path(NodePath p_path) { } } } -NodePath VisibilityEnabler2D::get_enable_node_path() { +NodePath VisibleOnScreenEnabler2D::get_enable_node_path() { return enable_node_path; } -void VisibilityEnabler2D::_update_enable_mode(bool p_enable) { +void VisibleOnScreenEnabler2D::_update_enable_mode(bool p_enable) { Node *node = static_cast(ObjectDB::get_instance(node_id)); if (node) { if (p_enable) { @@ -174,7 +174,7 @@ void VisibilityEnabler2D::_update_enable_mode(bool p_enable) { } } } -void VisibilityEnabler2D::_notification(int p_what) { +void VisibleOnScreenEnabler2D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { if (Engine::get_singleton()->is_editor_hint()) { return; @@ -193,12 +193,12 @@ void VisibilityEnabler2D::_notification(int p_what) { } } -void VisibilityEnabler2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enable_mode", "mode"), &VisibilityEnabler2D::set_enable_mode); - ClassDB::bind_method(D_METHOD("get_enable_mode"), &VisibilityEnabler2D::get_enable_mode); +void VisibleOnScreenEnabler2D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_enable_mode", "mode"), &VisibleOnScreenEnabler2D::set_enable_mode); + ClassDB::bind_method(D_METHOD("get_enable_mode"), &VisibleOnScreenEnabler2D::get_enable_mode); - ClassDB::bind_method(D_METHOD("set_enable_node_path", "path"), &VisibilityEnabler2D::set_enable_node_path); - ClassDB::bind_method(D_METHOD("get_enable_node_path"), &VisibilityEnabler2D::get_enable_node_path); + ClassDB::bind_method(D_METHOD("set_enable_node_path", "path"), &VisibleOnScreenEnabler2D::set_enable_node_path); + ClassDB::bind_method(D_METHOD("get_enable_node_path"), &VisibleOnScreenEnabler2D::get_enable_node_path); ADD_GROUP("Enabling", "enable_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "enable_mode", PROPERTY_HINT_ENUM, "Inherit,Always,WhenPaused"), "set_enable_mode", "get_enable_mode"); @@ -209,5 +209,5 @@ void VisibilityEnabler2D::_bind_methods() { BIND_ENUM_CONSTANT(ENABLE_MODE_WHEN_PAUSED); } -VisibilityEnabler2D::VisibilityEnabler2D() { +VisibleOnScreenEnabler2D::VisibleOnScreenEnabler2D() { } diff --git a/scene/2d/visibility_notifier_2d.h b/scene/2d/visible_on_screen_notifier_2d.h similarity index 87% rename from scene/2d/visibility_notifier_2d.h rename to scene/2d/visible_on_screen_notifier_2d.h index 8cb0989787..9c236a138f 100644 --- a/scene/2d/visibility_notifier_2d.h +++ b/scene/2d/visible_on_screen_notifier_2d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visibility_notifier_2d.h */ +/* visible_on_screen_notifier_2d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef VISIBILITY_NOTIFIER_2D_H -#define VISIBILITY_NOTIFIER_2D_H +#ifndef VISIBLE_ON_SCREEN_NOTIFIER_2D_H +#define VISIBLE_ON_SCREEN_NOTIFIER_2D_H #include "scene/2d/node_2d.h" class Viewport; -class VisibilityNotifier2D : public Node2D { - GDCLASS(VisibilityNotifier2D, Node2D); +class VisibleOnScreenNotifier2D : public Node2D { + GDCLASS(VisibleOnScreenNotifier2D, Node2D); Set viewports; @@ -64,11 +64,11 @@ public: bool is_on_screen() const; - VisibilityNotifier2D(); + VisibleOnScreenNotifier2D(); }; -class VisibilityEnabler2D : public VisibilityNotifier2D { - GDCLASS(VisibilityEnabler2D, VisibilityNotifier2D); +class VisibleOnScreenEnabler2D : public VisibleOnScreenNotifier2D { + GDCLASS(VisibleOnScreenEnabler2D, VisibleOnScreenNotifier2D); public: enum EnableMode { @@ -97,9 +97,9 @@ public: void set_enable_node_path(NodePath p_path); NodePath get_enable_node_path(); - VisibilityEnabler2D(); + VisibleOnScreenEnabler2D(); }; -VARIANT_ENUM_CAST(VisibilityEnabler2D::EnableMode); +VARIANT_ENUM_CAST(VisibleOnScreenEnabler2D::EnableMode); #endif // VISIBILITY_NOTIFIER_2D_H diff --git a/scene/3d/visibility_notifier_3d.cpp b/scene/3d/visible_on_screen_notifier_3d.cpp similarity index 72% rename from scene/3d/visibility_notifier_3d.cpp rename to scene/3d/visible_on_screen_notifier_3d.cpp index 39b17d195b..682bcec449 100644 --- a/scene/3d/visibility_notifier_3d.cpp +++ b/scene/3d/visible_on_screen_notifier_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visibility_notifier_3d.cpp */ +/* visible_on_screen_notifier_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "visibility_notifier_3d.h" +#include "visible_on_screen_notifier_3d.h" #include "core/config/engine.h" #include "scene/3d/camera_3d.h" @@ -36,7 +36,7 @@ #include "scene/animation/animation_player.h" #include "scene/scene_string_names.h" -void VisibilityNotifier3D::_visibility_enter() { +void VisibleOnScreenNotifier3D::_visibility_enter() { if (!is_inside_tree() || Engine::get_singleton()->is_editor_hint()) { return; } @@ -45,7 +45,7 @@ void VisibilityNotifier3D::_visibility_enter() { emit_signal(SceneStringNames::get_singleton()->screen_entered); _screen_enter(); } -void VisibilityNotifier3D::_visibility_exit() { +void VisibleOnScreenNotifier3D::_visibility_exit() { if (!is_inside_tree() || Engine::get_singleton()->is_editor_hint()) { return; } @@ -55,7 +55,7 @@ void VisibilityNotifier3D::_visibility_exit() { _screen_exit(); } -void VisibilityNotifier3D::set_aabb(const AABB &p_aabb) { +void VisibleOnScreenNotifier3D::set_aabb(const AABB &p_aabb) { if (aabb == p_aabb) { return; } @@ -66,23 +66,23 @@ void VisibilityNotifier3D::set_aabb(const AABB &p_aabb) { update_gizmo(); } -AABB VisibilityNotifier3D::get_aabb() const { +AABB VisibleOnScreenNotifier3D::get_aabb() const { return aabb; } -bool VisibilityNotifier3D::is_on_screen() const { +bool VisibleOnScreenNotifier3D::is_on_screen() const { return on_screen; } -void VisibilityNotifier3D::_notification(int p_what) { +void VisibleOnScreenNotifier3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_EXIT_TREE) { on_screen = false; } } -void VisibilityNotifier3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_aabb", "rect"), &VisibilityNotifier3D::set_aabb); - ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier3D::is_on_screen); +void VisibleOnScreenNotifier3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_aabb", "rect"), &VisibleOnScreenNotifier3D::set_aabb); + ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibleOnScreenNotifier3D::is_on_screen); ADD_PROPERTY(PropertyInfo(Variant::AABB, "aabb"), "set_aabb", "get_aabb"); @@ -90,38 +90,43 @@ void VisibilityNotifier3D::_bind_methods() { ADD_SIGNAL(MethodInfo("screen_exited")); } -Vector VisibilityNotifier3D::get_faces(uint32_t p_usage_flags) const { +Vector VisibleOnScreenNotifier3D::get_faces(uint32_t p_usage_flags) const { return Vector(); } -VisibilityNotifier3D::VisibilityNotifier3D() { +VisibleOnScreenNotifier3D::VisibleOnScreenNotifier3D() { RID notifier = RS::get_singleton()->visibility_notifier_create(); RS::get_singleton()->visibility_notifier_set_aabb(notifier, aabb); - RS::get_singleton()->visibility_notifier_set_callbacks(notifier, callable_mp(this, &VisibilityNotifier3D::_visibility_enter), callable_mp(this, &VisibilityNotifier3D::_visibility_exit)); + RS::get_singleton()->visibility_notifier_set_callbacks(notifier, callable_mp(this, &VisibleOnScreenNotifier3D::_visibility_enter), callable_mp(this, &VisibleOnScreenNotifier3D::_visibility_exit)); set_base(notifier); } +VisibleOnScreenNotifier3D::~VisibleOnScreenNotifier3D() { + RID base = get_base(); + set_base(RID()); + RS::get_singleton()->free(base); +} ////////////////////////////////////// -void VisibilityEnabler3D::_screen_enter() { +void VisibleOnScreenEnabler3D::_screen_enter() { _update_enable_mode(true); } -void VisibilityEnabler3D::_screen_exit() { +void VisibleOnScreenEnabler3D::_screen_exit() { _update_enable_mode(false); } -void VisibilityEnabler3D::set_enable_mode(EnableMode p_mode) { +void VisibleOnScreenEnabler3D::set_enable_mode(EnableMode p_mode) { enable_mode = p_mode; if (is_inside_tree()) { _update_enable_mode(is_on_screen()); } } -VisibilityEnabler3D::EnableMode VisibilityEnabler3D::get_enable_mode() { +VisibleOnScreenEnabler3D::EnableMode VisibleOnScreenEnabler3D::get_enable_mode() { return enable_mode; } -void VisibilityEnabler3D::set_enable_node_path(NodePath p_path) { +void VisibleOnScreenEnabler3D::set_enable_node_path(NodePath p_path) { if (enable_node_path == p_path) { return; } @@ -135,11 +140,11 @@ void VisibilityEnabler3D::set_enable_node_path(NodePath p_path) { } } } -NodePath VisibilityEnabler3D::get_enable_node_path() { +NodePath VisibleOnScreenEnabler3D::get_enable_node_path() { return enable_node_path; } -void VisibilityEnabler3D::_update_enable_mode(bool p_enable) { +void VisibleOnScreenEnabler3D::_update_enable_mode(bool p_enable) { Node *node = static_cast(ObjectDB::get_instance(node_id)); if (node) { if (p_enable) { @@ -159,7 +164,7 @@ void VisibilityEnabler3D::_update_enable_mode(bool p_enable) { } } } -void VisibilityEnabler3D::_notification(int p_what) { +void VisibleOnScreenEnabler3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { if (Engine::get_singleton()->is_editor_hint()) { return; @@ -178,12 +183,12 @@ void VisibilityEnabler3D::_notification(int p_what) { } } -void VisibilityEnabler3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enable_mode", "mode"), &VisibilityEnabler3D::set_enable_mode); - ClassDB::bind_method(D_METHOD("get_enable_mode"), &VisibilityEnabler3D::get_enable_mode); +void VisibleOnScreenEnabler3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_enable_mode", "mode"), &VisibleOnScreenEnabler3D::set_enable_mode); + ClassDB::bind_method(D_METHOD("get_enable_mode"), &VisibleOnScreenEnabler3D::get_enable_mode); - ClassDB::bind_method(D_METHOD("set_enable_node_path", "path"), &VisibilityEnabler3D::set_enable_node_path); - ClassDB::bind_method(D_METHOD("get_enable_node_path"), &VisibilityEnabler3D::get_enable_node_path); + ClassDB::bind_method(D_METHOD("set_enable_node_path", "path"), &VisibleOnScreenEnabler3D::set_enable_node_path); + ClassDB::bind_method(D_METHOD("get_enable_node_path"), &VisibleOnScreenEnabler3D::get_enable_node_path); ADD_GROUP("Enabling", "enable_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "enable_mode", PROPERTY_HINT_ENUM, "Inherit,Always,WhenPaused"), "set_enable_mode", "get_enable_mode"); @@ -194,5 +199,5 @@ void VisibilityEnabler3D::_bind_methods() { BIND_ENUM_CONSTANT(ENABLE_MODE_WHEN_PAUSED); } -VisibilityEnabler3D::VisibilityEnabler3D() { +VisibleOnScreenEnabler3D::VisibleOnScreenEnabler3D() { } diff --git a/scene/3d/visibility_notifier_3d.h b/scene/3d/visible_on_screen_notifier_3d.h similarity index 86% rename from scene/3d/visibility_notifier_3d.h rename to scene/3d/visible_on_screen_notifier_3d.h index 878c97e35e..fb7137c4f0 100644 --- a/scene/3d/visibility_notifier_3d.h +++ b/scene/3d/visible_on_screen_notifier_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visibility_notifier_3d.h */ +/* visible_on_screen_notifier_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef VISIBILITY_NOTIFIER_H -#define VISIBILITY_NOTIFIER_H +#ifndef VISIBLE_ON_SCREEN_NOTIFIER_3D_H +#define VISIBLE_ON_SCREEN_NOTIFIER_3D_H #include "scene/3d/visual_instance_3d.h" class World3D; class Camera3D; -class VisibilityNotifier3D : public VisualInstance3D { - GDCLASS(VisibilityNotifier3D, VisualInstance3D); +class VisibleOnScreenNotifier3D : public VisualInstance3D { + GDCLASS(VisibleOnScreenNotifier3D, VisualInstance3D); AABB aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2)); @@ -59,11 +59,12 @@ public: virtual Vector get_faces(uint32_t p_usage_flags) const override; - VisibilityNotifier3D(); + VisibleOnScreenNotifier3D(); + ~VisibleOnScreenNotifier3D(); }; -class VisibilityEnabler3D : public VisibilityNotifier3D { - GDCLASS(VisibilityEnabler3D, VisibilityNotifier3D); +class VisibleOnScreenEnabler3D : public VisibleOnScreenNotifier3D { + GDCLASS(VisibleOnScreenEnabler3D, VisibleOnScreenNotifier3D); public: enum EnableMode { @@ -92,9 +93,9 @@ public: void set_enable_node_path(NodePath p_path); NodePath get_enable_node_path(); - VisibilityEnabler3D(); + VisibleOnScreenEnabler3D(); }; -VARIANT_ENUM_CAST(VisibilityEnabler3D::EnableMode); +VARIANT_ENUM_CAST(VisibleOnScreenEnabler3D::EnableMode); #endif // VISIBILITY_NOTIFIER_H diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 332976a18d..2a97ae3acf 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -65,7 +65,7 @@ #include "scene/2d/sprite_2d.h" #include "scene/2d/tile_map.h" #include "scene/2d/touch_screen_button.h" -#include "scene/2d/visibility_notifier_2d.h" +#include "scene/2d/visible_on_screen_notifier_2d.h" #include "scene/animation/animation_blend_space_1d.h" #include "scene/animation/animation_blend_space_2d.h" #include "scene/animation/animation_blend_tree.h" @@ -229,7 +229,7 @@ #include "scene/3d/spring_arm_3d.h" #include "scene/3d/sprite_3d.h" #include "scene/3d/vehicle_body_3d.h" -#include "scene/3d/visibility_notifier_3d.h" +#include "scene/3d/visible_on_screen_notifier_3d.h" #include "scene/3d/voxel_gi.h" #include "scene/3d/world_environment.h" #include "scene/3d/xr_nodes.h" @@ -513,8 +513,8 @@ void register_scene_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); @@ -655,8 +655,8 @@ void register_scene_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); - ClassDB::register_class(); - ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); @@ -966,8 +966,8 @@ void register_scene_types() { ClassDB::add_compatibility_class("VehicleWheel", "VehicleWheel3D"); ClassDB::add_compatibility_class("ViewportContainer", "SubViewportContainer"); ClassDB::add_compatibility_class("Viewport", "SubViewport"); - ClassDB::add_compatibility_class("VisibilityEnabler", "VisibilityEnabler3D"); - ClassDB::add_compatibility_class("VisibilityNotifier", "VisibilityNotifier3D"); + ClassDB::add_compatibility_class("VisibilityEnabler", "VisibleOnScreenEnabler3D"); + ClassDB::add_compatibility_class("VisibilityNotifier", "VisibleOnScreenNotifier3D"); ClassDB::add_compatibility_class("VisualServer", "RenderingServer"); ClassDB::add_compatibility_class("VisualShaderNodeScalarConstant", "VisualShaderNodeFloatConstant"); ClassDB::add_compatibility_class("VisualShaderNodeScalarFunc", "VisualShaderNodeFloatFunc"); @@ -986,6 +986,8 @@ void register_scene_types() { ClassDB::add_compatibility_class("World", "World3D"); ClassDB::add_compatibility_class("StreamTexture", "StreamTexture2D"); ClassDB::add_compatibility_class("Light2D", "PointLight2D"); + ClassDB::add_compatibility_class("VisibilityNotifier2D", "VisibleOnScreenNotifier2D"); + ClassDB::add_compatibility_class("VisibilityNotifier3D", "VisibleOnScreenNotifier3D"); #endif /* DISABLE_DEPRECATED */ diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 9a7a47f884..8af4deda83 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -32,7 +32,7 @@ #include "core/config/project_settings.h" #include "scene/2d/camera_2d.h" -#include "scene/2d/visibility_notifier_2d.h" +#include "scene/2d/visible_on_screen_notifier_2d.h" #include "scene/main/window.h" #include "servers/navigation_server_2d.h" #include "servers/physics_server_2d.h" diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h index e31ac22351..65f89c8f64 100644 --- a/scene/resources/world_2d.h +++ b/scene/resources/world_2d.h @@ -35,7 +35,7 @@ #include "core/io/resource.h" #include "servers/physics_server_2d.h" -class VisibilityNotifier2D; +class VisibleOnScreenNotifier2D; class Viewport; struct SpatialIndexer2D; diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp index a85bd8fdba..8d9b1fd6ec 100644 --- a/scene/resources/world_3d.cpp +++ b/scene/resources/world_3d.cpp @@ -33,7 +33,7 @@ #include "core/math/camera_matrix.h" #include "core/math/octree.h" #include "scene/3d/camera_3d.h" -#include "scene/3d/visibility_notifier_3d.h" +#include "scene/3d/visible_on_screen_notifier_3d.h" #include "scene/scene_string_names.h" #include "servers/navigation_server_3d.h" diff --git a/scene/resources/world_3d.h b/scene/resources/world_3d.h index da5ed486b0..2c5be35609 100644 --- a/scene/resources/world_3d.h +++ b/scene/resources/world_3d.h @@ -38,7 +38,7 @@ #include "servers/rendering_server.h" class Camera3D; -class VisibilityNotifier3D; +class VisibleOnScreenNotifier3D; struct SpatialIndexer; class World3D : public Resource {