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>2021-12-22 23:35:46 +0300
committerHans Goudey <h.goudey@me.com>2021-12-22 23:35:46 +0300
commit0fd72a98ac1377a385b6558bf34a7cb372677ac1 (patch)
tree26c8071c95a22e258cbe69442ebc2aa20b7f9642 /source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
parentb4f978e9011d6c14f73ad871c77b1a325769e7c5 (diff)
Cleanup: Avoid adding points to splines sequentially
This should be faster because it avoids reallocating the internal vectors when the size is known beforehand, but it may also help a potential refactor to a different data structure (see T94193).
Diffstat (limited to 'source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc')
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc15
1 files changed, 10 insertions, 5 deletions
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
index 731be0f0f49..8841f558435 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
@@ -54,19 +54,24 @@ static std::unique_ptr<CurveEval> create_star_curve(const float inner_radius,
{
std::unique_ptr<CurveEval> curve = std::make_unique<CurveEval>();
std::unique_ptr<PolySpline> spline = std::make_unique<PolySpline>();
+ spline->set_cyclic(true);
+
+ spline->resize(points * 2);
+ MutableSpan<float3> positions = spline->positions();
+ spline->radii().fill(1.0f);
+ spline->tilts().fill(0.0f);
const float theta_step = (2.0f * M_PI) / float(points);
- for (int i : IndexRange(points)) {
+ for (const int i : IndexRange(points)) {
const float x = outer_radius * cos(theta_step * i);
const float y = outer_radius * sin(theta_step * i);
- spline->add_point(float3(x, y, 0.0f), 1.0f, 0.0f);
+ positions[i * 2] = {x, y, 0.0f};
const float inner_x = inner_radius * cos(theta_step * i + theta_step * 0.5f + twist);
const float inner_y = inner_radius * sin(theta_step * i + theta_step * 0.5f + twist);
- spline->add_point(float3(inner_x, inner_y, 0.0f), 1.0f, 0.0f);
+ positions[i * 2 + 1] = {inner_x, inner_y, 0.0f};
}
- spline->set_cyclic(true);
- spline->attributes.reallocate(spline->size());
+
curve->add_spline(std::move(spline));
curve->attributes.reallocate(curve->splines().size());