Debug Draw 3D (and 2D) 1.4.5
Draw 3D debug graphics and 2D overlays with this add-on.
Loading...
Searching...
No Matches
DebugDraw3D Class Reference

Singleton class for calling debugging 3D methods. More...

#include <debug_draw_3d.h>

Inheritance diagram for DebugDraw3D:

Public Types

enum  PointType : int {
  POINT_TYPE_SQUARE ,
  POINT_TYPE_SPHERE
}
 

Public Member Functions

Ref< DebugDraw3DScopeConfignew_scoped_config ()
 
Ref< DebugDraw3DScopeConfigscoped_config () override
 
void set_config (Ref< DebugDraw3DConfig > cfg)
 
Ref< DebugDraw3DConfigget_config () const
 
Color get_empty_color () const
 
void set_debug_enabled (const bool &state)
 
bool is_debug_enabled () const
 
Ref< DebugDraw3DStatsget_render_stats ()
 
Ref< DebugDraw3DStatsget_render_stats_for_world (Viewport *viewport)
 
void regenerate_geometry_meshes ()
 
void clear_all ()
 
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
 
void draw_sphere_xf (const Transform3D &transform, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 
void draw_cylinder (const Transform3D &transform, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 
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
 
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
 
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
 
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
 
void draw_aabb (const AABB &aabb, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 
void draw_aabb_ab (const Vector3 &a, const Vector3 &b, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 
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
 
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
 
void draw_line (const Vector3 &a, const Vector3 &b, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 
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
 
void draw_lines (const PackedVector3Array &lines, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 
void draw_line_path (const PackedVector3Array &path, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 
void draw_arrowhead (const Transform3D &transform, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
void draw_position (const Transform3D &transform, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 
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
 
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
 
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
 
void draw_camera_frustum (const class godot::Camera3D *camera, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 
void draw_camera_frustum_planes (const Array &camera_frustum, const Color &color=Colors::empty_color, const real_t &duration=0) FAKE_FUNC_IMPL
 

Static Public Member Functions

static DebugDraw3Dget_singleton ()
 

Detailed Description

Singleton class for calling debugging 3D methods.

You can use the project settings debug_draw_3d/settings/3d for additional customization.

For example, add_bevel_to_volumetric_geometry allows you to remove or add a bevel for volumetric lines.

use_icosphere and use_icosphere_for_hd allow you to change the sphere mesh.

Note
Wireframe shapes and volumetric wireframes do not support translucency to avoid overlap issues and for better performance. At this point, you can use translucency when drawing planes DebugDraw3D.draw_plane.

Note
Objects created in _physics_process are processed separately from those created in _process, so they will be deleted only in the first physics tick after rendering. This allows to display objects even if several frames passed between physics ticks.

Note
You can use this class anywhere, including in _physics_process and _process (and probably from other threads). It is worth mentioning that physics ticks may not be called every frame or may be called several times in one frame. So if you want to avoid multiple identical draw_ calls, you can call draw_ methods in _process or use such a check:
var physics_tick_processed := false
func _process(delta: float) -> void:
# Reset after rendering frame
physics_tick_processed = false
# some logic
func _physics_process(delta: float) -> void:
if not physics_tick_processed:
physics_tick_processed = true
# some DD3D logic

Note
Due to the way Godot registers this addon, it is not possible to use the draw_ methods in the first few frames immediately after the project is launched.

Member Enumeration Documentation

◆ PointType

Appearance of points on the path

Member Function Documentation

◆ get_singleton()

static DebugDraw3D * DebugDraw3D::get_singleton ( )
inlinestatic

Get singleton. Not available in GDScript.

◆ new_scoped_config()

Ref< DebugDraw3DScopeConfig > DebugDraw3D::new_scoped_config ( )

Create a new DebugDraw3DScopeConfig instance and register it.

This class allows you to override some parameters within scope for the following draw_* calls.

Store this instance in a local variable inside the method.

◆ scoped_config()

Ref< DebugDraw3DScopeConfig > DebugDraw3D::scoped_config ( )
override

Returns the default scope settings that will be applied at the start of each new frame.

Default values can be overridden in the project settings debug_draw_3d/settings/3d/volumetric_defaults.

◆ set_config()

void DebugDraw3D::set_config ( Ref< DebugDraw3DConfig > cfg)

Set the configuration global for everything in DebugDraw3D.

◆ get_config()

Ref< DebugDraw3DConfig > DebugDraw3D::get_config ( ) const

◆ get_empty_color()

Color DebugDraw3D::get_empty_color ( ) const

Get the color that is used as the default parameter for draw_* calls.

◆ set_debug_enabled()

void DebugDraw3D::set_debug_enabled ( const bool & state)

Set whether debug drawing works or not.

◆ get_render_stats()

Ref< DebugDraw3DStats > DebugDraw3D::get_render_stats ( )

Returns an instance of DebugDraw3DStats with the current statistics.

Some data can be delayed by 1 frame.

◆ get_render_stats_for_world()

Ref< DebugDraw3DStats > DebugDraw3D::get_render_stats_for_world ( Viewport * viewport)

Returns an instance of DebugDraw3DStats with the current statistics for the World3D of the Viewport.

Some data can be delayed by 1 frame.

◆ regenerate_geometry_meshes()

void DebugDraw3D::regenerate_geometry_meshes ( )

Regenerate meshes.

Can be useful if you want to change some project settings and not restart the project.

◆ clear_all()

void DebugDraw3D::clear_all ( )

Clear all 3D geometry

◆ draw_sphere()

void DebugDraw3D::draw_sphere ( const Vector3 & position,
const real_t & radius = 0.5f,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw a sphere

Parameters
positionCenter of the sphere
radiusSphere radius
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_sphere_xf()

void DebugDraw3D::draw_sphere_xf ( const Transform3D & transform,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw a sphere with a radius of 0.5

Parameters
transformSphere transform
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_cylinder()

void DebugDraw3D::draw_cylinder ( const Transform3D & transform,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw a vertical cylinder with radius 0.5 and height 1.0

Parameters
transformCylinder transform
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_cylinder_ab()

void DebugDraw3D::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 )

Draw a cylinder between points A and B with a certain radius

Parameters
aBottom point of the Cylinder
bTop point of the Cylinder
radiusCylinder radius
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_box()

void DebugDraw3D::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 )

Draw a box

is_box_centered = true
is_box_centered = false
Parameters
positionPosition of the Box
rotationRotation of the box
sizeSize of the Box
colorPrimary color
is_box_centeredSet where the center of the box will be. In the center or in the bottom corner
durationThe duration of how long the object will be visible

◆ draw_box_ab()

void DebugDraw3D::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 )

Draw a box between points A and B by rotating and scaling based on the up vector

is_ab_diagonal = true
is_ab_diagonal = false
Parameters
aStart position
bEnd position
upVertical vector by which the box will be aligned
colorPrimary color
is_ab_diagonalSet uses the diagonal between the corners or the diagonal between the centers of two edges
durationThe duration of how long the object will be visible

◆ draw_box_xf()

void DebugDraw3D::draw_box_xf ( const Transform3D & transform,
const Color & color = Colors::empty_color,
const bool & is_box_centered = true,
const real_t & duration = 0 )

Draw a box as in DebugDraw3D.draw_box

Parameters
transformBox transform
colorPrimary color
is_box_centeredSet where the center of the box will be. In the center or in the bottom corner
durationThe duration of how long the object will be visible

◆ draw_aabb()

void DebugDraw3D::draw_aabb ( const AABB & aabb,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw a box as in DebugDraw3D.draw_box, but based on the AABB

Parameters
aabbAABB
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_aabb_ab()

void DebugDraw3D::draw_aabb_ab ( const Vector3 & a,
const Vector3 & b,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw the box as in DebugDraw3D.draw_aabb, but AABB is defined by the diagonal AB

Parameters
aStart position
bEnd position
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_line_hit()

void DebugDraw3D::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 )

Draw line separated by hit point (billboard square) or not separated if is_hit = false.

Some of the default settings can be overridden in DebugDraw3DConfig.

Parameters
startStart point
endEnd point
hitHit point
is_hitWhether to draw the collision point
hit_sizeSize of the hit point
hit_colorColor of the hit point and line before hit
after_hit_colorColor of line after hit position
durationThe duration of how long the object will be visible

◆ draw_line_hit_offset()

void DebugDraw3D::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 )

Draw line separated by hit point.

Similar to DebugDraw3D.draw_line_hit, but instead of a hit point, an offset from the start point is used.

Some of the default settings can be overridden in DebugDraw3DConfig.

Parameters
startStart point
endEnd point
is_hitWhether to draw the collision point
unit_offset_of_hitUnit offset on the line where the collision occurs
hit_sizeSize of the hit point
hit_colorColor of the hit point and line before hit
after_hit_colorColor of line after hit position
durationThe duration of how long the object will be visible

◆ draw_line()

void DebugDraw3D::draw_line ( const Vector3 & a,
const Vector3 & b,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw a single line

Parameters
aStart point
bEnd point
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_ray()

void DebugDraw3D::draw_ray ( const Vector3 & origin,
const Vector3 & direction,
const real_t & length,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw a ray.

Same as DebugDraw3D.draw_line, but uses origin, direction and length instead of A and B.

Parameters
originOrigin
directionDirection
lengthLength
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_lines()

void DebugDraw3D::draw_lines ( const PackedVector3Array & lines,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw an array of lines. Each line is two points, so the array must be of even size.

Parameters
linesAn array of points of lines. 1 line = 2 vectors3. The array size must be even.
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_line_path()

void DebugDraw3D::draw_line_path ( const PackedVector3Array & path,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw an array of lines.

Unlike DebugDraw3D.draw_lines, here lines are drawn between each point in the array.

The array can be of any size.

Parameters
pathSequence of points
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_arrowhead()

void DebugDraw3D::draw_arrowhead ( const Transform3D & transform,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw the arrowhead

Parameters
transformTransform3D of the Arrowhead
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_arrow()

void DebugDraw3D::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 )

Draw line with arrowhead

Parameters
aStart point
bEnd point
colorPrimary color
arrow_sizeSize of the arrow
is_absolute_sizeIs arrow_size absolute or relative to the length of the string?
durationThe duration of how long the object will be visible

◆ draw_arrow_ray()

void DebugDraw3D::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 )

Same as DebugDraw3D.draw_arrow, but uses origin, direction and length instead of A and B.

Parameters
originOrigin
directionDirection
lengthLength
colorPrimary color
arrow_sizeSize of the arrow
is_absolute_sizeIs arrow_size absolute or relative to the line length?
durationThe duration of how long the object will be visible

◆ draw_arrow_path()

void DebugDraw3D::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 )

Draw a sequence of points connected by lines with arrows like DebugDraw3D.draw_line_path.

Parameters
pathSequence of points
colorPrimary color
arrow_sizeSize of the arrow
is_absolute_sizeIs the arrow_size absolute or relative to the length of the line?
durationThe duration of how long the object will be visible

◆ draw_point_path()

void DebugDraw3D::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 )

Draw a sequence of points connected by lines using billboard squares or spheres like DebugDraw3D.draw_line_path.

type = DebugDraw3D.POINT_TYPE_SQUARE
type = DebugDraw3D.POINT_TYPE_SPHERE
Parameters
pathSequence of points
typeType of points
points_colorColor of points
lines_colorColor of lines
sizeSize of squares
durationThe duration of how long the object will be visible

◆ draw_points()

void DebugDraw3D::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 )

Draw a sequence of points using billboard squares or spheres.

Parameters
pointsSequence of points
typeType of points
sizeSize of squares
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_square()

void DebugDraw3D::draw_square ( const Vector3 & position,
const real_t & size = 0.2f,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw a square that will always be turned towards the camera

Parameters
positionCenter position of square
sizeSquare size
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_plane()

void DebugDraw3D::draw_plane ( const Plane & plane,
const Color & color = Colors::empty_color,
const Vector3 & anchor_point = Vector3(INFINITY, INFINITY, INFINITY),
const real_t & duration = 0 )

Draws a plane of non-infinite size relative to the position of the current camera.

The plane size is set based on the Far parameter of the current camera or with DebugDraw3DScopeConfig.set_plane_size.

Parameters
planePlane data
colorPrimary color
anchor_pointA point that is projected onto a Plane, and its projection is used as the center of the drawn plane
durationThe duration of how long the object will be visible

◆ draw_position()

void DebugDraw3D::draw_position ( const Transform3D & transform,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw 3 intersecting lines with the given transformations

Parameters
transformTransform3D of lines
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_gizmo()

void DebugDraw3D::draw_gizmo ( const Transform3D & transform,
const Color & color = Colors::empty_color,
const bool & is_centered = false,
const real_t & duration = 0 )

Draw 3 lines with the given transformations and arrows at the ends

is_centered = false
is_centered = true
Parameters
transformTransform3D of lines
colorPrimary color
is_centeredIf true, then the lines will intersect in the center of the transform
durationThe duration of how long the object will be visible

◆ draw_grid()

void DebugDraw3D::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 )

Draw simple grid with given size and subdivision

Parameters
originGrid origin
x_sizeDirection and size of the X side. As an axis in the Basis.
y_sizeDirection and size of the Y side. As an axis in the Basis.
subdivisionNumber of cells for the X and Y axes
colorPrimary color
is_centeredDraw lines relative to origin
durationThe duration of how long the object will be visible

◆ draw_grid_xf()

void DebugDraw3D::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 )

Draw a simple grid with a given transform and subdivision.

Like DebugDraw3D.draw_grid, but instead of origin, x_size and y_size, a single transform is used.

Parameters
transformTransform3D of the Grid
p_subdivisionNumber of cells for the X and Y axes
colorPrimary color
is_centeredDraw lines relative to origin
durationThe duration of how long the object will be visible

◆ draw_camera_frustum()

void DebugDraw3D::draw_camera_frustum ( const class godot::Camera3D * camera,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw camera frustum area.

Parameters
cameraCamera node
colorPrimary color
durationThe duration of how long the object will be visible

◆ draw_camera_frustum_planes()

void DebugDraw3D::draw_camera_frustum_planes ( const Array & camera_frustum,
const Color & color = Colors::empty_color,
const real_t & duration = 0 )

Draw the frustum area of the camera based on an array of 6 planes.

Parameters
camera_frustumArray of frustum planes
colorPrimary color
durationThe duration of how long the object will be visible

The documentation for this class was generated from the following file: