Skip to content

Commit

Permalink
many fixes
Browse files Browse the repository at this point in the history
added draw_cylinder_ab
added normals and uvs to geometry
added shading to the volumetric geometry
removed useless methods from Utils
added tracy profiler
  • Loading branch information
DmitriySalnikov committed Dec 1, 2023
1 parent 9624b0f commit 76a8479
Show file tree
Hide file tree
Showing 43 changed files with 966 additions and 408 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
path = godot-cpp
url = https://github.com/godotengine/godot-cpp.git
branch = 3.4


[submodule "src/thirdparty/tracy"]
path = src/thirdparty/tracy
url = https://github.com/wolfpld/tracy.git
4 changes: 2 additions & 2 deletions addons/debug_draw_3d/debug_draw_3d.gdextension
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ macos.template_release = { }
windows.template_release.x86_64 = { }
linux.template_release.x86_64 = { }

web.template_release.wasm32 = {}
web.template_release.wasm32 = { }

android.template_release.arm32 = { }
android.template_release.arm64 = { }
Expand All @@ -40,7 +40,7 @@ macos.template_release.forced_dd3d = { }
windows.template_release.x86_64.forced_dd3d = { }
linux.template_release.x86_64.forced_dd3d = { }

web.template_release.wasm32.forced_dd3d = {}
web.template_release.wasm32.forced_dd3d = { }

[libraries]

Expand Down
6 changes: 3 additions & 3 deletions dev_build_godot_cpp.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ git apply --ignore-space-change --ignore-whitespace ../patches/unity_build.patch
::git apply --ignore-space-change --ignore-whitespace ../patches/debug_string.patch

title win x64 debug dev
scons platform=windows target=editor arch=x86_64 dev_build=yes debug_symbols=yes generate_bindings=yes %api%
scons platform=windows target=editor arch=x86_64 dev_build=yes %api% generate_bindings=yes
if errorlevel 1 ( echo Failed to generate and compile debug godot-cpp source code. Code: %errorlevel% && exit /b %errorlevel% )

title win x64 debug
Expand All @@ -20,9 +20,9 @@ scons platform=windows target=template_release arch=x86_64 debug_symbols=no %api
if errorlevel 1 ( echo Failed to compile Windows godot-cpp for x64. Code: %errorlevel% && exit /b %errorlevel% )

title android arm64v8 debug
scons platform=android target=template_debug arch=arm64v8 %api%
scons platform=android target=template_debug arch=arm64v8 ANDROID_HOME="" %api%
if errorlevel 1 ( echo Failed to compile debug Android godot-cpp for arm64v8. Code: %errorlevel% && exit /b %errorlevel% )

title android arm64v8
scons platform=android target=template_release arch=arm64v8 %api%
scons platform=android target=template_release arch=arm64v8 ANDROID_HOME="" %api%
if errorlevel 1 ( echo Failed to compile Android godot-cpp for arm64v8. Code: %errorlevel% && exit /b %errorlevel% )
42 changes: 23 additions & 19 deletions examples_dd3d/DebugDrawDemoScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,12 @@ func _update_keys_just_press():

func _process(delta: float) -> void:
DebugDraw3D.scoped_config().set_thickness(debug_thickness)
if false: #test
print("def ", DebugDraw3D.scoped_config().get_thickness())
if true: #test
var s11 = DebugDraw3D.new_scoped_config()
print("over ", s11.get_thickness())
s11.set_thickness(1)
print("over changed ", s11.get_thickness())
print("def recheck ", DebugDraw3D.scoped_config().get_thickness())
if true:
var s13 = DebugDraw3D.new_scoped_config()
s13.set_thickness(2)
print("scope ", s13.get_thickness())
print("def recheck 2 ", DebugDraw3D.scoped_config().get_thickness())
print("over recheck ", s11.get_thickness())
s13.set_thickness(3)

_update_keys_just_press()

