summaryrefslogtreecommitdiffstats
path: root/editor/plugins/path_3d_editor_plugin.cpp
diff options
context:
space:
mode:
authorYuri Sizov <yuris@humnom.net>2023-12-08 16:58:08 +0100
committerYuri Sizov <yuris@humnom.net>2023-12-08 16:58:08 +0100
commit959c166866cb7f6d2eddea279172cfeb1ca84f80 (patch)
tree020a42d6f13e1af4edde8215012e98d6421363c7 /editor/plugins/path_3d_editor_plugin.cpp
parentb3c20bcf1e32d867906ac436cf259f782516d903 (diff)
parent67a3ef6aca3c9335f0c3f3824d4448c12fc5d4cf (diff)
downloadredot-engine-959c166866cb7f6d2eddea279172cfeb1ca84f80.tar.gz
Merge pull request #83741 from BlueCube3310/path-3d-plugin-optimize
Optimize Path3DGizmo Mesh Generation
Diffstat (limited to 'editor/plugins/path_3d_editor_plugin.cpp')
-rw-r--r--editor/plugins/path_3d_editor_plugin.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/editor/plugins/path_3d_editor_plugin.cpp b/editor/plugins/path_3d_editor_plugin.cpp
index 42c080fdf2..6fe1949382 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<Vector3> _collision_segments;
+ _collision_segments.resize((sample_count - 1) * 2);
+ Vector3 *_collisions_ptr = _collision_segments.ptrw();
+
Vector<Vector3> bones;
+ bones.resize(sample_count * 4);
+ Vector3 *bones_ptr = bones.ptrw();
+
Vector<Vector3> 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);