diff --git a/doc/classes/VisualServer.xml b/doc/classes/VisualServer.xml
index a4d4b20c0c5..095f08d76d8 100644
--- a/doc/classes/VisualServer.xml
+++ b/doc/classes/VisualServer.xml
@@ -806,6 +806,14 @@
Modulates all colors in the given canvas.
+
+
+
+
+ Returns the bounding rectangle for a canvas item and its descendants in local space, as calculated by the renderer. This bound is used internally for culling.
+ [b]Warning:[/b] This function is intended for debugging in the editor, and will pass through and return a zero [Rect2] in exported projects.
+
+
diff --git a/servers/visual/visual_server_canvas.cpp b/servers/visual/visual_server_canvas.cpp
index 59d0c848829..759615a6877 100644
--- a/servers/visual/visual_server_canvas.cpp
+++ b/servers/visual/visual_server_canvas.cpp
@@ -1470,6 +1470,12 @@ Rect2 VisualServerCanvas::_debug_canvas_item_get_rect(RID p_item) {
return canvas_item->get_rect();
}
+Rect2 VisualServerCanvas::_debug_canvas_item_get_local_bound(RID p_item) {
+ Item *canvas_item = canvas_item_owner.getornull(p_item);
+ ERR_FAIL_COND_V(!canvas_item, Rect2());
+ return canvas_item->local_bound;
+}
+
void VisualServerCanvas::canvas_item_set_skeleton_relative_xform(RID p_item, Transform2D p_relative_xform) {
Item *canvas_item = canvas_item_owner.getornull(p_item);
ERR_FAIL_COND(!canvas_item);
diff --git a/servers/visual/visual_server_canvas.h b/servers/visual/visual_server_canvas.h
index 704cb3b7c05..038ee1be5d9 100644
--- a/servers/visual/visual_server_canvas.h
+++ b/servers/visual/visual_server_canvas.h
@@ -259,6 +259,7 @@ public:
void _canvas_item_skeleton_moved(RID p_item);
void canvas_item_set_skeleton_relative_xform(RID p_item, Transform2D p_relative_xform);
Rect2 _debug_canvas_item_get_rect(RID p_item);
+ Rect2 _debug_canvas_item_get_local_bound(RID p_item);
void canvas_item_set_interpolated(RID p_item, bool p_interpolated);
void canvas_item_reset_physics_interpolation(RID p_item);
diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h
index b592d7ad455..6cf0c35acfe 100644
--- a/servers/visual/visual_server_raster.h
+++ b/servers/visual/visual_server_raster.h
@@ -720,6 +720,7 @@ public:
BIND2(canvas_item_attach_skeleton, RID, RID)
BIND2(canvas_item_set_skeleton_relative_xform, RID, Transform2D)
BIND1R(Rect2, _debug_canvas_item_get_rect, RID)
+ BIND1R(Rect2, _debug_canvas_item_get_local_bound, RID)
BIND2(canvas_item_set_interpolated, RID, bool)
BIND1(canvas_item_reset_physics_interpolation, RID)
diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h
index 016c52231c6..101c57310c7 100644
--- a/servers/visual/visual_server_wrap_mt.h
+++ b/servers/visual/visual_server_wrap_mt.h
@@ -624,6 +624,7 @@ public:
FUNC2(canvas_item_attach_skeleton, RID, RID)
FUNC2(canvas_item_set_skeleton_relative_xform, RID, Transform2D)
FUNC1R(Rect2, _debug_canvas_item_get_rect, RID)
+ FUNC1R(Rect2, _debug_canvas_item_get_local_bound, RID)
FUNC2(canvas_item_set_interpolated, RID, bool)
FUNC1(canvas_item_reset_physics_interpolation, RID)
diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp
index 15b67e6b119..18df1c42626 100644
--- a/servers/visual_server.cpp
+++ b/servers/visual_server.cpp
@@ -2206,6 +2206,7 @@ void VisualServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("canvas_item_set_material", "item", "material"), &VisualServer::canvas_item_set_material);
ClassDB::bind_method(D_METHOD("canvas_item_set_use_parent_material", "item", "enabled"), &VisualServer::canvas_item_set_use_parent_material);
ClassDB::bind_method(D_METHOD("debug_canvas_item_get_rect", "item"), &VisualServer::debug_canvas_item_get_rect);
+ ClassDB::bind_method(D_METHOD("debug_canvas_item_get_local_bound", "item"), &VisualServer::debug_canvas_item_get_local_bound);
ClassDB::bind_method(D_METHOD("canvas_light_create"), &VisualServer::canvas_light_create);
ClassDB::bind_method(D_METHOD("canvas_light_attach_to_canvas", "light", "canvas"), &VisualServer::canvas_light_attach_to_canvas);
ClassDB::bind_method(D_METHOD("canvas_light_set_enabled", "light", "enabled"), &VisualServer::canvas_light_set_enabled);
diff --git a/servers/visual_server.h b/servers/visual_server.h
index d504e601466..79923e8ec19 100644
--- a/servers/visual_server.h
+++ b/servers/visual_server.h
@@ -1060,14 +1060,15 @@ public:
virtual void canvas_item_attach_skeleton(RID p_item, RID p_skeleton) = 0;
virtual void canvas_item_set_skeleton_relative_xform(RID p_item, Transform2D p_relative_xform) = 0;
- Rect2 debug_canvas_item_get_rect(RID p_item) {
#ifdef TOOLS_ENABLED
- return _debug_canvas_item_get_rect(p_item);
+ Rect2 debug_canvas_item_get_rect(RID p_item) { return _debug_canvas_item_get_rect(p_item); }
+ Rect2 debug_canvas_item_get_local_bound(RID p_item) { return _debug_canvas_item_get_local_bound(p_item); }
#else
- return Rect2();
+ Rect2 debug_canvas_item_get_rect(RID p_item) { return Rect2(); }
+ Rect2 debug_canvas_item_get_local_bound(RID p_item) { return Rect2(); }
#endif
- }
virtual Rect2 _debug_canvas_item_get_rect(RID p_item) = 0;
+ virtual Rect2 _debug_canvas_item_get_local_bound(RID p_item) = 0;
virtual void canvas_item_set_interpolated(RID p_item, bool p_interpolated) = 0;
virtual void canvas_item_reset_physics_interpolation(RID p_item) = 0;