Expand Down Expand Up @@ -127,12 +120,13 @@ func _process(delta: float) -> void:
if !Engine.is_editor_hint():
get_viewport().msaa_3d = Viewport.MSAA_DISABLED if get_viewport().msaa_3d == Viewport.MSAA_4X else Viewport.MSAA_4X

if _is_key_just_pressed(KEY_1):
DebugDraw3D.debug_enabled = !DebugDraw3D.debug_enabled
if _is_key_just_pressed(KEY_2):
DebugDraw2D.debug_enabled = !DebugDraw2D.debug_enabled
if _is_key_just_pressed(KEY_3):
DebugDrawManager.debug_enabled = !DebugDrawManager.debug_enabled
if !Engine.is_editor_hint():
if _is_key_just_pressed(KEY_1):
DebugDraw3D.debug_enabled = !DebugDraw3D.debug_enabled
if _is_key_just_pressed(KEY_2):
DebugDraw2D.debug_enabled = !DebugDraw2D.debug_enabled
if _is_key_just_pressed(KEY_3):
DebugDrawManager.debug_enabled = !DebugDrawManager.debug_enabled


if Engine.is_editor_hint():
Expand All @@ -156,8 +150,9 @@ func _process(delta: float) -> void:
time -= delta

# Cylinders
DebugDraw3D.draw_cylinder($Cylinder1.global_transform, Color.CRIMSON)
DebugDraw3D.draw_cylinder(Transform3D(Basis.IDENTITY, $Cylinder2.global_transform.origin).scaled(Vector3(1,2,1)), Color.RED)
DebugDraw3D.draw_cylinder($Cylinders/Cylinder1.global_transform, Color.CRIMSON)
DebugDraw3D.draw_cylinder(Transform3D(Basis.IDENTITY.scaled(Vector3(1,2,1)), $Cylinders/Cylinder2.global_position), Color.RED)
DebugDraw3D.draw_cylinder_ab($"Cylinders/Cylinder3/1".global_position, $"Cylinders/Cylinder3/2".global_position, 0.35)

# Boxes
DebugDraw3D.draw_box_xf($Box1.global_transform, Color.MEDIUM_PURPLE)
Expand All @@ -181,6 +176,9 @@ func _process(delta: float) -> void:
time3 = 2
time3 -= delta

# Test UP vector
DebugDraw3D.draw_line($"Lines/7".global_transform.origin, target.global_transform.origin, Color.RED)

# Lines with Arrow
DebugDraw3D.draw_arrow_line($"Lines/2".global_transform.origin, target.global_transform.origin, Color.BLUE, 0.5, true)
DebugDraw3D.draw_arrow_ray($"Lines/4".global_transform.origin, (target.global_transform.origin - $"Lines/4".global_transform.origin).normalized(), 8.0, Color.LAVENDER, 0.5, true)
Expand Down Expand Up @@ -212,8 +210,10 @@ func _process(delta: float) -> void:
DebugDraw3D.draw_point_path(points_below3, 0.25, Color.BLUE, Color.TOMATO)

# Misc
#for i in 1000:
DebugDraw3D.draw_camera_frustum($Camera, Color.DARK_ORANGE)
if true:
#for i in 1000:
var a11 = DebugDraw3D.new_scoped_config().set_thickness(0)
DebugDraw3D.draw_camera_frustum($Camera, Color.DARK_ORANGE)

DebugDraw3D.draw_arrow($Misc/Arrow.global_transform, Color.YELLOW_GREEN)

Expand Down Expand Up @@ -309,6 +309,10 @@ func _text_tests():
DebugDraw2D.set_text("Filling lines buffer", "%.2f ms" % (render_stats.time_filling_buffers_lines_usec / 1000.0), 9)
DebugDraw2D.set_text("Filling time", "%.2f ms" % (render_stats.total_time_filling_buffers_usec / 1000.0), 10)
DebugDraw2D.set_text("Total time", "%.2f ms" % (render_stats.total_time_spent_usec / 1000.0), 11)

