[Bf-blender-cvs] [b500099e5c2] geometry-nodes-curve-support: Geometry Nodes Curves: Add generic interpolattion to evaluated points
Hans Goudey
noreply at git.blender.org
Fri Apr 16 22:33:29 CEST 2021
Commit: b500099e5c26feb8f97e57f999d6a94ca0614e69
Author: Hans Goudey
Date: Fri Apr 16 15:33:15 2021 -0500
Branches: geometry-nodes-curve-support
https://developer.blender.org/rBb500099e5c26feb8f97e57f999d6a94ca0614e69
Geometry Nodes Curves: Add generic interpolattion to evaluated points
===================================================================
M source/blender/blenkernel/BKE_attribute_math.hh
M source/blender/blenkernel/BKE_derived_curve.hh
M source/blender/blenkernel/intern/derived_curve.cc
M source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_attribute_math.hh b/source/blender/blenkernel/BKE_attribute_math.hh
index 16fc0db60fb..d97ae9362e7 100644
--- a/source/blender/blenkernel/BKE_attribute_math.hh
+++ b/source/blender/blenkernel/BKE_attribute_math.hh
@@ -14,6 +14,8 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#pragma once
+
#include "BLI_array.hh"
#include "BLI_color.hh"
#include "BLI_float2.hh"
diff --git a/source/blender/blenkernel/BKE_derived_curve.hh b/source/blender/blenkernel/BKE_derived_curve.hh
index 232f069ffa9..90af9f6a848 100644
--- a/source/blender/blenkernel/BKE_derived_curve.hh
+++ b/source/blender/blenkernel/BKE_derived_curve.hh
@@ -26,6 +26,7 @@
#include "BLI_float4x4.hh"
#include "BLI_vector.hh"
+#include "BKE_attribute_math.hh"
#include "BKE_curve.h"
struct Curve;
@@ -132,8 +133,31 @@ class Spline {
blender::Span<blender::float3> evaluated_tangents() const;
blender::Span<blender::float3> evaluated_normals() const;
- /* TODO: I'm not sure this is the best abstraction here, maybe we want another cache. */
- float get_evaluated_point_radius(const int index) const;
+ /* TODO: Check for null default mixer. Use std::enable_if? */
+ template<typename T>
+ void interpolate_data_to_evaluated_points(blender::Span<T> source_data,
+ blender::MutableSpan<T> result_data) const
+ {
+ const int control_points_len = this->size();
+ blender::Span<PointMapping> mappings = this->evaluated_mappings();
+
+ blender::attribute_math::DefaultMixer<T> mixer(result_data);
+
+ for (const int evaluated_point_index : mappings.index_range()) {
+ const PointMapping &mapping = mappings[evaluated_point_index];
+ const int index = mapping.control_point_index;
+ const int next_index = (index + 1) % control_points_len;
+ const float factor = mapping.factor;
+
+ const T &value = source_data[index];
+ const T &next_value = source_data[next_index];
+
+ mixer.mix_in(evaluated_point_index, value, 1.0f - factor);
+ mixer.mix_in(evaluated_point_index, next_value, factor);
+ }
+
+ mixer.finalize();
+ }
protected:
virtual void correct_end_tangents() const = 0;
diff --git a/source/blender/blenkernel/intern/derived_curve.cc b/source/blender/blenkernel/intern/derived_curve.cc
index ca8f73b3ca5..d13cc9954c6 100644
--- a/source/blender/blenkernel/intern/derived_curve.cc
+++ b/source/blender/blenkernel/intern/derived_curve.cc
@@ -491,22 +491,6 @@ void Spline::mark_cache_invalid()
length_cache_dirty_ = true;
}
-float Spline::get_evaluated_point_radius(const int evaluated_index) const
-{
- this->ensure_base_cache();
- Span<PointMapping> mappings = this->evaluated_mapping_cache_;
-
- const PointMapping &mapping = mappings[evaluated_index];
- const int index = mapping.control_point_index;
- const float factor = mapping.factor;
-
- const float radius = this->radii()[index];
- const int next_index = (index == this->size() - 1) ? 0 : index + 1;
- const float next_radius = this->radii()[next_index];
-
- return interpf(next_radius, radius, factor);
-}
-
/** \} */
/* -------------------------------------------------------------------- */
@@ -620,26 +604,28 @@ void BezierSpline::add_point(const float3 position,
void BezierSpline::drop_front(const int count)
{
BLI_assert(this->size() - count > 0);
- vector_drop_front(handle_types_start_, count);
- vector_drop_front(handle_positions_start_, count);
- vector_drop_front(positions_, count);
- vector_drop_front(handle_types_end_, count);
- vector_drop_front(handle_positions_end_, count);
- vector_drop_front(radii_, count);
- vector_drop_front(tilts_, count);
+ vector_drop_front(this->handle_types_start_, count);
+ vector_drop_front(this->handle_positions_start_, count);
+ vector_drop_front(this->positions_, count);
+ vector_drop_front(this->handle_types_end_, count);
+ vector_drop_front(this->handle_positions_end_, count);
+ vector_drop_front(this->radii_, count);
+ vector_drop_front(this->tilts_, count);
+ this->mark_cache_invalid();
}
void BezierSpline::drop_back(const int count)
{
const int new_size = this->size() - count;
BLI_assert(new_size > 0);
- handle_types_start_.resize(new_size);
- handle_positions_start_.resize(new_size);
- positions_.resize(new_size);
- handle_types_end_.resize(new_size);
- handle_positions_end_.resize(new_size);
- radii_.resize(new_size);
- tilts_.resize(new_size);
+ this->handle_types_start_.resize(new_size);
+ this->handle_positions_start_.resize(new_size);
+ this->positions_.resize(new_size);
+ this->handle_types_end_.resize(new_size);
+ this->handle_positions_end_.resize(new_size);
+ this->radii_.resize(new_size);
+ this->tilts_.resize(new_size);
+ this->mark_cache_invalid();
}
bool BezierSpline::segment_is_vector(const int index) const
@@ -879,20 +865,22 @@ void NURBSpline::add_point(const float3 position,
void NURBSpline::drop_front(const int count)
{
BLI_assert(this->size() - count > 0);
- vector_drop_front(positions_, count);
- vector_drop_front(radii_, count);
- vector_drop_front(tilts_, count);
- vector_drop_front(weights_, count);
+ vector_drop_front(this->positions_, count);
+ vector_drop_front(this->radii_, count);
+ vector_drop_front(this->tilts_, count);
+ vector_drop_front(this->weights_, count);
+ this->mark_cache_invalid();
}
void NURBSpline::drop_back(const int count)
{
const int new_size = this->size() - count;
BLI_assert(new_size > 0);
- positions_.resize(new_size);
- radii_.resize(new_size);
- tilts_.resize(new_size);
- weights_.resize(new_size);
+ this->positions_.resize(new_size);
+ this->radii_.resize(new_size);
+ this->tilts_.resize(new_size);
+ this->weights_.resize(new_size);
+ this->mark_cache_invalid();
}
MutableSpan<float3> NURBSpline::positions()
@@ -982,18 +970,20 @@ void PolySpline::add_point(const float3 position, const float radius, const floa
void PolySpline::drop_front(const int count)
{
BLI_assert(this->size() - count > 0);
- vector_drop_front(positions_, count);
- vector_drop_front(radii_, count);
- vector_drop_front(tilts_, count);
+ vector_drop_front(this->positions_, count);
+ vector_drop_front(this->radii_, count);
+ vector_drop_front(this->tilts_, count);
+ this->mark_cache_invalid();
}
void PolySpline::drop_back(const int count)
{
const int new_size = this->size() - count;
BLI_assert(new_size > 0);
- positions_.resize(new_size);
- radii_.resize(new_size);
- tilts_.resize(new_size);
+ this->positions_.resize(new_size);
+ this->radii_.resize(new_size);
+ this->tilts_.resize(new_size);
+ this->mark_cache_invalid();
}
MutableSpan<float3> PolySpline::positions()
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 085d32e7b34..19a5f0660ca 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
@@ -14,7 +14,9 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include "BLI_array.hh"
#include "BLI_float4x4.hh"
+#include "BLI_timeit.hh"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -38,6 +40,8 @@ static bNodeSocketTemplate geo_node_curve_to_mesh_out[] = {
{-1, ""},
};
+using blender::Array;
+
namespace blender::nodes {
static void vert_extrude_to_mesh_data(const Spline &spline,
@@ -179,12 +183,13 @@ static void spline_extrude_to_mesh_data(const Spline &spline,
Span<float3> tangents = spline.evaluated_tangents();
Span<float3> normals = spline.evaluated_normals();
Span<float3> profile_positions = profile_spline.evaluated_positions();
+ Array<float> radii(spline_vert_len);
+ spline.interpolate_data_to_evaluated_points<float>(spline.radii(), radii);
for (const int i_ring : IndexRange(spline_vert_len)) {
float4x4 point_matrix = float4x4::from_normalized_axis_data(
positions[i_ring], tangents[i_ring], normals[i_ring]);
- const float radius = spline.get_evaluated_point_radius(i_ring);
- point_matrix.apply_scale(radius);
+ point_matrix.apply_scale(radii[i_ring]);
for (const int i_profile : IndexRange(profile_vert_len)) {
MVert &vert = verts[vert_offset++];
More information about the Bf-blender-cvs
mailing list