[Bf-blender-cvs] [6a1ab4747b7] master: Geometry Nodes: Copy parameters when copying a curves data-block

Hans Goudey noreply at git.blender.org
Tue Jul 19 17:15:48 CEST 2022


Commit: 6a1ab4747b7758017721cb191046a9db800f7894
Author: Hans Goudey
Date:   Tue Jul 19 10:14:46 2022 -0500
Branches: master
https://developer.blender.org/rB6a1ab4747b7758017721cb191046a9db800f7894

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

===================================================================

M	source/blender/blenkernel/BKE_curves.hh
M	source/blender/blenkernel/BKE_curves_utils.hh
M	source/blender/blenkernel/intern/curves.cc
M	source/blender/blenkernel/intern/curves_utils.cc
M	source/blender/geometry/GEO_mesh_to_curve.hh
M	source/blender/geometry/GEO_set_curve_type.hh
M	source/blender/geometry/GEO_subdivide_curves.hh
M	source/blender/geometry/intern/mesh_to_curve_convert.cc
M	source/blender/geometry/intern/realize_instances.cc
M	source/blender/geometry/intern/set_curve_type.cc
M	source/blender/geometry/intern/subdivide_curves.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
M	source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_to_curve.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh
index fb97e52f6da..25a912b8825 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -735,6 +735,12 @@ Curves *curves_new_nomain(CurvesGeometry curves);
  */
 Curves *curves_new_nomain_single(int points_num, CurveType type);
 
+/**
+ * Copy data from #src to #dst, except the geometry data in #CurvesGeometry. Typically used to
+ * copy high-level parameters when a geometry-altering operation creates a new curves data-block.
+ */
+void curves_copy_parameters(const Curves &src, Curves &dst);
+
 std::array<int, CURVE_TYPES_NUM> calculate_type_counts(const VArray<int8_t> &types);
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/BKE_curves_utils.hh b/source/blender/blenkernel/BKE_curves_utils.hh
index f223e173ea9..0fbd33002e1 100644
--- a/source/blender/blenkernel/BKE_curves_utils.hh
+++ b/source/blender/blenkernel/BKE_curves_utils.hh
@@ -55,6 +55,13 @@ void fill_points(const CurvesGeometry &curves,
   fill_points(curves, curve_selection, &value, dst);
 }
 
+/**
+ * Copy only the information on the point domain, but not the offsets or any point attributes,
+ * meant for operations that change the number of points but not the number of curves.
+ * \warning The returned curves have invalid offsets!
+ */
+bke::CurvesGeometry copy_only_curve_domain(const bke::CurvesGeometry &src_curves);
+
 /**
  * Copy the size of every curve in #curve_ranges to the corresponding index in #counts.
  */
diff --git a/source/blender/blenkernel/intern/curves.cc b/source/blender/blenkernel/intern/curves.cc
index 78791b55b4d..7e9f994313b 100644
--- a/source/blender/blenkernel/intern/curves.cc
+++ b/source/blender/blenkernel/intern/curves.cc
@@ -388,6 +388,23 @@ Curves *curves_new_nomain(CurvesGeometry curves)
   return curves_id;
 }
 
+void curves_copy_parameters(const Curves &src, Curves &dst)
+{
+  dst.flag = src.flag;
+  dst.attributes_active_index = src.attributes_active_index;
+  MEM_SAFE_FREE(dst.mat);
+  dst.mat = static_cast<Material **>(MEM_malloc_arrayN(src.totcol, sizeof(Material *), __func__));
+  dst.totcol = src.totcol;
+  MutableSpan(dst.mat, dst.totcol).copy_from(Span(src.mat, src.totcol));
+  dst.symmetry = src.symmetry;
+  dst.selection_domain = src.selection_domain;
+  dst.surface = src.surface;
+  MEM_SAFE_FREE(dst.surface_uv_map);
+  if (src.surface_uv_map != nullptr) {
+    dst.surface_uv_map = BLI_strdup(src.surface_uv_map);
+  }
+}
+
 CurvesSurfaceTransforms::CurvesSurfaceTransforms(const Object &curves_ob, const Object *surface_ob)
 {
   this->curves_to_world = curves_ob.obmat;
diff --git a/source/blender/blenkernel/intern/curves_utils.cc b/source/blender/blenkernel/intern/curves_utils.cc
index f7db60ee588..d98832e796c 100644
--- a/source/blender/blenkernel/intern/curves_utils.cc
+++ b/source/blender/blenkernel/intern/curves_utils.cc
@@ -84,6 +84,18 @@ void fill_points(const CurvesGeometry &curves,
   });
 }
 
