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-07-19 18:14:46 +0300
committerHans Goudey <h.goudey@me.com>2022-07-19 18:16:30 +0300
commit6a1ab4747b7758017721cb191046a9db800f7894 (patch)
treea3e28d26c96c2070b231bcb6c5f6a9b0409361aa /source/blender/geometry/intern/set_curve_type.cc
parent9246ff373a19df24255d924979c78793f97b2834 (diff)
Geometry Nodes: Copy parameters when copying a curves data-block
Previously, things like materials, symmetry, and selection options stored on `Curves` weren't copied to the result in nodes like the subdivide and resample nodes. Now they are, which fixes some unexpected behavior and allows visualization of the sculpt mode selection. In the realize instances and join nodes the behavior is the same as for meshes, the parameters are taken from the first (top) input. I also refactored some functions to return a `CurvesGeometry` by-value, which makes it the responsibility of the node to copy the parameters. That should make the algorithms more reusable in other situations. Differential Revision: https://developer.blender.org/D15408
Diffstat (limited to 'source/blender/geometry/intern/set_curve_type.cc')
-rw-r--r--source/blender/geometry/intern/set_curve_type.cc76
1 files changed, 24 insertions, 52 deletions
diff --git a/source/blender/geometry/intern/set_curve_type.cc b/source/blender/geometry/intern/set_curve_type.cc
index 08888a74973..40ee2488a4b 100644
--- a/source/blender/geometry/intern/set_curve_type.cc
+++ b/source/blender/geometry/intern/set_curve_type.cc
@@ -1,9 +1,9 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
+#include "BKE_attribute.hh"
#include "BKE_attribute_math.hh"
#include "BKE_curves.hh"
#include "BKE_curves_utils.hh"
-#include "BKE_geometry_set.hh"
#include "BLI_task.hh"
@@ -322,39 +322,16 @@ static void retrieve_generic_point_attributes(const bke::AttributeAccessor &src_
});
}
-static Curves *create_result_curves(const bke::CurvesGeometry &src_curves,
- const IndexMask selection,
- const CurveType dst_type)
-{
- Curves *dst_curves_id = bke::curves_new_nomain(0, src_curves.curves_num());
- bke::CurvesGeometry &dst_curves = bke::CurvesGeometry::wrap(dst_curves_id->geometry);
- CurveComponent dst_component;
- dst_component.replace(dst_curves_id, GeometryOwnershipType::Editable);
- /* Directly copy curve attributes, since they stay the same (except for curve types). */
- CustomData_copy(&src_curves.curve_data,
- &dst_curves.curve_data,
- CD_MASK_ALL,
- CD_DUPLICATE,
- src_curves.curves_num());
-
- dst_curves.fill_curve_types(selection, dst_type);
-
- return dst_curves_id;
-}
-
-static Curves *convert_curves_to_bezier(const CurveComponent &src_component,
- const bke::CurvesGeometry &src_curves,
- const IndexMask selection)
+static bke::CurvesGeometry convert_curves_to_bezier(const bke::CurvesGeometry &src_curves,
+ const IndexMask selection)
{
const VArray<int8_t> src_knot_modes = src_curves.nurbs_knots_modes();
const VArray<int8_t> src_types = src_curves.curve_types();
const VArray<bool> src_cyclic = src_curves.cyclic();
const Span<float3> src_positions = src_curves.positions();
- Curves *dst_curves_id = create_result_curves(src_curves, selection, CURVE_TYPE_BEZIER);
- bke::CurvesGeometry &dst_curves = bke::CurvesGeometry::wrap(dst_curves_id->geometry);
- CurveComponent dst_component;
- dst_component.replace(dst_curves_id, GeometryOwnershipType::Editable);
+ bke::CurvesGeometry dst_curves = bke::curves::copy_only_curve_domain(src_curves);
+ dst_curves.fill_curve_types(selection, CURVE_TYPE_BEZIER);
MutableSpan<int> dst_offsets = dst_curves.offsets_for_write();
retrieve_curve_sizes(src_curves, dst_curves.offsets_for_write());
@@ -367,8 +344,8 @@ static Curves *convert_curves_to_bezier(const CurveComponent &src_component,
bke::curves::accumulate_counts_to_offsets(dst_offsets);
dst_curves.resize(dst_offsets.last(), dst_curves.curves_num());
- const bke::AttributeAccessor src_attributes = *src_component.attributes();
- bke::MutableAttributeAccessor dst_attributes = *dst_component.attributes_for_write();
+ const bke::AttributeAccessor src_attributes = src_curves.attributes();
+ bke::MutableAttributeAccessor dst_attributes = dst_curves.attributes_for_write();
GenericAttributes attributes;
retrieve_generic_point_attributes(src_attributes, dst_attributes, attributes);
@@ -501,21 +478,18 @@ static Curves *convert_curves_to_bezier(const CurveComponent &src_component,
attribute.finish();
}
- return dst_curves_id;
+ return dst_curves;
}
-static Curves *convert_curves_to_nurbs(const CurveComponent &src_component,
- const bke::CurvesGeometry &src_curves,
- const IndexMask selection)
+static bke::CurvesGeometry convert_curves_to_nurbs(const bke::CurvesGeometry &src_curves,
+ const IndexMask selection)
{
const VArray<int8_t> src_types = src_curves.curve_types();
const VArray<bool> src_cyclic = src_curves.cyclic();
const Span<float3> src_positions = src_curves.positions();
- Curves *dst_curves_id = create_result_curves(src_curves, selection, CURVE_TYPE_NURBS);
- bke::CurvesGeometry &dst_curves = bke::CurvesGeometry::wrap(dst_curves_id->geometry);
- CurveComponent dst_component;
- dst_component.replace(dst_curves_id, GeometryOwnershipType::Editable);
+ bke::CurvesGeometry dst_curves = bke::curves::copy_only_curve_domain(src_curves);
+ dst_curves.fill_curve_types(selection, CURVE_TYPE_NURBS);
MutableSpan<int> dst_offsets = dst_curves.offsets_for_write();
retrieve_curve_sizes(src_curves, dst_curves.offsets_for_write());
@@ -527,8 +501,8 @@ static Curves *convert_curves_to_nurbs(const CurveComponent &src_component,
bke::curves::accumulate_counts_to_offsets(dst_offsets);
dst_curves.resize(dst_offsets.last(), dst_curves.curves_num());
- const bke::AttributeAccessor src_attributes = *src_component.attributes();
- bke::MutableAttributeAccessor dst_attributes = *dst_component.attributes_for_write();
+ const bke::AttributeAccessor src_attributes = src_curves.attributes();
+ bke::MutableAttributeAccessor dst_attributes = dst_curves.attributes_for_write();
GenericAttributes attributes;
retrieve_generic_point_attributes(src_attributes, dst_attributes, attributes);
@@ -669,7 +643,7 @@ static Curves *convert_curves_to_nurbs(const CurveComponent &src_component,
attribute.finish();
}
- return dst_curves_id;
+ return dst_curves;
}
static bke::CurvesGeometry convert_curves_trivial(const bke::CurvesGeometry &src_curves,
@@ -682,33 +656,31 @@ static bke::CurvesGeometry convert_curves_trivial(const bke::CurvesGeometry &src
return dst_curves;
}
-Curves *convert_curves(const CurveComponent &src_component,
- const bke::CurvesGeometry &src_curves,
- const IndexMask selection,
- const CurveType dst_type)
+bke::CurvesGeometry convert_curves(const bke::CurvesGeometry &src_curves,
+ const IndexMask selection,
+ const CurveType dst_type)
{
switch (dst_type) {
case CURVE_TYPE_CATMULL_ROM:
case CURVE_TYPE_POLY:
- return bke::curves_new_nomain(convert_curves_trivial(src_curves, selection, dst_type));
+ return convert_curves_trivial(src_curves, selection, dst_type);
case CURVE_TYPE_BEZIER:
- return convert_curves_to_bezier(src_component, src_curves, selection);
+ return convert_curves_to_bezier(src_curves, selection);
case CURVE_TYPE_NURBS:
- return convert_curves_to_nurbs(src_component, src_curves, selection);
+ return convert_curves_to_nurbs(src_curves, selection);
}
BLI_assert_unreachable();
- return nullptr;
+ return {};
}
bool try_curves_conversion_in_place(const IndexMask selection,
const CurveType dst_type,
- FunctionRef<Curves &()> get_writable_curves_fn)
+ FunctionRef<bke::CurvesGeometry &()> get_writable_curves_fn)
{
if (conversion_can_change_point_num(dst_type)) {
return false;
}
- Curves &curves_id = get_writable_curves_fn();
- bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id.geometry);
+ bke::CurvesGeometry &curves = get_writable_curves_fn();
curves.fill_curve_types(selection, dst_type);
curves.remove_attributes_based_on_types();
return true;