From 67a3ef6aca3c9335f0c3f3824d4448c12fc5d4cf Mon Sep 17 00:00:00 2001 From: BlueCube3310 <53150244+BlueCube3310@users.noreply.github.com> Date: Sat, 21 Oct 2023 19:03:57 +0200 Subject: [PATCH] Optimize Path3DGizmo mesh generation --- editor/plugins/path_3d_editor_plugin.cpp | 28 +++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp index 9d66e606b09..d6943dd7314 100644 --- a/editor/plugins/path_3d_editor_plugin.cpp +++ b/editor/plugins/path_3d_editor_plugin.cpp @@ -303,9 +303,19 @@ void Path3DGizmo::redraw() { } const Transform3D *r = frames.ptr(); + Vector _collision_segments; + _collision_segments.resize((sample_count - 1) * 2); + Vector3 *_collisions_ptr = _collision_segments.ptrw(); + Vector bones; + bones.resize(sample_count * 4); + Vector3 *bones_ptr = bones.ptrw(); + Vector ribbon; + ribbon.resize(sample_count); + Vector3 *ribbon_ptr = ribbon.ptrw(); + for (int i = 0; i < sample_count; i++) { const Vector3 p1 = r[i].origin; const Vector3 side = r[i].basis.get_column(0); @@ -313,23 +323,25 @@ void Path3DGizmo::redraw() { const Vector3 forward = r[i].basis.get_column(2); // Collision segments. - if (i != sample_count) { + if (i != sample_count - 1) { const Vector3 p2 = r[i + 1].origin; - _collision_segments.push_back(p1); - _collision_segments.push_back(p2); + _collisions_ptr[(i * 2)] = p1; + _collisions_ptr[(i * 2) + 1] = p2; } // Path3D as a ribbon. - ribbon.push_back(p1); + ribbon_ptr[i] = p1; // Fish Bone. const Vector3 p_left = p1 + (side + forward - up * 0.3) * 0.06; const Vector3 p_right = p1 + (-side + forward - up * 0.3) * 0.06; - bones.push_back(p1); - bones.push_back(p_left); - bones.push_back(p1); - bones.push_back(p_right); + const int bone_idx = i * 4; + + bones_ptr[bone_idx] = p1; + bones_ptr[bone_idx + 1] = p_left; + bones_ptr[bone_idx + 2] = p1; + bones_ptr[bone_idx + 3] = p_right; } add_collision_segments(_collision_segments);