+bke::CurvesGeometry copy_only_curve_domain(const bke::CurvesGeometry &src_curves)
+{
+  bke::CurvesGeometry dst_curves(0, src_curves.curves_num());
+  CustomData_copy(&src_curves.curve_data,
+                  &dst_curves.curve_data,
+                  CD_MASK_ALL,
+                  CD_DUPLICATE,
+                  src_curves.curves_num());
+  dst_curves.runtime->type_counts = src_curves.runtime->type_counts;
+  return dst_curves;
+}
+
 IndexMask indices_for_type(const VArray<int8_t> &types,
                            const std::array<int, CURVE_TYPES_NUM> &type_counts,
                            const CurveType type,
diff --git a/source/blender/geometry/GEO_mesh_to_curve.hh b/source/blender/geometry/GEO_mesh_to_curve.hh
index c480e4178cf..f619aaff217 100644
--- a/source/blender/geometry/GEO_mesh_to_curve.hh
+++ b/source/blender/geometry/GEO_mesh_to_curve.hh
@@ -1,12 +1,12 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 
+#pragma once
+
 #include "BLI_index_mask.hh"
 
-#pragma once
+#include "BKE_curves.hh"
 
 struct Mesh;
-struct Curves;
-class MeshComponent;
 
 /** \file
  * \ingroup geo
@@ -15,10 +15,10 @@ class MeshComponent;
 namespace blender::geometry {
 
 /**
- * Convert the mesh into one or many poly splines. Since splines cannot have branches,
- * intersections of more than three edges will become breaks in splines. Attributes that
+ * Convert the mesh into one or many poly curves. Since curves cannot have branches,
+ * intersections of more than three edges will become breaks in curves. Attributes that
  * are not built-in on meshes and not curves are transferred to the result curve.
  */
-Curves *mesh_to_curve_convert(const MeshComponent &mesh_component, const IndexMask selection);
+bke::CurvesGeometry mesh_to_curve_convert(const Mesh &mesh, const IndexMask selection);
 
 }  // namespace blender::geometry
diff --git a/source/blender/geometry/GEO_set_curve_type.hh b/source/blender/geometry/GEO_set_curve_type.hh
index 6a75450006b..f38e63b1fc8 100644
--- a/source/blender/geometry/GEO_set_curve_type.hh
+++ b/source/blender/geometry/GEO_set_curve_type.hh
@@ -2,17 +2,10 @@
 
 #pragma once
 
-#include "DNA_curves_types.h"
-
 #include "BLI_function_ref.hh"
 #include "BLI_index_mask.hh"
 
-struct Curves;
-class CurveComponent;
-
-namespace blender::bke {
-class CurvesGeometry;
-}
+#include "BKE_curves.hh"
 
 namespace blender::geometry {
 
@@ -27,14 +20,13 @@ namespace blender::geometry {
  */
 bool try_curves_conversion_in_place(IndexMask selection,
                                     CurveType dst_type,
-                                    FunctionRef<Curves &()> get_writable_curves_fn);
+                                    FunctionRef<bke::CurvesGeometry &()> get_writable_curves_fn);
 
 /**
  * Change the types of the selected curves, potentially changing the total point count.
  */
-Curves *convert_curves(const CurveComponent &src_component,
-                       const bke::CurvesGeometry &src_curves,
-                       IndexMask selection,
-                       CurveType dst_type);
+bke::CurvesGeometry convert_curves(const bke::CurvesGeometry &src_curves,
+                                   IndexMask selection,
+                                   CurveType dst_type);
 
 }  // namespace blender::geometry
