nicholas-maltbie / godot_debug_draw_3d

Draw 3d debug graphics and 2d overlays with this add-on.

Home Page:https://nickmaltbie.com/godot_debug_draw_3d/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

icon

Debug drawing utility for Godot

This is an add-on for debug drawing in 3D and for some 2D overlays, which is written in C++ and can be used with GDScript or C#.

Based on my previous addon, which was developed only for C#, and which was inspired by Zylann's GDScript addon

Support me

Your support adds motivation to develop my public projects.

qiwi

Boosty

Features

3D:

  • Arrow
  • Billboard opaque square
  • Box
  • Camera Frustum
  • Cylinder
  • Gizmo
  • Grid
  • Line
  • Line Path
  • Line with Arrow
  • Points
  • Position 3D (3 crossing axes)
  • Sphere

2D:

  • [Work in progress]

Overlay:

  • Text (with grouping and coloring)
  • FPS Graph
  • Custom Graphs

Precompiled for:

  • Windows
  • Linux
  • macOS
  • Android
  • Web (WebAssembly)

screenshot_web

Thanks to Nick Maltbie (nicholas-maltbie) (#24)

Warning

  • The web version uses OpenGL, which in Godot 4.1 incorrectly assigns colors to the last rendered geometry instances.
  • Firefox most likely can't run this demo

Download

To download, use the Godot Asset Library or download the archive by clicking the button at the top of the main repository page: Code -> Download ZIP, then unzip it to your project folder. Or use one of the stable versions from the GitHub Releases page (just download one of the Source Codes in assets).

Usage

  • Close editor
  • Copy addons/debug_draw_3d to your addons folder, create it if the folder doesn't exist
  • Launch editor

C#

When you start the engine for the first time, bindings for C# will be generated automatically. If this does not happen, you can manually generate them through the Project - Tools - Debug Draw menu.

project_tools_menu

Examples

More examples can be found in the examples_dd3d/ folder.

Simple test:

func _process(delta: float) -> void:
    var _time = Time.get_ticks_msec() / 1000.0
    var box_pos = Vector3(0, sin(_time * 4), 0)
    var line_begin = Vector3(-1, sin(_time * 4), 0)
    var line_end = Vector3(1, cos(_time * 4), 0)

    DebugDraw3D.draw_box(box_pos, Vector3(1, 2, 1), Color(0, 1, 0))
    DebugDraw3D.draw_line(line_begin, line_end, Color(1, 1, 0))
    DebugDraw2D.set_text("Time", _time)
    DebugDraw2D.set_text("Frames drawn", Engine.get_frames_drawn())
    DebugDraw2D.set_text("FPS", Engine.get_frames_per_second())
    DebugDraw2D.set_text("delta", delta)
public override void _Process(float delta)
{
    var _time = Time.GetTicksMsec() / 1000.0f;
    var box_pos = new Vector3(0, Mathf.Sin(_time * 4f), 0);
    var line_begin = new Vector3(-1, Mathf.Sin(_time * 4f), 0);
    var line_end = new Vector3(1, Mathf.Cos(_time * 4f), 0);

    DebugDraw3D.DrawBox(box_pos, new Vector3(1, 2, 1), new Color(0, 1, 0));
    DebugDraw3D.DrawLine(line_begin, line_end, new Color(1, 1, 0));
    DebugDraw2D.SetText("Time", _time);
    DebugDraw2D.SetText("Frames drawn", Engine.GetFramesDrawn());
    DebugDraw2D.SetText("FPS", Engine.GetFramesPerSecond());
    DebugDraw2D.SetText("delta", delta);
}

screenshot_1

API

A list of all functions is available in the documentation inside the editor. screenshot_4

Besides DebugDraw2D/3D, you can also use Dbg2/3.

    DebugDraw3D.draw_box_xf(Transform3D(), Color.GREEN)
    Dbg3.draw_box_xf(Transform3D(), Color.GREEN)

    DebugDraw2D.set_text("delta", delta)
    Dbg2.set_text("delta", delta)

But unfortunately at the moment GDExtension does not support adding documentation.

Exporting a project

Most likely, when exporting a release version of a game, you don't want to export the debug library along with it. But since there is still no Conditional Compilation in GDScript, so I decided to create a dummy library that has the same API as a regular library, but has minimal impact on performance, even if calls to its methods occur. The dummy library is used by default in the release version. However if you need to use debug rendering in the release version, then you can add the forced_dd3d feature when exporting. In this case, the release library with all the functionality will be used.

export_features

In C#, these tags are not taken into account at compile time, so the Release build will use Runtime checks to disable draw calls. If you want to avoid this, you can manually specify the FORCED_DD3D symbol.

csharp_compilation_symbols

Known issues and limitations

Enabling occlusion culing can lower fps instead of increasing it. At the moment I do not know how to speed up the calculation of the visibility of objects.

The text in the keys and values of a text group cannot contain multi-line strings.

The entire text overlay can only be placed in one corner, unlike DataGraphs.

Frustum of Camera3D does not take into account the window size from ProjectSettings.

OpenGL: The last instance of MultiMesh incorrectly sets the color

The version for Godot 4.0 requires explicitly specifying the exact data types, otherwise errors may occur.

More screenshots

DebugDrawDemoScene.tscn in editor screenshot_2

DebugDrawDemoScene.tscn in play mode screenshot_3

Build

As well as for the engine itself, you will need to configure the environment. And also you need to apply several patches:

cd godot-cpp
git apply --ignore-space-change --ignore-whitespace ../patches/always_build_fix.patch
git apply --ignore-space-change --ignore-whitespace ../patches/1165.patch
# Optional
## Build only the necessary classes
git apply --ignore-space-change --ignore-whitespace ../patches/godot_cpp_exclude_unused_classes.patch
## Faster build
git apply --ignore-space-change --ignore-whitespace ../patches/unity_build.patch
## Fixes for JavaScript/Web support
git apply --ignore-space-change --ignore-whitespace ../patches/fixed_javascript_build.patch

Then you can just run scons as usual:

# build for the current system.
# target=editor is used for both the editor and the debug template.
scons target=editor dev_build=yes debug_symbols=yes
# build for the android. ANDROID_NDK_ROOT is required in your environment variables.
scons platform=android target=template_release arch=arm64v8

JavaScript/Web build

If you have problems running the Web version of your project, you can try using the scripts and tips from this page.

If you too want to add an Interactive Demo to your GitHub repository, then you can see how Nick Maltbie (nicholas-maltbie) added this feature to this repository in PR #24!

In short, you need to activate Extension Support when exporting and add the gzuidhof/coi-serviceworker to the <head> and to the export folder. Then you will need to somehow publish a demo on the GitHub pages, as for example done in #24.

export_web_for_github

About

Draw 3d debug graphics and 2d overlays with this add-on.

https://nickmaltbie.com/godot_debug_draw_3d/

License:Other


Languages

Language:C++ 80.0%Language:C# 8.9%Language:GDScript 6.8%Language:Python 3.4%Language:Batchfile 0.5%Language:C 0.4%