diff options
author | Hans Goudey <h.goudey@me.com> | 2021-06-09 23:12:29 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-06-09 23:15:40 +0300 |
commit | 91f141f9706e51df4d71b272cb575c22b14ec3cc (patch) | |
tree | c004e25fb0ea91b2407d80980b75ab3ffa954e98 | |
parent | 79743803fe899229b6fc02f954effedf6a5ad71d (diff) | |
parent | 675677ec67c6b922b3a5e602c8bf3dbb562bd687 (diff) |
Merge branch 'master' into geometry-nodes-curve-to-points-node
6 files changed, 44 insertions, 40 deletions
diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh index 2c34d9050f5..dfbe82f31fd 100644 --- a/source/blender/blenkernel/BKE_spline.hh +++ b/source/blender/blenkernel/BKE_spline.hh @@ -171,24 +171,24 @@ class Spline { blender::Array<float> sample_uniform_index_factors(const int samples_size) const; LookupResult lookup_data_from_index_factor(const float index_factor) const; - void sample_data_based_on_index_factors(const blender::fn::GVArray &src, - blender::Span<float> index_factors, - blender::fn::GMutableSpan dst) const; + + void sample_based_on_index_factors(const blender::fn::GVArray &src, + blender::Span<float> index_factors, + blender::fn::GMutableSpan dst) const; template<typename T> - void sample_data_based_on_index_factors(const blender::VArray<T> &src, - blender::Span<float> index_factors, - blender::MutableSpan<T> dst) const + void sample_based_on_index_factors(const blender::VArray<T> &src, + blender::Span<float> index_factors, + blender::MutableSpan<T> dst) const { - this->sample_data_based_on_index_factors( + this->sample_based_on_index_factors( blender::fn::GVArray_For_VArray(src), index_factors, blender::fn::GMutableSpan(dst)); } template<typename T> - void sample_data_based_on_index_factors(blender::Span<T> src, - blender::Span<float> index_factors, - blender::MutableSpan<T> dst) const + void sample_based_on_index_factors(blender::Span<T> src, + blender::Span<float> index_factors, + blender::MutableSpan<T> dst) const { - this->sample_data_based_on_index_factors( - blender::fn::GVArray_For_Span(src), index_factors, blender::fn::GMutableSpan(dst)); + this->sample_based_on_index_factors(blender::VArray_For_Span(src), index_factors, dst); } /** diff --git a/source/blender/blenkernel/intern/spline_base.cc b/source/blender/blenkernel/intern/spline_base.cc index 605bf6f9e7b..9f8c215b31f 100644 --- a/source/blender/blenkernel/intern/spline_base.cc +++ b/source/blender/blenkernel/intern/spline_base.cc @@ -241,8 +241,7 @@ Span<float3> Spline::evaluated_normals() const calculate_normals_z_up(tangents, normals); /* Rotate the generated normals with the interpolated tilt data. */ - blender::fn::GVArray_Typed<float> tilts{ - this->interpolate_to_evaluated_points(blender::fn::GVArray_For_Span(this->tilts()))}; + GVArray_Typed<float> tilts = this->interpolate_to_evaluated_points(this->tilts()); for (const int i : normals.index_range()) { normals[i] = rotate_direction_around_axis(normals[i], tangents[i], tilts[i]); } @@ -354,9 +353,14 @@ GVArrayPtr Spline::interpolate_to_evaluated_points(GSpan data) const return this->interpolate_to_evaluated_points(GVArray_For_GSpan(data)); } -void Spline::sample_data_based_on_index_factors(const GVArray &src, - Span<float> index_factors, - GMutableSpan dst) const +/** + * Sample any input data with a value for each evaluated point (already interpolated to evaluated + * points) to arbitrary parameters in betwen the evaluated points. The interpolation is quite + * simple, but this handles the cyclic and end point special cases. + */ +void Spline::sample_based_on_index_factors(const GVArray &src, + Span<float> index_factors, + GMutableSpan dst) const { BLI_assert(src.size() == this->evaluated_points_size()); diff --git a/source/blender/blenkernel/intern/spline_nurbs.cc b/source/blender/blenkernel/intern/spline_nurbs.cc index cae206341a0..bfb0d652b1a 100644 --- a/source/blender/blenkernel/intern/spline_nurbs.cc +++ b/source/blender/blenkernel/intern/spline_nurbs.cc @@ -26,6 +26,7 @@ using blender::float3; using blender::IndexRange; using blender::MutableSpan; using blender::Span; +using blender::fn::GVArray_Typed; SplinePtr NURBSpline::copy() const { @@ -434,10 +435,9 @@ Span<float3> NURBSpline::evaluated_positions() const const int eval_size = this->evaluated_points_size(); evaluated_position_cache_.resize(eval_size); - blender::fn::GVArray_Typed<float3> evaluated_positions{ - this->interpolate_to_evaluated_points(blender::fn::GVArray_For_Span<float3>(positions_))}; - - evaluated_positions->materialize(evaluated_position_cache_); + /* TODO: Avoid copying the evaluated data from the temporary array. */ + GVArray_Typed<float3> evaluated = Spline::interpolate_to_evaluated_points(positions_.as_span()); + evaluated->materialize(evaluated_position_cache_); position_cache_dirty_ = false; return evaluated_position_cache_; diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc index 2e349d4df21..9d0820eb0b0 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc @@ -82,9 +82,11 @@ static SplinePtr resample_spline(const Spline &input_spline, const int count) output_spline->set_cyclic(input_spline.is_cyclic()); output_spline->normal_mode = input_spline.normal_mode; - if (input_spline.evaluated_edges_size() < 1) { - output_spline->resize(1); - output_spline->positions().first() = input_spline.positions().first(); + if (input_spline.evaluated_edges_size() < 1 || count == 1) { + output_spline->add_point(input_spline.positions().first(), + input_spline.tilts().first(), + input_spline.radii().first()); + output_spline->attributes.reallocate(1); return output_spline; } @@ -92,15 +94,15 @@ static SplinePtr resample_spline(const Spline &input_spline, const int count) Array<float> uniform_samples = input_spline.sample_uniform_index_factors(count); - input_spline.sample_data_based_on_index_factors<float3>( + input_spline.sample_based_on_index_factors<float3>( input_spline.evaluated_positions(), uniform_samples, output_spline->positions()); - input_spline.sample_data_based_on_index_factors<float>( + input_spline.sample_based_on_index_factors<float>( input_spline.interpolate_to_evaluated_points(input_spline.radii()), uniform_samples, output_spline->radii()); - input_spline.sample_data_based_on_index_factors<float>( + input_spline.sample_based_on_index_factors<float>( input_spline.interpolate_to_evaluated_points(input_spline.tilts()), uniform_samples, output_spline->tilts()); @@ -121,7 +123,7 @@ static SplinePtr resample_spline(const Spline &input_spline, const int count) return false; } - input_spline.sample_data_based_on_index_factors( + input_spline.sample_based_on_index_factors( *input_spline.interpolate_to_evaluated_points(*input_attribute), uniform_samples, *output_attribute); @@ -146,7 +148,7 @@ static std::unique_ptr<CurveEval> resample_curve(const CurveEval &input_curve, else if (mode_param.mode == GEO_NODE_CURVE_SAMPLE_LENGTH) { BLI_assert(mode_param.length); const float length = spline->length(); - const int count = length / *mode_param.length; + const int count = std::max(int(length / *mode_param.length), 1); output_curve->add_spline(resample_spline(*spline, count)); } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc index fe1b23bf6d7..b6f04352929 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc @@ -181,8 +181,7 @@ static void spline_extrude_to_mesh_data(const Spline &spline, Span<float3> normals = spline.evaluated_normals(); Span<float3> profile_positions = profile_spline.evaluated_positions(); - GVArray_Typed<float> radii{ - spline.interpolate_to_evaluated_points(blender::fn::GVArray_For_Span(spline.radii()))}; + GVArray_Typed<float> radii = spline.interpolate_to_evaluated_points(spline.radii()); for (const int i_ring : IndexRange(spline_vert_len)) { float4x4 point_matrix = float4x4::from_normalized_axis_data( positions[i_ring], normals[i_ring], tangents[i_ring]); diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc index ce82182c7df..069b9031466 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc @@ -236,15 +236,15 @@ static void copy_uniform_sample_point_attributes(Span<SplinePtr> splines, const Array<float> uniform_samples = spline.sample_uniform_index_factors(size); - spline.sample_data_based_on_index_factors<float3>( + spline.sample_based_on_index_factors<float3>( spline.evaluated_positions(), uniform_samples, data.positions.slice(offset, size)); - spline.sample_data_based_on_index_factors<float>( + spline.sample_based_on_index_factors<float>( spline.interpolate_to_evaluated_points(spline.radii()), uniform_samples, data.radii.slice(offset, size)); - spline.sample_data_based_on_index_factors<float>( + spline.sample_based_on_index_factors<float>( spline.interpolate_to_evaluated_points(spline.tilts()), uniform_samples, data.tilts.slice(offset, size)); @@ -256,19 +256,18 @@ static void copy_uniform_sample_point_attributes(Span<SplinePtr> splines, BLI_assert(spline.attributes.get_for_read(name)); GSpan spline_span = *spline.attributes.get_for_read(name); - spline.sample_data_based_on_index_factors( - *spline.interpolate_to_evaluated_points(spline_span), - uniform_samples, - point_span.slice(offset, size)); + spline.sample_based_on_index_factors(*spline.interpolate_to_evaluated_points(spline_span), + uniform_samples, + point_span.slice(offset, size)); } - spline.sample_data_based_on_index_factors<float3>( + spline.sample_based_on_index_factors<float3>( spline.evaluated_tangents(), uniform_samples, data.tangents.slice(offset, size)); for (float3 &tangent : data.tangents) { tangent.normalize(); } - spline.sample_data_based_on_index_factors<float3>( + spline.sample_based_on_index_factors<float3>( spline.evaluated_normals(), uniform_samples, data.normals.slice(offset, size)); for (float3 &normals : data.normals) { normals.normalize(); |