diff --git a/examples_dd3d/DebugDrawDemoScene.gd b/examples_dd3d/DebugDrawDemoScene.gd index 13b3a779..63c306c9 100644 --- a/examples_dd3d/DebugDrawDemoScene.gd +++ b/examples_dd3d/DebugDrawDemoScene.gd @@ -59,6 +59,7 @@ func _update_keys_just_press(): var set_key = func (k: Key): return (1 if button_presses[k] == 0 else button_presses[k]) if Input.is_key_pressed(k) else 0 button_presses[KEY_LEFT] = set_key.call(KEY_LEFT) button_presses[KEY_UP] = set_key.call(KEY_UP) + button_presses[KEY_CTRL] = set_key.call(KEY_CTRL) button_presses[KEY_F1] = set_key.call(KEY_F1) button_presses[KEY_1] = set_key.call(KEY_1) button_presses[KEY_2] = set_key.call(KEY_2) @@ -106,6 +107,9 @@ func _process(delta: float) -> void: DebugDraw3D.config.use_frustum_culling = !DebugDraw3D.config.use_frustum_culling if _is_key_just_pressed(KEY_UP): DebugDraw3D.config.force_use_camera_from_scene = !DebugDraw3D.config.force_use_camera_from_scene + if _is_key_just_pressed(KEY_CTRL): + 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 @@ -305,11 +309,12 @@ func _text_tests(): if text_groups_show_hints: DebugDraw2D.begin_text_group("controls", 1024, Color.WHITE, false) DebugDraw2D.set_text("Shift: change render layers", DebugDraw3D.config.geometry_render_layers, 1) - DebugDraw2D.set_text("Down: freeze render", DebugDraw3D.config.freeze_3d_render, 2) - DebugDraw2D.set_text("Up: use scene camera", DebugDraw3D.config.force_use_camera_from_scene, 3) - DebugDraw2D.set_text("1,2,3: toggle debug", "%s, %s 😐, %s 😏" % [DebugDraw3D.debug_enabled, DebugDraw2D.debug_enabled, DebugDrawManager.debug_enabled], 4) - DebugDraw2D.set_text("Left: toggle frustum culling", DebugDraw3D.config.use_frustum_culling, 5) - DebugDraw2D.set_text("Right: draw bounds for culling", DebugDraw3D.config.visible_instance_bounds, 6) + DebugDraw2D.set_text("Ctrl: toggle anti-aliasing", "MSAA 4x" if get_viewport().msaa_3d == Viewport.MSAA_4X else "Disabled", 2) + DebugDraw2D.set_text("Down: freeze render", DebugDraw3D.config.freeze_3d_render, 3) + DebugDraw2D.set_text("Up: use scene camera", DebugDraw3D.config.force_use_camera_from_scene, 4) + DebugDraw2D.set_text("1,2,3: toggle debug", "%s, %s 😐, %s 😏" % [DebugDraw3D.debug_enabled, DebugDraw2D.debug_enabled, DebugDrawManager.debug_enabled], 5) + DebugDraw2D.set_text("Left: toggle frustum culling", DebugDraw3D.config.use_frustum_culling, 6) + DebugDraw2D.set_text("Right: draw bounds for culling", DebugDraw3D.config.visible_instance_bounds, 7) func _more_tests(): diff --git a/examples_dd3d/DebugDrawDemoScene.tscn b/examples_dd3d/DebugDrawDemoScene.tscn index 51c19d90..6dd95a1c 100644 --- a/examples_dd3d/DebugDrawDemoScene.tscn +++ b/examples_dd3d/DebugDrawDemoScene.tscn @@ -283,10 +283,10 @@ transform = Transform3D(10.7186, 0, 0, 0, 3.9777, 0, 0, 0, 7.05487, 10.6302, 1.9 [node name="LinePathAnim" type="AnimationPlayer" parent="."] root_node = NodePath("../LinePath") +autoplay = "New Anim" libraries = { "": SubResource("AnimationLibrary_nj4nv") } -autoplay = "New Anim" [node name="LinePath" type="Node3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.67362, -8) @@ -328,6 +328,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10.6349, 0.625214, -5.81358) [node name="Box1" type="Node3D" parent="."] transform = Transform3D(2.90583, -0.000527017, -5.34615, 0.00469241, 3.92788, 0.0141019, 0.556318, -0.0303774, 1.91619, -14.007, 0, 2.794) +rotation_edit_mode = 2 [node name="Box2" type="Node3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -14.4103, 0, 6.71577) @@ -452,11 +453,10 @@ transform = Transform3D(0.935992, 0.352021, 0, -0.352021, 0.935992, 0, 0, 0, 1, target_position = Vector3(0, -3.464, 0) [node name="AnimationPlayer" type="AnimationPlayer" parent="HitTest"] -callback_mode_process = 0 +autoplay = "New Anim" libraries = { "": SubResource("AnimationLibrary_vh8ml") } -autoplay = "New Anim" [node name="LagTest" type="CSGBox3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 10.4482, -1.49353, -0.450473) diff --git a/examples_dd3d/DebugDrawDemoSceneCS.cs b/examples_dd3d/DebugDrawDemoSceneCS.cs index 6a7fdd47..65e32a32 100644 --- a/examples_dd3d/DebugDrawDemoSceneCS.cs +++ b/examples_dd3d/DebugDrawDemoSceneCS.cs @@ -159,6 +159,7 @@ void _update_keys_just_press() var set = (Key k) => Input.IsKeyPressed(k) ? (button_presses[k] == 0 ? 1 : button_presses[k]) : 0; button_presses[Key.Left] = set(Key.Left); button_presses[Key.Up] = set(Key.Up); + button_presses[Key.Ctrl] = set(Key.Ctrl); button_presses[Key.F1] = set(Key.F1); button_presses[Key.Key1] = set(Key.Key1); button_presses[Key.Key2] = set(Key.Key2); @@ -210,6 +211,10 @@ public override void _Process(double delta) if (_is_key_just_pressed(Key.Up)) DebugDraw3D.Config.ForceUseCameraFromScene = !DebugDraw3D.Config.ForceUseCameraFromScene; + if (_is_key_just_pressed(Key.Ctrl)) + if (!Engine.IsEditorHint()) + GetViewport().Msaa3D = GetViewport().Msaa3D == Viewport.Msaa.Msaa4X ? Viewport.Msaa.Disabled : Viewport.Msaa.Msaa4X; + if (_is_key_just_pressed(Key.Key1)) DebugDraw3D.DebugEnabled = !DebugDraw3D.DebugEnabled; if (_is_key_just_pressed(Key.Key2)) @@ -467,11 +472,12 @@ void _text_tests() { DebugDraw2D.BeginTextGroup("controls", 1024, Colors.White, false); DebugDraw2D.SetText("Shift: change render layers", DebugDraw3D.Config.GeometryRenderLayers, 1); - DebugDraw2D.SetText("Down: freeze render", DebugDraw3D.Config.Freeze3dRender, 2); - DebugDraw2D.SetText("Up: use scene camera", DebugDraw3D.Config.ForceUseCameraFromScene, 3); - DebugDraw2D.SetText("1,2,3: toggle debug", $"{DebugDraw3D.DebugEnabled}, {DebugDraw2D.DebugEnabled} 😐, {DebugDrawManager.DebugEnabled} 😏", 4); - DebugDraw2D.SetText("Left: toggle frustum culling", DebugDraw3D.Config.UseFrustumCulling, 5); - DebugDraw2D.SetText("Right: draw bounds for culling", DebugDraw3D.Config.VisibleInstanceBounds, 6); + DebugDraw2D.SetText("Ctrl: change render layers", GetViewport().Msaa3D == Viewport.Msaa.Msaa4X ? "MSAA 4x" : "Disabled", 2); + DebugDraw2D.SetText("Down: freeze render", DebugDraw3D.Config.Freeze3dRender, 3); + DebugDraw2D.SetText("Up: use scene camera", DebugDraw3D.Config.ForceUseCameraFromScene, 4); + DebugDraw2D.SetText("1,2,3: toggle debug", $"{DebugDraw3D.DebugEnabled}, {DebugDraw2D.DebugEnabled} 😐, {DebugDrawManager.DebugEnabled} 😏", 5); + DebugDraw2D.SetText("Left: toggle frustum culling", DebugDraw3D.Config.UseFrustumCulling, 6); + DebugDraw2D.SetText("Right: draw bounds for culling", DebugDraw3D.Config.VisibleInstanceBounds, 7); } } diff --git a/lib_utils.py b/lib_utils.py index 2eb0dc11..39ec466f 100644 --- a/lib_utils.py +++ b/lib_utils.py @@ -150,9 +150,15 @@ def generate_sources_for_resources(env, src_out): ("src/resources/billboard_unshaded.gdshader", True), ] generate_resources_cpp_h_files(shared_files, "DD3DResources", "shared_resources.gen", src_out) + print("The generation of C++ sources with the contents of resources has been completed") + print() def generate_resources_cpp_h_files(input_files, namespace, output_no_ext, src_out): + print(f"Generating sources '{output_no_ext}.[cpp/h]' with content from resources:") + print("\n".join([f"{i[0]} as {'text' if i[1] else 'binary'}" for i in input_files])) + print() + gen_dir = "gen/" out_dir = src_folder + "/" + gen_dir Path(out_dir).mkdir(parents=True, exist_ok=True) diff --git a/src/3d/debug_draw_3d.cpp b/src/3d/debug_draw_3d.cpp index bb4707fe..6e98de31 100644 --- a/src/3d/debug_draw_3d.cpp +++ b/src/3d/debug_draw_3d.cpp @@ -10,6 +10,7 @@ GODOT_WARNING_DISABLE() #include +#include GODOT_WARNING_RESTORE() #include @@ -94,6 +95,10 @@ void DebugDraw3D::init(DebugDrawManager *root) { _load_materials(); #ifndef DISABLE_DEBUG_RENDERING +#ifdef DEV_ENABLED + DEV_PRINT_STD_F("To regenerate the 3D geometry press the \"%s\" action\n", reload_action_name); +#endif + dgc = std::make_unique(this); #endif } @@ -119,6 +124,18 @@ DebugDraw3D::~DebugDraw3D() { void DebugDraw3D::process(double delta) { #ifndef DISABLE_DEBUG_RENDERING +#ifdef DEV_ENABLED + if (Input::get_singleton()->is_action_just_pressed(reload_action_name)) { + LOCK_GUARD(datalock); + Node *old_world = dgc->get_world(); + dgc.reset(); + + _load_materials(); + dgc = std::make_unique(this); + dgc->set_world(old_world); + } +#endif + // Update 3D debug dgc->update_geometry(delta); #endif @@ -277,7 +294,7 @@ void DebugDraw3D::draw_sphere_base(const Vector3 &position, const real_t &radius void DebugDraw3D::draw_sphere_xf_base(const Transform3D &transform, const Color &color, const real_t &duration, const bool &hd) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_instance( hd ? InstanceType::SPHERES_HD : InstanceType::SPHERES, duration, @@ -311,7 +328,7 @@ void DebugDraw3D::draw_sphere_hd_xf(const Transform3D &transform, const Color &c void DebugDraw3D::draw_cylinder(const Transform3D &transform, const Color &color, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_instance( InstanceType::CYLINDERS, duration, @@ -330,7 +347,7 @@ void DebugDraw3D::draw_box(const Vector3 &position, const Vector3 &size, const C void DebugDraw3D::draw_box_xf(const Transform3D &transform, const Color &color, const bool &is_box_centered, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); /// It's possible to use less space to contain box, but this method works better in more cases SphereBounds sb(transform.origin, MathUtils::get_max_basis_length(transform.basis) * MathUtils::CubeRadiusForSphere); @@ -365,7 +382,7 @@ void DebugDraw3D::draw_aabb_ab(const Vector3 &a, const Vector3 &b, const Color & void DebugDraw3D::draw_line_hit(const Vector3 &start, const Vector3 &end, const Vector3 &hit, const bool &is_hit, const real_t &hit_size, const Color &hit_color, const Color &after_hit_color, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); if (is_hit) { dgc->geometry_pool.add_or_update_line(duration, { start, hit }, IS_DEFAULT_COLOR(hit_color) ? config->get_line_hit_color() : hit_color); dgc->geometry_pool.add_or_update_line(duration, { hit, end }, IS_DEFAULT_COLOR(after_hit_color) ? config->get_line_after_hit_color() : after_hit_color); @@ -383,7 +400,7 @@ void DebugDraw3D::draw_line_hit(const Vector3 &start, const Vector3 &end, const void DebugDraw3D::draw_line_hit_offset(const Vector3 &start, const Vector3 &end, const bool &is_hit, const real_t &unit_offset_of_hit, const real_t &hit_size, const Color &hit_color, const Color &after_hit_color, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); if (is_hit && unit_offset_of_hit >= 0 && unit_offset_of_hit <= 1) { draw_line_hit(start, end, ((end - start).normalized() * start.distance_to(end) * unit_offset_of_hit + start), is_hit, hit_size, hit_color, after_hit_color, duration); } else { @@ -395,13 +412,13 @@ void DebugDraw3D::draw_line_hit_offset(const Vector3 &start, const Vector3 &end, void DebugDraw3D::draw_line(const Vector3 &a, const Vector3 &b, const Color &color, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_line(duration, { a, b }, IS_DEFAULT_COLOR(color) ? Colors::red : color); } void DebugDraw3D::draw_lines(const PackedVector3Array &lines, const Color &color, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); if (lines.size() % 2 != 0) { PRINT_ERROR("The size of the lines array must be even. " + String::num_int64(lines.size()) + " is not even."); @@ -418,7 +435,7 @@ void DebugDraw3D::draw_lines(const PackedVector3Array &lines, const Color &color void DebugDraw3D::draw_lines_c(const std::vector &lines, const Color &color, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); if (lines.size() % 2 != 0) { PRINT_ERROR("The size of the lines array must be even. " + String::num_int64(lines.size()) + " is not even."); @@ -430,7 +447,7 @@ void DebugDraw3D::draw_lines_c(const std::vector &lines, const Color &c void DebugDraw3D::draw_ray(const Vector3 &origin, const Vector3 &direction, const real_t &length, const Color &color, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_line(duration, { origin, origin + direction * length }, IS_DEFAULT_COLOR(color) ? Colors::red : color); } @@ -443,7 +460,7 @@ void DebugDraw3D::draw_line_path(const PackedVector3Array &path, const Color &co return; } - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_line(duration, GeometryGenerator::CreateLinesFromPath(path), IS_DEFAULT_COLOR(color) ? Colors::light_green : color); } @@ -452,7 +469,7 @@ void DebugDraw3D::draw_line_path(const PackedVector3Array &path, const Color &co void DebugDraw3D::create_arrow(const Vector3 &a, const Vector3 &b, const Color &color, const real_t &arrow_size, const bool &is_absolute_size, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); Vector3 dir = (b - a); real_t size = (is_absolute_size ? arrow_size : dir.length() * arrow_size) * 2; Vector3 pos = b - dir.normalized() * size; @@ -473,7 +490,7 @@ void DebugDraw3D::create_arrow(const Vector3 &a, const Vector3 &b, const Color & void DebugDraw3D::draw_arrow(const Transform3D &transform, const Color &color, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_instance( InstanceType::ARROWHEADS, @@ -485,7 +502,7 @@ void DebugDraw3D::draw_arrow(const Transform3D &transform, const Color &color, c void DebugDraw3D::draw_arrow_line(const Vector3 &a, const Vector3 &b, const Color &color, const real_t &arrow_size, const bool &is_absolute_size, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_line(duration, { a, b }, IS_DEFAULT_COLOR(color) ? Colors::light_green : color); create_arrow(a, b, color, arrow_size, is_absolute_size, duration); @@ -498,7 +515,7 @@ void DebugDraw3D::draw_arrow_ray(const Vector3 &origin, const Vector3 &direction void DebugDraw3D::draw_arrow_path(const PackedVector3Array &path, const Color &color, const real_t &arrow_size, const bool &is_absolute_size, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_line(duration, GeometryGenerator::CreateLinesFromPath(path), IS_DEFAULT_COLOR(color) ? Colors::light_green : color); for (int i = 0; i < path.size() - 1; i++) { @@ -525,7 +542,7 @@ void DebugDraw3D::draw_square(const Vector3 &position, const real_t &size, const Transform3D t(Basis(), position); t.basis.scale(Vector3_ONE * size); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_instance( InstanceType::BILLBOARD_SQUARES, duration, @@ -543,7 +560,7 @@ void DebugDraw3D::draw_points(const PackedVector3Array &points, const real_t &si void DebugDraw3D::draw_position(const Transform3D &transform, const Color &color, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_instance( InstanceType::POSITIONS, duration, @@ -554,7 +571,7 @@ void DebugDraw3D::draw_position(const Transform3D &transform, const Color &color void DebugDraw3D::draw_gizmo(const Transform3D &transform, const Color &color, const bool &is_centered, const real_t &duration) { CHECK_BEFORE_CALL(); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); bool is_color_empty = IS_DEFAULT_COLOR(color); #define COLOR(axis) is_color_empty ? Colors::axis_##axis : color @@ -587,7 +604,7 @@ void DebugDraw3D::draw_grid_xf(const Transform3D &transform, const Vector2i &_su #define MAX_SUBDIVISIONS 1024 * 1024 ERR_FAIL_COND(_subdivision.x > MAX_SUBDIVISIONS); ERR_FAIL_COND(_subdivision.y > MAX_SUBDIVISIONS); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); Vector2i subdivision = _subdivision.abs(); subdivision = Vector2i(Math::clamp(subdivision.x, 1, MAX_SUBDIVISIONS), Math::clamp(subdivision.y, 1, MAX_SUBDIVISIONS)); @@ -622,7 +639,7 @@ void DebugDraw3D::draw_camera_frustum_planes_c(const std::array &plane CHECK_BEFORE_CALL(); auto lines = GeometryGenerator::CreateCameraFrustumLines(planes); - LOCK_GUARD(dgc->datalock); + LOCK_GUARD(datalock); dgc->geometry_pool.add_or_update_line(duration, lines, IS_DEFAULT_COLOR(color) ? Colors::red : color); } diff --git a/src/3d/debug_draw_3d.h b/src/3d/debug_draw_3d.h index 4e51df6d..2431552f 100644 --- a/src/3d/debug_draw_3d.h +++ b/src/3d/debug_draw_3d.h @@ -10,6 +10,7 @@ GODOT_WARNING_DISABLE() GODOT_WARNING_RESTORE() #include +#include using namespace godot; @@ -23,6 +24,7 @@ class DebugDraw3D : public Object { GDCLASS(DebugDraw3D, Object) friend DebugDrawManager; + friend DebugGeometryContainer; private: static DebugDraw3D *singleton; @@ -31,6 +33,11 @@ class DebugDraw3D : public Object { DebugDrawManager *root_node = nullptr; #ifndef DISABLE_DEBUG_RENDERING +#ifdef DEV_ENABLED + const char *reload_action_name = "ui_end"; +#endif + std::recursive_mutex datalock; + // Meshes std::unique_ptr dgc; diff --git a/src/3d/debug_geometry_container.cpp b/src/3d/debug_geometry_container.cpp index 6cb9a446..65a7016f 100644 --- a/src/3d/debug_geometry_container.cpp +++ b/src/3d/debug_geometry_container.cpp @@ -45,43 +45,43 @@ DebugGeometryContainer::DebugGeometryContainer(class DebugDraw3D *root) { // CreateMMI(InstanceType::CUBES_CENTERED, UsingShaderType::Wireframe, NAMEOF(mmi_cubes_centered), array_mesh_cube_center); auto array_mesh_arrow_head = GeometryGenerator::CreateMesh(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::ArrowheadVertices, GeometryGenerator::ArrowheadIndices); - //CreateMMI(InstanceType::ARROWHEADS, UsingShaderType::Wireframe, NAMEOF(mmi_arrowheads), array_mesh_arrow_head); + // CreateMMI(InstanceType::ARROWHEADS, UsingShaderType::Wireframe, NAMEOF(mmi_arrowheads), array_mesh_arrow_head); auto array_mesh_billboard = GeometryGenerator::CreateMesh(Mesh::PrimitiveType::PRIMITIVE_TRIANGLES, GeometryGenerator::CenteredSquareVertices, GeometryGenerator::SquareIndices); CreateMMI(InstanceType::BILLBOARD_SQUARES, UsingShaderType::Billboard, NAMEOF(mmi_billboard_squares), array_mesh_billboard); auto array_mesh_pos = GeometryGenerator::CreateMesh(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::PositionVertices, GeometryGenerator::PositionIndices); - //CreateMMI(InstanceType::POSITIONS, UsingShaderType::Wireframe, NAMEOF(mmi_positions), array_mesh_pos); + // CreateMMI(InstanceType::POSITIONS, UsingShaderType::Wireframe, NAMEOF(mmi_positions), array_mesh_pos); - auto array_mesh_sphere = GeometryGenerator::CreateMesh(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::CreateSphereLines(8, 8, 0.5f, Vector3_ZERO)); - //CreateMMI(InstanceType::SPHERES, UsingShaderType::Wireframe, NAMEOF(mmi_spheres), array_mesh_sphere); + auto array_mesh_sphere = GeometryGenerator::CreateMesh(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::CreateSphereLines(8, 8, 0.5f, Vector3_ZERO, 2)); + // CreateMMI(InstanceType::SPHERES, UsingShaderType::Wireframe, NAMEOF(mmi_spheres), array_mesh_sphere); - auto array_mesh_sphere_hd = GeometryGenerator::CreateMesh(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::CreateSphereLines(16, 16, 0.5f, Vector3_ZERO)); - //CreateMMI(InstanceType::SPHERES_HD, UsingShaderType::Wireframe, NAMEOF(mmi_spheres_hd), array_mesh_sphere_hd); - - auto array_mesh_cylinder = GeometryGenerator::CreateMesh(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::CreateCylinderLines(52, 1, 1, Vector3_ZERO, 4)); - //CreateMMI(InstanceType::CYLINDERS, UsingShaderType::Wireframe, NAMEOF(mmi_cylinders), array_mesh_cylinder); + auto array_mesh_sphere_hd = GeometryGenerator::CreateMesh(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::CreateSphereLines(16, 16, 0.5f, Vector3_ZERO, 2)); + // CreateMMI(InstanceType::SPHERES_HD, UsingShaderType::Wireframe, NAMEOF(mmi_spheres_hd), array_mesh_sphere_hd); + auto array_mesh_cylinder = GeometryGenerator::CreateMesh(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::CreateCylinderLines(14, 1, 1, Vector3_ZERO, 2)); + // CreateMMI(InstanceType::CYLINDERS, UsingShaderType::Wireframe, NAMEOF(mmi_cylinders), array_mesh_cylinder); auto array_mesh_cube_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_cube); CreateMMI(InstanceType::CUBES, UsingShaderType::Expandable, NAMEOF(TEST_CUBE_VOLUMETRIC), array_mesh_cube_volumetric); auto array_mesh_cube_centered_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_cube_center); CreateMMI(InstanceType::CUBES_CENTERED, UsingShaderType::Expandable, NAMEOF(TEST_CUBE_VOLUMETRIC), array_mesh_cube_centered_volumetric); - - auto array_mesh_sphere_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_sphere); + + auto array_mesh_sphere_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_sphere, false); CreateMMI(InstanceType::SPHERES, UsingShaderType::Expandable, NAMEOF(TEST_CUBE_VOLUMETRIC), array_mesh_sphere_volumetric); - - auto array_mesh_arrow_head_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_arrow_head); + + auto array_mesh_arrow_head_simple = GeometryGenerator::CreateMesh(Mesh::PrimitiveType::PRIMITIVE_LINES, GeometryGenerator::ArrowheadVertices, GeometryGenerator::ArrowheadIndicesSimplified); + auto array_mesh_arrow_head_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_arrow_head_simple); CreateMMI(InstanceType::ARROWHEADS, UsingShaderType::Expandable, NAMEOF(TEST_CUBE_VOLUMETRIC), array_mesh_arrow_head_volumetric); - + auto array_mesh_pos_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_pos); CreateMMI(InstanceType::POSITIONS, UsingShaderType::Expandable, NAMEOF(TEST_CUBE_VOLUMETRIC), array_mesh_pos_volumetric); - - auto array_mesh_sphere_hd_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_sphere_hd); + + auto array_mesh_sphere_hd_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_sphere_hd, false); CreateMMI(InstanceType::SPHERES_HD, UsingShaderType::Expandable, NAMEOF(TEST_CUBE_VOLUMETRIC), array_mesh_sphere_hd_volumetric); - - auto array_mesh_cylinder_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_cylinder); + + auto array_mesh_cylinder_volumetric = GeometryGenerator::ConvertWireframeToVolumetric(array_mesh_cylinder, false); CreateMMI(InstanceType::CYLINDERS, UsingShaderType::Expandable, NAMEOF(TEST_CUBE_VOLUMETRIC), array_mesh_cylinder_volumetric); set_render_layer_mask(1); @@ -89,7 +89,7 @@ DebugGeometryContainer::DebugGeometryContainer(class DebugDraw3D *root) { } DebugGeometryContainer::~DebugGeometryContainer() { - LOCK_GUARD(datalock); + LOCK_GUARD(owner->datalock); geometry_pool.clear_pool(); geometry_pool.clear_pool(); @@ -158,7 +158,7 @@ Node *DebugGeometryContainer::get_world() { // TODO add mark_dirty for 3d to reduce editor updates if only delayed shapes are displayed. void DebugGeometryContainer::update_geometry(double delta) { - LOCK_GUARD(datalock); + LOCK_GUARD(owner->datalock); // Don't clear geometry if frozen if (owner->get_config()->is_freeze_3d_render()) @@ -297,12 +297,12 @@ void DebugGeometryContainer::update_geometry(double delta) { } Ref DebugGeometryContainer::get_render_stats() { - LOCK_GUARD(datalock); + LOCK_GUARD(owner->datalock); return geometry_pool.get_stats(); } void DebugGeometryContainer::set_render_layer_mask(int32_t layers) { - LOCK_GUARD(datalock); + LOCK_GUARD(owner->datalock); if (render_layers != layers) { RenderingServer *rs = RS(); for (auto &mmi : multi_mesh_storage) @@ -318,6 +318,7 @@ int32_t DebugGeometryContainer::get_render_layer_mask() const { } void DebugGeometryContainer::clear_3d_objects() { + LOCK_GUARD(owner->datalock); for (auto &s : multi_mesh_storage) { s.mesh->set_instance_count(0); } diff --git a/src/3d/debug_geometry_container.h b/src/3d/debug_geometry_container.h index 78c462eb..dc65892e 100644 --- a/src/3d/debug_geometry_container.h +++ b/src/3d/debug_geometry_container.h @@ -68,8 +68,6 @@ class DebugGeometryContainer { void CreateMMI(InstanceType type, UsingShaderType shader, const String &name, Ref mesh); - std::recursive_mutex datalock; - public: DebugGeometryContainer(class DebugDraw3D *root); ~DebugGeometryContainer(); diff --git a/src/3d/geometry_generators.cpp b/src/3d/geometry_generators.cpp index 6755fa99..66030636 100644 --- a/src/3d/geometry_generators.cpp +++ b/src/3d/geometry_generators.cpp @@ -128,6 +128,17 @@ const std::array GeometryGenerator::ArrowheadIndices{ 4, }; +const std::array GeometryGenerator::ArrowheadIndicesSimplified{ + 0, + 1, + 0, + 2, + 0, + 3, + 0, + 4, +}; + const std::array GeometryGenerator::CenteredSquareVertices{ Vector3(0.5f, 0.5f, 0), Vector3(0.5f, -0.5f, 0), @@ -185,7 +196,7 @@ Ref GeometryGenerator::CreateMesh(Mesh::PrimitiveType type, const Pac return mesh; } -Ref GeometryGenerator::ConvertWireframeToVolumetric(Ref mesh) { +Ref GeometryGenerator::ConvertWireframeToVolumetric(Ref mesh, const bool &add_caps) { Array arrs = mesh->surface_get_arrays(0); PackedVector3Array vertexes = arrs[ArrayMesh::ArrayType::ARRAY_VERTEX]; PackedVector3Array normals = arrs[ArrayMesh::ArrayType::ARRAY_NORMAL]; @@ -201,11 +212,11 @@ Ref GeometryGenerator::ConvertWireframeToVolumetric(Ref me if (indexes.size()) { for (int i = 0; i < indexes.size(); i += 2) { - GenerateVolumetricSegment(vertexes[indexes[i]], vertexes[indexes[i + 1]], true ? Vector3(0, 1, 0.0001) : normals[indexes[i]], res_vertexes, res_custom0, res_indexes); + GenerateVolumetricSegment(vertexes[indexes[i]], vertexes[indexes[i + 1]], true ? Vector3(0, 1, 0.0001f) : normals[indexes[i]], res_vertexes, res_custom0, res_indexes, add_caps); } } else { for (int i = 0; i < vertexes.size(); i += 2) { - GenerateVolumetricSegment(vertexes[i], vertexes[i + 1], true ? Vector3(0, 1, 0.0001) : normals[i], res_vertexes, res_custom0, res_indexes); + GenerateVolumetricSegment(vertexes[i], vertexes[i + 1], true ? Vector3(0, 1, 0.0001f) : normals[i], res_vertexes, res_custom0, res_indexes, add_caps); } } @@ -219,7 +230,7 @@ Ref GeometryGenerator::ConvertWireframeToVolumetric(Ref me ArrayMesh::ARRAY_CUSTOM_RGB_FLOAT << Mesh::ARRAY_FORMAT_CUSTOM0_SHIFT); } -void GeometryGenerator::GenerateVolumetricSegment(Vector3 a, Vector3 b, Vector3 normal_up, PackedVector3Array &vertexes, PackedVector3Array &custom0, PackedInt32Array &indexes) { +void GeometryGenerator::GenerateVolumetricSegment(const Vector3 &a, const Vector3 &b, const Vector3 &normal_up, PackedVector3Array &vertexes, PackedVector3Array &custom0, PackedInt32Array &indexes, const bool &add_caps) { bool debug_size = false; Vector3 dir = (b - a).normalized(); @@ -228,11 +239,6 @@ void GeometryGenerator::GenerateVolumetricSegment(Vector3 a, Vector3 b, Vector3 Vector3 up = dir.cross(left).normalized(); Vector3 down = up * -1; - Vector3 h_right = right * 0.5; - Vector3 h_left = left * 0.5; - Vector3 h_up = up * 0.5; - Vector3 h_down = down * 0.5; - Vector3 mult = debug_size ? Vector3(1, 1, 1) * 0.5 : Vector3(); int64_t base = vertexes.size(); @@ -262,37 +268,32 @@ void GeometryGenerator::GenerateVolumetricSegment(Vector3 a, Vector3 b, Vector3 indexes.append(base + 7); indexes.append(base + 6); - // Start cap - indexes.append(base + 0); - indexes.append(base + 1); - indexes.append(base + 2); - indexes.append(base + 0); - indexes.append(base + 3); - indexes.append(base + 1); - // End cap - indexes.append(base + 4); - indexes.append(base + 6); - indexes.append(base + 5); - indexes.append(base + 4); - indexes.append(base + 5); - indexes.append(base + 7); + if (add_caps) { + // Start cap + indexes.append(base + 0); + indexes.append(base + 1); + indexes.append(base + 2); + indexes.append(base + 0); + indexes.append(base + 3); + indexes.append(base + 1); + // End cap + indexes.append(base + 4); + indexes.append(base + 6); + indexes.append(base + 5); + indexes.append(base + 4); + indexes.append(base + 5); + indexes.append(base + 7); + } + + custom0.push_back(right); + custom0.push_back(left); + custom0.push_back(up); + custom0.push_back(down); - indexes.append(2); - indexes.append(3); - indexes.append(6); - indexes.append(3); - indexes.append(7); - indexes.append(6); - - custom0.push_back(h_right); - custom0.push_back(h_left); - custom0.push_back(h_up); - custom0.push_back(h_down); - - custom0.push_back(h_right); - custom0.push_back(h_left); - custom0.push_back(h_up); - custom0.push_back(h_down); + custom0.push_back(right); + custom0.push_back(left); + custom0.push_back(up); + custom0.push_back(down); } std::vector GeometryGenerator::CreateCameraFrustumLines(const std::array &frustum) { @@ -325,9 +326,9 @@ std::vector GeometryGenerator::CreateCameraFrustumLines(const std::arra return res; } -std::vector GeometryGenerator::CreateSphereLines(const int &_lats, const int &_lons, const float &radius, const Vector3 &position) { - int lats = _lats; - int lons = _lons; +std::vector GeometryGenerator::CreateSphereLines(const int &_lats, const int &_lons, const float &radius, const Vector3 &position, const int &subdivide) { + int lats = _lats * subdivide; + int lons = _lons * subdivide; if (lats < 2) lats = 2; @@ -356,30 +357,31 @@ std::vector GeometryGenerator::CreateSphereLines(const int &_lats, cons float x1 = cos(lng1); float y1 = sin(lng1); - Vector3 v[4]{ + Vector3 v[3]{ Vector3(x1 * zr0, z0, y1 * zr0) * radius + position, Vector3(x1 * zr1, z1, y1 * zr1) * radius + position, - Vector3(x0 * zr1, z1, y0 * zr1) * radius + position, Vector3(x0 * zr0, z0, y0 * zr0) * radius + position }; - res[total++] = v[0]; - res[total++] = v[1]; - res[total++] = v[2]; + if (j % subdivide == 0) { + res[total++] = v[0]; + res[total++] = v[1]; + } - res[total++] = v[2]; - res[total++] = v[3]; - res[total++] = v[0]; + if (i % subdivide == 0) { + res[total++] = v[2]; + res[total++] = v[0]; + } } } return res; } -std::vector GeometryGenerator::CreateCylinderLines(const int &edges, const float &radius, const float &height, const Vector3 &position, const int &draw_edge_each_n_step) { +std::vector GeometryGenerator::CreateCylinderLines(const int &edges, const float &radius, const float &height, const Vector3 &position, const int &subdivide) { real_t angle = 360.f / edges; std::vector points; - points.reserve(4 * (size_t)edges + (((size_t)edges / (size_t)draw_edge_each_n_step) * 2)); + points.reserve(4 * (size_t)edges + (((size_t)edges * (size_t)subdivide) * 2)); Vector3 d = Vector3(0, height, 0); for (int i = 0; i < edges; i++) { @@ -397,7 +399,7 @@ std::vector GeometryGenerator::CreateCylinderLines(const int &edges, co points.push_back(b - d); // Edge - if (i % draw_edge_each_n_step == 0) { + if (i % subdivide == 0) { points.push_back(a + d); points.push_back(a - d); } diff --git a/src/3d/geometry_generators.h b/src/3d/geometry_generators.h index cdd48a5f..4297d8e1 100644 --- a/src/3d/geometry_generators.h +++ b/src/3d/geometry_generators.h @@ -16,7 +16,7 @@ using namespace godot; class GeometryGenerator { private: - static void GenerateVolumetricSegment(Vector3 a, Vector3 b, Vector3 normal_up, PackedVector3Array &vertexes, PackedVector3Array &custom0, PackedInt32Array &indexes); + static void GenerateVolumetricSegment(const Vector3 &a, const Vector3 &b, const Vector3 &normal_up, PackedVector3Array &vertexes, PackedVector3Array &custom0, PackedInt32Array &indexes, const bool &add_caps = true); public: #pragma region Predefined Geometry Parts @@ -27,6 +27,7 @@ class GeometryGenerator { const static std::array CubeWithDiagonalsIndices; const static std::array ArrowheadVertices; const static std::array ArrowheadIndices; + const static std::array ArrowheadIndicesSimplified; const static std::array CenteredSquareVertices; const static std::array SquareIndices; const static std::array PositionVertices; @@ -47,11 +48,11 @@ class GeometryGenerator { static Ref CreateMesh(Mesh::PrimitiveType type, const PackedVector3Array &vertices, const PackedInt32Array &indices = {}, const PackedColorArray &colors = {}, const PackedVector3Array &normals = {}, const PackedFloat32Array &custom0 = {}, BitField flags = 0); - static Ref ConvertWireframeToVolumetric(Ref mesh); + static Ref ConvertWireframeToVolumetric(Ref mesh, const bool &add_caps = true); static std::vector CreateCameraFrustumLines(const std::array &frustum); // TODO like in cylinder add more lines and draw_edge_each_n_step to make them more precise - static std::vector CreateSphereLines(const int &_lats, const int &_lons, const float &radius, const Vector3 &position); - static std::vector CreateCylinderLines(const int &edges, const float &radius, const float &height, const Vector3 &position, const int &draw_edge_each_n_step = 1); + static std::vector CreateSphereLines(const int &_lats, const int &_lons, const float &radius, const Vector3 &position, const int &subdivide = 1); + static std::vector CreateCylinderLines(const int &edges, const float &radius, const float &height, const Vector3 &position, const int &subdivide = 1); static std::vector CreateLinesFromPath(const PackedVector3Array &path); }; diff --git a/src/debug_draw_manager.cpp b/src/debug_draw_manager.cpp index 0fb14483..e166a338 100644 --- a/src/debug_draw_manager.cpp +++ b/src/debug_draw_manager.cpp @@ -24,6 +24,7 @@ const char *DebugDrawManager::s_extension_unloading = "extension_unloading"; void DebugDrawManager::_bind_methods() { #define REG_CLASS_NAME DebugDrawManager + // TODO USE CALLABLE_MP! // ClassDB::bind_method(D_METHOD(NAMEOF(get_title)), &DebugDrawGraph::get_title); ClassDB::bind_method(D_METHOD(NAMEOF(_add_to_tree)), &DebugDrawManager::_add_to_tree); ClassDB::bind_method(D_METHOD(NAMEOF(_integrate_into_engine)), &DebugDrawManager::_integrate_into_engine); diff --git a/src/editor/asset_library_update_checker.h b/src/editor/asset_library_update_checker.h index de8e2833..a4325e3f 100644 --- a/src/editor/asset_library_update_checker.h +++ b/src/editor/asset_library_update_checker.h @@ -18,7 +18,6 @@ class AssetLibraryUpdateChecker : public RefCounted { GDCLASS(AssetLibraryUpdateChecker, RefCounted) private: - std::thread http_thread; bool is_thread_closing = false; Ref http = nullptr; diff --git a/src/editor/editor_menu_extensions.cpp b/src/editor/editor_menu_extensions.cpp index 750ee6b3..073d7a73 100644 --- a/src/editor/editor_menu_extensions.cpp +++ b/src/editor/editor_menu_extensions.cpp @@ -75,8 +75,8 @@ DebugDrawMenuExtensionPlugin::DebugDrawMenuExtensionPlugin() { } DebugDrawMenuExtensionPlugin::~DebugDrawMenuExtensionPlugin() { - DEV_PRINT(NAMEOF(DebugDrawMenuExtensionPlugin) " deconstructor"); - //remove_tool_menu_item(menu_item_name); + // DEV_PRINT(NAMEOF(DebugDrawMenuExtensionPlugin) " deconstructor"); + // remove_tool_menu_item(menu_item_name); } #endif \ No newline at end of file diff --git a/src/resources/extendable_meshes.gdshader b/src/resources/extendable_meshes.gdshader index 88a75845..d6671647 100644 --- a/src/resources/extendable_meshes.gdshader +++ b/src/resources/extendable_meshes.gdshader @@ -1,16 +1,22 @@ shader_type spatial; render_mode cull_disabled, shadows_disabled, unshaded, world_vertex_coords; -//render_mode wireframe; uniform float extend : hint_range(0.0, 1.0, 0.001) = 0.1; +mat3 orthonormalize(mat3 m) { + vec3 x = normalize(m[0]); + vec3 y = normalize(m[1] - dot(m[1], x) * x); + vec3 z = normalize(m[2] - dot(m[2], x) * x - dot(m[2], y) * y); + return mat3(x, y, z); +} + void vertex() { - VERTEX = VERTEX + CUSTOM0.xyz * extend; + VERTEX = VERTEX + (CUSTOM0.xyz * (extend * 0.5)) * orthonormalize(inverse(mat3(normalize(MODEL_MATRIX[0].xyz), normalize(MODEL_MATRIX[1].xyz), normalize(MODEL_MATRIX[2].xyz)))); } void fragment() { if (FRONT_FACING) ALBEDO = COLOR.xyz; else - ALBEDO = COLOR.xyz * 0.65f; + ALBEDO = COLOR.xyz * 0.85f; }