Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-08-28 22:33:03 +0300
committerHans Goudey <h.goudey@me.com>2022-08-28 22:33:03 +0300
commit67f3259c54657996d47112967c9b982f78ebfe6e (patch)
tree175eef61ff9e52044c56344e47aa93ac40f4c29c /source/blender/geometry
parent28750bcf7e8b73d9da015898a3c0f21ef5d761f2 (diff)
Curves: Avoid creating types array when unnecessary
When the curve type attribute doesn't exist, there is no reason to create an array for it only to fill the default value, which will add overhead to subsequent "add" operations. I added a "get_if_single" method to virtual array to simplify this check. Also use the existing functions for filling curve types. Differential Revision: https://developer.blender.org/D15560
Diffstat (limited to 'source/blender/geometry')
-rw-r--r--source/blender/geometry/intern/add_curves_on_mesh.cc12
1 files changed, 5 insertions, 7 deletions
diff --git a/source/blender/geometry/intern/add_curves_on_mesh.cc b/source/blender/geometry/intern/add_curves_on_mesh.cc
index 299040d4d32..7f269578f5d 100644
--- a/source/blender/geometry/intern/add_curves_on_mesh.cc
+++ b/source/blender/geometry/intern/add_curves_on_mesh.cc
@@ -276,6 +276,7 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves,
/* Grow number of curves first, so that the offsets array can be filled. */
curves.resize(old_points_num, new_curves_num);
+ const IndexRange new_curves_range = curves.curves_range().drop_front(old_curves_num);
/* Compute new curve offsets. */
MutableSpan<int> curve_offsets = curves.offsets_for_write();
@@ -290,8 +291,8 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves,
else {
new_point_counts_per_curve.fill(inputs.fallback_point_count);
}
- for (const int i : IndexRange(added_curves_num)) {
- curve_offsets[old_curves_num + i + 1] += curve_offsets[old_curves_num + i];
+ for (const int i : new_curves_range) {
+ curve_offsets[i + 1] += curve_offsets[i];
}
const int new_points_num = curves.offsets().last();
@@ -342,7 +343,7 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves,
const VArray<float> curves_selection = curves.selection_curve_float();
if (curves_selection.is_span()) {
MutableSpan<float> curves_selection_span = curves.selection_curve_float_for_write();
- curves_selection_span.drop_front(old_curves_num).fill(1.0f);
+ curves_selection_span.slice(new_curves_range).fill(1.0f);
}
/* Initialize position attribute. */
@@ -366,10 +367,7 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves,
inputs.transforms->surface_to_curves_normal);
}
- /* Set curve types. */
- MutableSpan<int8_t> types_span = curves.curve_types_for_write();
- types_span.drop_front(old_curves_num).fill(CURVE_TYPE_CATMULL_ROM);
- curves.update_curve_types();
+ curves.fill_curve_types(new_curves_range, CURVE_TYPE_CATMULL_ROM);
return outputs;
}