121NAPI_CLASS_SINGLETON
class DebugDraw3D :
public Object,
public IScopeStorage<DebugDraw3DScopeConfig, DebugDraw3DScopeConfig::Data> {
122 GDCLASS(DebugDraw3D, Object)
124 friend DebugDrawManager;
126#ifndef DISABLE_DEBUG_RENDERING
127 friend DebugGeometryContainer;
128 friend NodesContainer;
129 friend _DD3D_WorldWatcher;
144 String root_settings_section;
145 static constexpr const char *s_use_icosphere =
"use_icosphere";
146 static constexpr const char *s_use_icosphere_hd =
"use_icosphere_for_hd";
147 static constexpr const char *s_add_bevel_to_volumetric =
"add_bevel_to_volumetric_geometry";
148 static constexpr const char *s_default_frustum_scale =
"defaults/frustum_length_scale";
150 static constexpr const char *s_default_thickness =
"volumetric_defaults/thickness";
151 static constexpr const char *s_default_center_brightness =
"volumetric_defaults/center_brightness";
152 static constexpr const char *s_default_hd_spheres =
"volumetric_defaults/hd_spheres";
153 static constexpr const char *s_default_plane_size =
"volumetric_defaults/plane_size";
155 static constexpr const char *s_render_priority =
"rendering/render_priority";
156 static constexpr const char *s_render_mode =
"rendering/render_mode";
157 static constexpr const char *s_render_fog_disabled =
"rendering/disable_fog";
159 std::vector<SubViewport *> custom_editor_viewports;
162 Ref<DebugDraw3DScopeConfig> default_scoped_config;
164#ifndef DISABLE_DEBUG_RENDERING
165 ProfiledMutex(std::recursive_mutex, datalock,
"3D Geometry lock");
167 struct ScopedPairIdConfig {
171 id(id), scfg(scfg) {}
174 std::unordered_map<uint64_t, std::vector<ScopedPairIdConfig>> scoped_configs;
176 std::unordered_map<uint64_t, std::shared_ptr<DebugDraw3DScopeConfig::Data>> cached_scoped_configs;
177 uint64_t created_scoped_configs = 0;
181 } scoped_stats_3d = {};
184 const DebugDraw3DScopeConfig::Data *scoped_config_for_current_thread()
override;
188 std::vector<std::array<GeometryGenerator::GeneratedMeshData, (int)MeshMaterialVariant::MAX>> shared_generated_meshes;
191 struct ViewportToDebugContainerItem {
193 _DD3D_WorldWatcher *world_watcher;
194 std::unique_ptr<DebugGeometryContainer> dgcs[(int)MeshMaterialVariant::MAX];
195 std::unique_ptr<NodesContainer> ncs[(int)MeshMaterialVariant::MAX];
197 ViewportToDebugContainerItem();
198 ViewportToDebugContainerItem(ViewportToDebugContainerItem &&other)
noexcept;
199 ~ViewportToDebugContainerItem();
202 std::unordered_map<uint64_t , ViewportToDebugContainerItem> debug_containers;
204 std::unordered_map<const Viewport *, ViewportToDebugContainerItem *> viewport_to_world_cache;
205 std::unordered_map<uint64_t , Ref<World3D>> world3ds_found_for_threads_cache;
208 Ref<ShaderMaterial> mesh_shaders[(int)MeshMaterialType::MAX][(
int)MeshMaterialVariant::MAX];
211 void _register_scoped_config(uint64_t p_thread_id, uint64_t p_guard_id, DebugDraw3DScopeConfig *p_cfg)
override;
212 void _unregister_scoped_config(uint64_t p_thread_id, uint64_t p_guard_id)
override;
213 void _clear_scoped_configs()
override;
215 std::array<GeometryGenerator::GeneratedMeshData, (int)MeshMaterialVariant::MAX> *get_shared_meshes();
216 DebugDraw3D::ViewportToDebugContainerItem *get_debug_container(
const DebugDraw3DScopeConfig::DebugContainerDependent &p_dgcd,
const bool p_generate_new_container);
217 void _deferred_find_world_in_viewport(uint64_t p_viewport_id);
218 void _register_viewport_world_deferred(uint64_t p_viewport_id,
const uint64_t p_world_id, _DD3D_WorldWatcher *watcher);
219 Node *_get_root_world_node(Node *p_scene_root, Viewport *p_vp);
220 void _remove_debug_container(
const uint64_t &p_world_id);
222 _FORCE_INLINE_ Vector3 get_up_vector(
const Vector3 &p_dir);
223 void add_or_update_line_with_thickness(real_t p_exp_time,
const Vector3 *p_lines,
const size_t p_line_count,
const Color &p_col,
const std::function<
void(DelayedRendererLine *)> p_custom_upd =
nullptr);
224 Node *get_root_node();
226 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);
227 void create_capsule(
const Transform3D &p_xf,
const Vector3 &p_center,
const Vector3 &p_top_cap,
const Vector3 &p_bottom_cap,
const real_t &p_radius,
const real_t &p_height,
const Color &p_color,
const real_t &p_duration = 0);
230 void _save_generated_meshes();
235 void init(DebugDrawManager *p_root);
237 void set_custom_editor_viewport(std::vector<SubViewport *> p_viewports);
238 std::vector<SubViewport *> get_custom_editor_viewports();
240 Ref<ShaderMaterial> get_material_variant(MeshMaterialType p_type, MeshMaterialVariant p_var);
242 void _load_materials();
243 inline bool _is_enabled_override()
const;
245 void process_start(
double delta);
246 void process_end(
double delta);
247 void physics_process_start(
double p_delta);
248 void physics_process_end(
double p_delta);
250#pragma region Exposed Parameter Values
253 bool debug_enabled =
true;
255 Ref<DebugDraw3DConfig> config;
261 static void _bind_methods();
274#pragma region Configs
301#pragma region Exposed Parameters
303 void set_empty_color(
const godot::Color &col) {}
313 NAPI
bool is_debug_enabled()
const;
317#pragma region Exposed Draw Methods
333#ifndef DISABLE_DEBUG_RENDERING
334#define FAKE_FUNC_IMPL
336#define FAKE_FUNC_IMPL \
353#pragma region Spheres
356 void draw_sphere_base(
const godot::Transform3D &transform,
const godot::Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
367 NAPI
void draw_sphere(const godot::Vector3 &position, const real_t &radius = 0.5f, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
377 NAPI
void draw_sphere_xf(const godot::Transform3D &transform, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
381#pragma region Cylinders
402 NAPI
void draw_capsule(
const godot::Vector3 &position,
const godot::Quaternion &rotation,
const real_t &radius,
const real_t &height,
const godot::Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
418 NAPI
void draw_capsule_ab(const godot::Vector3 &a, const godot::Vector3 &b, const real_t &radius = 0.5f, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
429 NAPI
void draw_cylinder(const godot::Transform3D &transform, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
445 NAPI
void draw_cylinder_ab(const godot::Vector3 &a, const godot::Vector3 &b, const real_t &radius = 0.5f, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
465 NAPI
void draw_box(
const godot::Vector3 &position,
const godot::Quaternion &rotation,
const godot::Vector3 &size,
const godot::Color &color = Colors::empty_color,
const bool &is_box_centered =
false,
const real_t &duration = 0) FAKE_FUNC_IMPL;
484 NAPI
void draw_box_ab(const godot::Vector3 &a, const godot::Vector3 &b, const godot::Vector3 &up, const godot::Color &color = Colors::empty_color, const
bool &is_ab_diagonal = true, const real_t &duration = 0) FAKE_FUNC_IMPL;
494 NAPI
void draw_box_xf(const godot::Transform3D &transform, const godot::Color &color = Colors::empty_color, const
bool &is_box_centered = true, const real_t &duration = 0) FAKE_FUNC_IMPL;
503 NAPI
void draw_aabb(const godot::AABB &aabb, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
513 NAPI
void draw_aabb_ab(const godot::Vector3 &a, const godot::Vector3 &b, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
535 NAPI
void draw_line_hit(
const godot::Vector3 &start,
const godot::Vector3 &end,
const godot::Vector3 &hit,
const bool &is_hit,
const real_t &hit_size = 0.25f,
const godot::Color &hit_color = Colors::empty_color,
const godot::Color &after_hit_color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
553 NAPI
void draw_line_hit_offset(const godot::Vector3 &start, const godot::Vector3 &end, const
bool &is_hit, const real_t &unit_offset_of_hit = 0.5f, const real_t &hit_size = 0.25f, const godot::Color &hit_color = Colors::empty_color, const godot::Color &after_hit_color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
567 NAPI
void draw_line(
const godot::Vector3 &a,
const godot::Vector3 &b,
const godot::Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
580 NAPI
void draw_ray(const godot::Vector3 &origin, const godot::Vector3 &direction, const real_t &length, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
591 void draw_lines(const godot::PackedVector3Array &lines, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
594 NAPI
void draw_lines_c(const godot::Vector3 *lines_data, const uint64_t &lines_size, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
610 void draw_line_path(const godot::PackedVector3Array &path, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
613 NAPI
void draw_line_path_c(const godot::Vector3 *path_data, const uint64_t &path_size, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
626 NAPI
void draw_arrowhead(
const godot::Transform3D &transform,
const godot::Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
643 NAPI
void draw_arrow(const godot::Vector3 &a, const godot::Vector3 &b, const godot::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;
656 NAPI
void draw_arrow_ray(const godot::Vector3 &origin, const godot::Vector3 &direction, const real_t &length, const godot::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;
672 void draw_arrow_path(const godot::PackedVector3Array &path, const godot::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;
675 NAPI
void draw_arrow_path_c(const godot::Vector3 *path_data, const uint64_t &path_size, const godot::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;
697 void draw_point_path(
const godot::PackedVector3Array &path,
const DebugDraw3D::PointType type = PointType::POINT_TYPE_SQUARE,
const real_t &size = 0.25f,
const godot::Color &points_color = Colors::empty_color,
const godot::Color &lines_color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
700 NAPI
void draw_point_path_c(const godot::Vector3 *path_data, const uint64_t &path_size, const DebugDraw3D::
PointType type =
PointType::POINT_TYPE_SQUARE, const real_t &size = 0.25f, const godot::Color &points_color = Colors::empty_color, const godot::Color &lines_color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
718 void draw_points(
const godot::PackedVector3Array &points,
const DebugDraw3D::PointType type = DebugDraw3D::PointType::POINT_TYPE_SQUARE,
const real_t &size = 0.25f,
const godot::Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
721 NAPI
void draw_points_c(const godot::Vector3 *points_data, const uint64_t &points_size, const DebugDraw3D::
PointType type = DebugDraw3D::
PointType::POINT_TYPE_SQUARE, const real_t &size = 0.25f, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
731 NAPI
void draw_square(const godot::Vector3 &position, const real_t &size = 0.2f, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
745 NAPI
void draw_plane(const godot::Plane &plane, const godot::Color &color = Colors::empty_color, const godot::Vector3 &anchor_point = godot::Vector3(INFINITY, INFINITY, INFINITY), const real_t &duration = 0) FAKE_FUNC_IMPL;
756 NAPI
void draw_position(const godot::Transform3D &transform, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
770 NAPI
void draw_gizmo(const godot::Transform3D &transform, const godot::Color &color = Colors::empty_color, const
bool &is_centered = false, const real_t &duration = 0) FAKE_FUNC_IMPL;
785 NAPI
void draw_grid(const godot::Vector3 &origin, const godot::Vector3 &x_size, const godot::Vector3 &y_size, const godot::Vector2i &subdivision, const godot::Color &color = Colors::empty_color, const
bool &is_centered = true, const real_t &duration = 0) FAKE_FUNC_IMPL;
798 NAPI
void draw_grid_xf(const godot::Transform3D &transform, const godot::Vector2i &p_subdivision, const godot::Color &color = Colors::empty_color, const
bool &is_centered = true, const real_t &duration = 0) FAKE_FUNC_IMPL;
800#pragma region Camera Frustum
811 NAPI
void draw_camera_frustum(
const class godot::Camera3D *camera,
const godot::Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
820 void draw_camera_frustum_planes(const godot::Array &camera_frustum, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
823 NAPI
void draw_camera_frustum_planes_c(const godot::Plane *camera_frustum_data, const uint64_t camera_frustum_size, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;
844 void draw_text(
const godot::Vector3 &position,
const godot::String text,
const int size = 32,
const godot::Color &color = Colors::empty_color,
const real_t &duration = 0) FAKE_FUNC_IMPL;
847 NAPI
void draw_text_c(const godot::Vector3 &position, const
char *text_string, const
int size = 32, const godot::Color &color = Colors::empty_color, const real_t &duration = 0) FAKE_FUNC_IMPL;