diff --git a/source/blender/geometry/GEO_subdivide_curves.hh b/source/blender/geometry/GEO_subdivide_curves.hh
index 66c2eb53496..ba55118baa4 100644
--- a/source/blender/geometry/GEO_subdivide_curves.hh
+++ b/source/blender/geometry/GEO_subdivide_curves.hh
@@ -4,11 +4,10 @@
 
 #include "BLI_function_ref.hh"
 #include "BLI_index_mask.hh"
+#include "BLI_virtual_array.hh"
 
 #include "BKE_curves.hh"
 
-class CurveComponent;
-
 namespace blender::geometry {
 
 /**
@@ -18,9 +17,8 @@ namespace blender::geometry {
  *
  * \param selection: A selection of curves to consider when subdividing.
  */
-Curves *subdivide_curves(const CurveComponent &src_component,
-                         const bke::CurvesGeometry &src_curves,
-                         IndexMask selection,
-                         const VArray<int> &cuts);
+bke::CurvesGeometry subdivide_curves(const bke::CurvesGeometry &src_curves,
+                                     IndexMask selection,
+                                     const VArray<int> &cuts);
 
 }  // namespace blender::geometry
diff --git a/source/blender/geometry/intern/mesh_to_curve_convert.cc b/source/blender/geometry/intern/mesh_to_curve_convert.cc
index 681dfd15137..fdacb174462 100644
--- a/source/blender/geometry/intern/mesh_to_curve_convert.cc
+++ b/source/blender/geometry/intern/mesh_to_curve_convert.cc
@@ -30,13 +30,12 @@ static void copy_with_map(const VArray<T> &src, Span<int> map, MutableSpan<T> ds
   });
 }
 
-static Curves *create_curve_from_vert_indices(const MeshComponent &mesh_component,
-                                              const Span<int> vert_indices,
-                                              const Span<int> curve_offsets,
-                                              const IndexRange cyclic_curves)
+static bke::CurvesGeometry create_curve_from_vert_indices(const Mesh &mesh,
+                                                          const Span<int> vert_indices,
+                                                          const Span<int> curve_offsets,
+                                                          const IndexRange cyclic_curves)
 {
-  Curves *curves_id = bke::curves_new_nomain(vert_indices.size(), curve_offsets.size());
-  bke::CurvesGeometry &curves = bke::CurvesGeometry::wrap(curves_id->geometry);
+  bke::CurvesGeometry curves(vert_indices.size(), curve_offsets.size());
   curves.offsets_for_write().drop_back(1).copy_from(curve_offsets);
   curves.offsets_for_write().last() = vert_indices.size();
   curves.fill_curve_types(CURVE_TYPE_POLY);
@@ -44,8 +43,8 @@ static Curves *create_curve_from_vert_indices(const MeshComponent &mesh_componen
   curves.cyclic_for_write().fill(false);
   curves.cyclic_for_write().slice(cyclic_curves).fill(true);
 
+  const bke::AttributeAccessor mesh_attributes = bke::mesh_attributes(mesh);
   bke::MutableAttributeAccessor curves_attributes = curves.attributes_for_write();
-  const bke::AttributeAccessor mesh_attributes = *mesh_component.attributes();
 
   Set<bke::AttributeIDRef> source_attribute_ids = mesh_attributes.all_ids();
 
@@ -76,7 +75,7 @@ static Curves *create_curve_from_vert_indices(const MeshComponent &mesh_componen
     });
   }
 
-  return curves_id;
+  return curves;
 }
 
 struct CurveFromEdgesOutput {
@@ -220,16 +219,14 @@ static Vector<std::pair<int, int>> get_selected_edges(const Mesh &mesh, const In
   return selected_edges;
 }
 
-Curves *mesh_to_curve_convert(const MeshComponent &mesh_component, const IndexMask selection)
+bke::CurvesGeometry mesh_to_curve_convert(const Mesh &mesh, const IndexMask selection)
 {
-  const Mesh &mesh = *mesh_component.get_for_read();
-  Vector<std::pair<int, int>> selected_edges = get_selected_edges(*mesh_component.get_for_read(),
-                                                                  selection);
+  Vector<std::pair<int, int>> selected_edges = get_selected_edg

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list