From 068300c7c98600c87d0ccc78c4bdd66ad017f7fe Mon Sep 17 00:00:00 2001 From: jmb462 Date: Sun, 28 Feb 2021 22:15:52 +0100 Subject: Adding Raycast3D custom debug shape thickness and color --- editor/node_3d_editor_gizmos.cpp | 31 +++++++++++++++++-------------- editor/plugins/node_3d_editor_plugin.h | 1 + 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'editor') diff --git a/editor/node_3d_editor_gizmos.cpp b/editor/node_3d_editor_gizmos.cpp index e6b99fa63f..16eefb1ad3 100644 --- a/editor/node_3d_editor_gizmos.cpp +++ b/editor/node_3d_editor_gizmos.cpp @@ -198,7 +198,11 @@ void EditorNode3DGizmo::add_mesh(const Ref &p_mesh, bool p_billboard, } void EditorNode3DGizmo::add_lines(const Vector &p_lines, const Ref &p_material, bool p_billboard, const Color &p_modulate) { - if (p_lines.is_empty()) { + add_vertices(p_lines, p_material, Mesh::PRIMITIVE_LINES, p_billboard, p_modulate); +} + +void EditorNode3DGizmo::add_vertices(const Vector &p_vertices, const Ref &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard, const Color &p_modulate) { + if (p_vertices.is_empty()) { return; } @@ -209,13 +213,13 @@ void EditorNode3DGizmo::add_lines(const Vector &p_lines, const Ref color; - color.resize(p_lines.size()); + color.resize(p_vertices.size()); { Color *w = color.ptrw(); - for (int i = 0; i < p_lines.size(); i++) { + for (int i = 0; i < p_vertices.size(); i++) { if (is_selected()) { w[i] = Color(1, 1, 1, 0.8) * p_modulate; } else { @@ -226,13 +230,13 @@ void EditorNode3DGizmo::add_lines(const Vector &p_lines, const Refadd_surface_from_arrays(Mesh::PRIMITIVE_LINES, a); + mesh->add_surface_from_arrays(p_primitive_type, a); mesh->surface_set_material(0, p_material); if (p_billboard) { float md = 0; - for (int i = 0; i < p_lines.size(); i++) { - md = MAX(0, p_lines[i].length()); + for (int i = 0; i < p_vertices.size(); i++) { + md = MAX(0, p_vertices[i].length()); } if (md) { mesh->set_custom_aabb(AABB(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0)); @@ -1906,16 +1910,15 @@ void RayCast3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->clear(); - Vector lines; + const Ref material = raycast->is_enabled() ? raycast->get_debug_material() : get_material("shape_material_disabled"); - lines.push_back(Vector3()); - lines.push_back(raycast->get_target_position()); + p_gizmo->add_lines(raycast->get_debug_line_vertices(), material); - const Ref material = - get_material(raycast->is_enabled() ? "shape_material" : "shape_material_disabled", p_gizmo); + if (raycast->get_debug_shape_thickness() > 1) { + p_gizmo->add_vertices(raycast->get_debug_shape_vertices(), material, Mesh::PRIMITIVE_TRIANGLE_STRIP); + } - p_gizmo->add_lines(lines, material); - p_gizmo->add_collision_segments(lines); + p_gizmo->add_collision_segments(raycast->get_debug_line_vertices()); } ///// diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index cf4aa33257..ff4a941b06 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -99,6 +99,7 @@ protected: public: void add_lines(const Vector &p_lines, const Ref &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); + void add_vertices(const Vector &p_vertices, const Ref &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); void add_mesh(const Ref &p_mesh, bool p_billboard = false, const Ref &p_skin_reference = Ref(), const Ref &p_material = Ref()); void add_collision_segments(const Vector &p_lines); void add_collision_triangles(const Ref &p_tmesh); -- cgit v1.2.3