DebugDraw2D.set_text("---", null, 14)

DebugDraw2D.set_text("Created scoped configs", "%d" % render_stats.created_scoped_configs, 15)

if text_groups_show_stats && text_groups_show_stats_2d:
DebugDraw2D.set_text("----", null, 19)
Expand Down
41 changes: 35 additions & 6 deletions examples_dd3d/DebugDrawDemoScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ process_priority = 1
script = ExtResource("1")
custom_font = ExtResource("2_aedbq")
draw_array_of_boxes = true
debug_thickness = 0.075
start_culling_distance = 55.0
text_groups_show_stats = true
text_groups_position = 2
text_groups_default_font_size = 15
text_groups_title_font_size = 20
Expand Down Expand Up @@ -288,6 +290,18 @@ libraries = {
"": SubResource("AnimationLibrary_nj4nv")
}
[node name="Label3D" type="Label3D" parent="."]
transform = Transform3D(1, -1.93359e-07, -8.48396e-08, -1.17881e-07, 1, 5.96046e-08, 6.22839e-09, 0, 1, 0, 0, 0)
visible = false
pixel_size = 0.0025
billboard = 1
double_sided = false
modulate = Color(0, 0, 0, 1)
outline_modulate = Color(1, 1, 1, 1)
text = "TestTestTestTest
TestTestTest"
font_size = 80
[node name="LinePath" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.67362, -8)
Expand All @@ -311,14 +325,26 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, -1)
[node name="Spatial7" type="Node3D" parent="LinePath"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0)
[node name="Cylinder1" type="Node3D" parent="."]
transform = Transform3D(1.30832, 0.213863, -3.73947e-07, 0.60031, -0.408523, 0.929687, 0.225355, -0.153359, -2.47654, -25.6488, 0, -6.39029)
[node name="Cylinders" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -23.5266, 4.76837e-07, -5.82213)
[node name="Cylinder1" type="Node3D" parent="Cylinders"]
transform = Transform3D(1.20775, 0.591481, -3.4521e-07, 0.554162, -1.12986, 0.858242, 0.208031, -0.424147, -2.28622, -3.03832, 0, -0.377882)
[node name="Cylinder2" type="Node3D" parent="Cylinders"]
transform = Transform3D(0.667622, 0.306331, 0.114996, 0.327448, -0.625499, -0.23481, -5.73853e-08, 0.143919, -0.383377, 0.234978, -0.4237, 0.332998)
[node name="Cylinder2" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -22.134, -9.53674e-07, -6.39029)
[node name="Cylinder3" type="Node3D" parent="Cylinders"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.35527, -0.655492, -0.352802)
[node name="1" type="Node3D" parent="Cylinders/Cylinder3"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.419773, -2.38419e-07, -1.40591)
[node name="2" type="Node3D" parent="Cylinders/Cylinder3"]
transform = Transform3D(1, -1.93359e-07, -8.48396e-08, -1.17881e-07, 1, 5.96046e-08, 6.22839e-09, 0, 1, 1.01018, 0.486778, 1.32635)
[node name="SphereTransform" type="Node3D" parent="."]
transform = Transform3D(3.018, 0, 0, 0, 0.945452, -0.636291, 0, 1.04515, 4.40664, -14.547, 0.166728, -5.65327)
transform = Transform3D(3.018, 0, 0, 0, 0.945452, -3.30182, 0, 1.04515, 2.98686, -14.547, 0.166728, -5.65327)
[node name="SphereHDTransform" type="Node3D" parent="."]
transform = Transform3D(1.26984, 1.16629, -2.42095, 0.098772, 0.80937, 4.21576, -2.65493, 0.587941, -1.00109, -14.5341, 0.166728, -10.3981)
Expand Down Expand Up @@ -408,8 +434,11 @@ transform = Transform3D(-0.998871, -0.0207882, -0.0355643, 0.0855375, -0.5714, -
[node name="6" type="Node3D" parent="Lines"]
transform = Transform3D(-0.998872, -0.0207882, -0.0355643, 0.0855371, -0.5714, -2.68836, 0.0136012, -0.249864, 0.572533, 1.43441, 1.50606, 1.20028)
[node name="7" type="Node3D" parent="Lines"]
transform = Transform3D(-0.998873, -0.0207882, -0.0355641, 0.0855357, -0.5714, -2.68836, 0.0136014, -0.249864, 0.572533, 0.0511096, -1.3236, 1.06745)
[node name="Target" type="Node3D" parent="Lines"]
transform = Transform3D(1, -2.7352e-06, 2.60722e-07, 3.30799e-06, 1, 0, -3.51517e-07, -1.49012e-08, 1, -0.69134, 0.176476, 1.30597)
transform = Transform3D(1, -2.7352e-06, 2.60722e-07, 3.7807e-06, 1, 0, -3.59182e-07, -1.49012e-08, 1, -0.69134, 0.176476, 1.30597)
[node name="HitTest" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.48967, -1.03227, 9.524)
Expand Down
1 change: 1 addition & 0 deletions examples_dd3d/addon_icon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extends Node3D

func _process(delta: float) -> void:
var a = DebugDraw3D.new_scoped_config().set_thickness(0.015)
DebugDraw3D.draw_box_xf($box.global_transform, Color.GREEN)
DebugDraw3D.draw_gizmo($gizmo.global_transform)
DebugDraw3D.draw_grid_xf($gizmo/grid.global_transform, Vector2i(2,2), DebugDraw3D.empty_color, false)
Expand Down
2 changes: 1 addition & 1 deletion examples_dd3d/addon_icon.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ transform = Transform3D(1, -2.98023e-08, 1.19209e-07, 0, 1, 0, 1.19209e-07, -2.9
transform = Transform3D(0.401341, 0.207831, -0.437109, -0.449118, 0.371584, -0.235691, 0.180418, 0.46267, 0.385639, 0.466197, 0.322665, 0.200436)

[node name="cylinder" type="Node3D" parent="."]
transform = Transform3D(0.155339, 0.116074, -0.113004, -0.160317, 0.13264, -0.0841321, 0.0232731, 0.138948, 0.174714, -0.0566943, -0.290515, 0.905274)
transform = Transform3D(0.155034, 0.231693, -0.112783, -0.160003, 0.264761, -0.0839674, 0.0232275, 0.277352, 0.174372, -0.0566943, -0.290515, 0.905274)

[node name="line" type="Node3D" parent="."]

Expand Down
21 changes: 13 additions & 8 deletions lib_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def setup_options(env, arguments, gen_help):

opts = Variables([], arguments)

opts.Add(BoolVariable("tracy_enabled", "Enable tracy profiler", False))
opts.Add(BoolVariable("force_enabled_dd3d", "Keep the rendering code in the release build", False))
opts.Add(BoolVariable("lto", "Link-time optimization", False))
opts.Add(PathVariable("addon_output_dir", "Path to the output directory", output_dir, PathVariable.PathIsDirCreate))
Expand All @@ -23,7 +24,7 @@ def setup_options(env, arguments, gen_help):
gen_help(env, opts)


def setup_defines_and_flags(env):
def setup_defines_and_flags(env, src_out):
env.Append(CPPDEFINES=["GDEXTENSION_LIBRARY"])

if "release" in env["target"] and not env["force_enabled_dd3d"]:
Expand All @@ -38,6 +39,13 @@ def setup_defines_and_flags(env):
env.AppendUnique(CCFLAGS=["-flto"])
env.AppendUnique(LINKFLAGS=["-flto"])

if env["tracy_enabled"]:
env.Append(CPPDEFINES=["TRACY_ENABLE"])
env.Append(CPPDEFINES=["TRACY_ON_DEMAND"])
env.Append(CPPDEFINES=["TRACY_DELAYED_INIT"])
env.Append(CPPDEFINES=["TRACY_MANUAL_LIFETIME"])
src_out.append("src/thirdparty/tracy/public/TracyClient.cpp")


def is_file_locked(file_path):
if not os.path.exists(file_path):
Expand Down Expand Up @@ -91,12 +99,9 @@ def replace_flag(arr, flag, new_flag):
def get_library_object(env, arguments=None, gen_help=None):
if arguments != None and gen_help:
setup_options(env, arguments, gen_help)
setup_defines_and_flags(env)

env.Append(CPPPATH=[src_folder])

# replace_flag(env["CXXFLAGS"], "/std:c++17" if env.get("is_msvc", False) else "-std=c++17",
# "/std:c++20" if env.get("is_msvc", False) else "-std=c++20")
additional_src = []
setup_defines_and_flags(env, additional_src)
env.Append(CPPPATH=src_folder)

src = []
with open(src_folder + "/default_sources.json") as f:
Expand Down Expand Up @@ -124,7 +129,7 @@ def get_library_object(env, arguments=None, gen_help=None):
env.Default(
env.SharedLibrary(
target=env.File(Path(env["addon_output_dir"]) / (library_full_name + env["SHLIBSUFFIX"])),
source=get_sources(src),
source=additional_src + get_sources(src),
SHLIBSUFFIX=env["SHLIBSUFFIX"],
)
)
Expand Down
15 changes: 11 additions & 4 deletions src/2d/config_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include <limits.h>

const char *DebugDrawConfig2D::s_marked_dirty = "marked_dirty";

void DebugDrawConfig2D::_bind_methods() {
#ifdef DEV_ENABLED
ClassDB::bind_method(D_METHOD(NAMEOF(api_test1)), &DebugDrawConfig2D::api_test1);
Expand Down Expand Up @@ -37,11 +35,19 @@ void DebugDrawConfig2D::_bind_methods() {
REG_PROP(text_background_color, Variant::COLOR);
REG_PROP(text_custom_font, Variant::OBJECT);

ADD_SIGNAL(MethodInfo(s_marked_dirty));
#undef REG_CLASS_NAME
}

DebugDrawConfig2D::~DebugDrawConfig2D() {
mark_dirty_func = nullptr;
}

void DebugDrawConfig2D::register_config(std::function<void()> p_mark_dirty) {
mark_dirty_func = p_mark_dirty;
}

void DebugDrawConfig2D::unregister_config() {
mark_dirty_func = nullptr;
}

DebugDrawConfig2D::DebugDrawConfig2D() {
Expand All @@ -53,7 +59,8 @@ DebugDrawConfig2D::DebugDrawConfig2D() {
}

void DebugDrawConfig2D::mark_canvas_dirty() {
emit_signal(s_marked_dirty);
if (mark_dirty_func)
mark_dirty_func();
}

void DebugDrawConfig2D::set_graphs_base_offset(const Vector2i &_offset) {
Expand Down
9 changes: 7 additions & 2 deletions src/2d/config_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "common/colors.h"
#include "utils/compiler.h"

#include <functional>

GODOT_WARNING_DISABLE()
#include <godot_cpp/classes/font.hpp>
#include <godot_cpp/classes/ref_counted.hpp>
Expand Down Expand Up @@ -64,15 +66,18 @@ class DebugDrawConfig2D : public RefCounted {

#pragma endregion // Exposed Parameter Values

std::function<void()> mark_dirty_func = nullptr;

protected:
static void _bind_methods();

public:
const static char *s_marked_dirty;

DebugDrawConfig2D();
~DebugDrawConfig2D();

void register_config(std::function<void()> p_mark_dirty);
void unregister_config();

void set_graphs_base_offset(const Vector2i &_offset);
Vector2i get_graphs_base_offset() const;

Expand Down
Loading

0 comments on commit 76a8479

Please sign in to comment.