100class DebugDraw3D :
public Object,
public IScopeStorage<DebugDraw3DScopeConfig, DebugDraw3DScopeConfig::Data> {
105#ifndef DISABLE_DEBUG_RENDERING
106 friend DebugGeometryContainer;
107 friend _DD3D_WorldWatcher;
122 String root_settings_section;
123 const static char *s_use_icosphere;
124 const static char *s_use_icosphere_hd;
125 const static char *s_add_bevel_to_volumetric;
126 const static char *s_default_frustum_scale;
128 const static char *s_default_thickness;
129 const static char *s_default_center_brightness;
130 const static char *s_default_hd_spheres;
131 const static char *s_default_plane_size;
133 std::vector<SubViewport *> custom_editor_viewports;
136 Ref<DebugDraw3DScopeConfig> default_scoped_config;
138#ifndef DISABLE_DEBUG_RENDERING
139 ProfiledMutex(std::recursive_mutex, datalock,
"3D Geometry lock");
141 typedef std::pair<uint64_t, DebugDraw3DScopeConfig *> ScopedPairIdConfig;
143 std::unordered_map<uint64_t, std::vector<ScopedPairIdConfig> > scoped_configs;
145 std::unordered_map<uint64_t, std::shared_ptr<DebugDraw3DScopeConfig::Data> > cached_scoped_configs;
146 uint64_t created_scoped_configs = 0;
150 } scoped_stats_3d = {};
153 const std::shared_ptr<DebugDraw3DScopeConfig::Data> scoped_config_for_current_thread()
override;
157 std::vector<Ref<ArrayMesh> > shared_generated_meshes;
159 std::unordered_map<uint64_t, std::shared_ptr<DebugGeometryContainer> > debug_containers;
160 struct viewportToWorldCache {
161 uint64_t world_id = 0;
162 std::shared_ptr<DebugGeometryContainer> dgc;
164 std::unordered_map<const Viewport *, viewportToWorldCache> viewport_to_world_cache;
167 Ref<ShaderMaterial> shader_wireframe_mat;
168 Ref<Shader> shader_wireframe_code;
170 Ref<ShaderMaterial> shader_billboard_mat;
171 Ref<Shader> shader_billboard_code;
173 Ref<ShaderMaterial> shader_plane_mat;
174 Ref<Shader> shader_plane_code;
176 Ref<ShaderMaterial> shader_extendable_mat;
177 Ref<Shader> shader_extendable_code;
180 void _register_scoped_config(uint64_t p_thread_id, uint64_t p_guard_id,
DebugDraw3DScopeConfig *p_cfg)
override;
181 void _unregister_scoped_config(uint64_t p_thread_id, uint64_t p_guard_id)
override;
182 void _clear_scoped_configs()
override;
184 Ref<ArrayMesh> *get_shared_meshes();
185 std::shared_ptr<DebugGeometryContainer> create_debug_container();
186 std::shared_ptr<DebugGeometryContainer> get_debug_container(Viewport *p_vp);
187 void _register_viewport_world_deferred(Viewport *p_vp,
const uint64_t p_world_id);
188 Viewport *_get_root_world_viewport(Viewport *p_vp);
189 void _remove_debug_container(
const uint64_t &p_world_id);
191 _FORCE_INLINE_ Vector3 get_up_vector(
const Vector3 &p_dir);
192 void add_or_update_line_with_thickness(real_t p_exp_time, std::unique_ptr<Vector3[]> p_lines,
const size_t p_line_count,
const Color &p_col,
const std::function<
void(DelayedRendererLine *)> p_custom_upd =
nullptr);
193 Node *get_root_node();
195 void create_arrow(
const Vector3 &p_a,
const Vector3 &p_b,
const Color &p_color,
const real_t &p_arrow_size,
const bool &p_is_absolute_size,
const real_t &p_duration = 0);
201 void set_custom_editor_viewport(std::vector<SubViewport *> p_viewports);
202 std::vector<SubViewport *> get_custom_editor_viewports();
204 Ref<ShaderMaterial> get_wireframe_material();
205 Ref<ShaderMaterial> get_billboard_material();
206 Ref<ShaderMaterial> get_plane_material();
207 Ref<ShaderMaterial> get_extendable_material();
209 void _load_materials();
210 inline bool _is_enabled_override()
const;
212 void process(
double p_delta);
213 void physics_process_start(
double p_delta);
214 void physics_process_end(
double p_delta);
216#pragma region Exposed Parameter Values
219 bool debug_enabled =
true;
221 Ref<DebugDraw3DConfig> config;
227 static void _bind_methods();
240#pragma region Configs
267#pragma region Exposed Parameters
269 void set_empty_color(
const Color &col){};
279 bool is_debug_enabled()
const;
283#pragma region Exposed Draw Methods
299#ifndef DISABLE_DEBUG_RENDERING
300#define FAKE_FUNC_IMPL
302#define FAKE_FUNC_IMPL \
318#pragma region Spheres
321 void draw_sphere_base(
const Transform3D &transform,
const Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
332 void draw_sphere(const Vector3 &position, const real_t &radius = 0.5f, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
342 void draw_sphere_xf(const Transform3D &transform, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
346#pragma region Cylinders
357 void draw_cylinder(
const Transform3D &transform,
const Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
370 void draw_cylinder_ab(const Vector3 &a, const Vector3 &b, const real_t &radius = 0.5f, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
390 void draw_box(
const Vector3 &position,
const Quaternion &rotation,
const Vector3 &size,
const Color &color = Colors::empty_color,
const bool &is_box_centered =
false,
const real_t &duration = 0) FAKE_FUNC_IMPL;
406 void draw_box_ab(const Vector3 &a, const Vector3 &b, const Vector3 &up, const Color &color = Colors::empty_color, const
bool &is_ab_diagonal = true, const real_t &duration = 0) FAKE_FUNC_IMPL;
416 void draw_box_xf(const Transform3D &transform, const Color &color = Colors::empty_color, const
bool &is_box_centered = true, const real_t &duration = 0) FAKE_FUNC_IMPL;
425 void draw_aabb(const AABB &aabb, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
435 void draw_aabb_ab(const Vector3 &a, const Vector3 &b, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
457 void draw_line_hit(
const Vector3 &start,
const Vector3 &end,
const Vector3 &hit,
const bool &is_hit,
const real_t &hit_size = 0.25f,
const Color &hit_color = Colors::empty_color,
const Color &after_hit_color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
475 void draw_line_hit_offset(const Vector3 &start, const Vector3 &end, const
bool &is_hit, const real_t &unit_offset_of_hit = 0.5f, const real_t &hit_size = 0.25f, const Color &hit_color = Colors::empty_color, const Color &after_hit_color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
480 void draw_lines_c(
const std::vector<Vector3> &lines,
const Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
491 void draw_line(const Vector3 &a, const Vector3 &b, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
504 void draw_ray(const Vector3 &origin, const Vector3 &direction, const real_t &length, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
515 void draw_lines(const PackedVector3Array &lines, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
528 void draw_line_path(const PackedVector3Array &path, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
541 void draw_arrowhead(
const Transform3D &transform,
const Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
555 void draw_arrow(const Vector3 &a, const Vector3 &b, const Color &color = Colors::empty_color, const real_t &arrow_size = 0.5f, const
bool &is_absolute_size = false, const real_t &duration = 0) FAKE_FUNC_IMPL;
568 void draw_arrow_ray(const Vector3 &origin, const Vector3 &direction, const real_t &length, const Color &color = Colors::empty_color, const real_t &arrow_size = 0.5f, const
bool &is_absolute_size = false, const real_t &duration = 0) FAKE_FUNC_IMPL;
581 void draw_arrow_path(const PackedVector3Array &path, const Color &color = Colors::empty_color, const real_t &arrow_size = 0.75f, const
bool &is_absolute_size = true, const real_t &duration = 0) FAKE_FUNC_IMPL;
600 void draw_point_path(
const PackedVector3Array &path,
const PointType type = PointType::POINT_TYPE_SQUARE,
const real_t &size = 0.25f,
const Color &points_color = Colors::empty_color,
const Color &lines_color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
618 void draw_points(
const PackedVector3Array &points,
const PointType type = PointType::POINT_TYPE_SQUARE,
const real_t &size = 0.25f,
const Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
628 void draw_square(const Vector3 &position, const real_t &size = 0.2f, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
642 void draw_plane(const Plane &plane, const Color &color = Colors::empty_color, const Vector3 &anchor_point = Vector3(INFINITY, INFINITY, INFINITY), const real_t &duration = 0) FAKE_FUNC_IMPL;
653 void draw_position(const Transform3D &transform, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
667 void draw_gizmo(const Transform3D &transform, const Color &color = Colors::empty_color, const
bool &is_centered = false, const real_t &duration = 0) FAKE_FUNC_IMPL;
682 void draw_grid(const Vector3 &origin, const Vector3 &x_size, const Vector3 &y_size, const Vector2i &subdivision, const Color &color = Colors::empty_color, const
bool &is_centered = true, const real_t &duration = 0) FAKE_FUNC_IMPL;
695 void draw_grid_xf(const Transform3D &transform, const Vector2i &p_subdivision, const Color &color = Colors::empty_color, const
bool &is_centered = true, const real_t &duration = 0) FAKE_FUNC_IMPL;
697#pragma region Camera Frustum
700 void draw_camera_frustum_planes_c(
const std::array<Plane, 6> &planes,
const Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
710 void draw_camera_frustum(const class godot::Camera3D *camera, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
719 void draw_camera_frustum_planes(const Array &camera_frustum, const Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;