[Bf-blender-cvs] [96bdd65e740] master: Curves: Support applying geometry nodes modifier

Hans Goudey noreply at git.blender.org
Tue Apr 26 15:08:01 CEST 2022


Commit: 96bdd65e740e669eceb18258dbc4b27d268d10aa
Author: Hans Goudey
Date:   Tue Apr 26 08:07:54 2022 -0500
Branches: master
https://developer.blender.org/rB96bdd65e740e669eceb18258dbc4b27d268d10aa

Curves: Support applying geometry nodes modifier

This commit adds support for the curves object to the apply modifier
operator. A warning is added when the evaluated result of the modifier
doesn't contain any curves data.

Differential Revision: https://developer.blender.org/D14730

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

M	source/blender/editors/object/object_modifier.cc

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

diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc
index 8dec2a5eb1c..f90a31a7cbe 100644
--- a/source/blender/editors/object/object_modifier.cc
+++ b/source/blender/editors/object/object_modifier.cc
@@ -38,6 +38,7 @@
 #include "BKE_context.h"
 #include "BKE_curve.h"
 #include "BKE_curves.h"
+#include "BKE_curves.hh"
 #include "BKE_displist.h"
 #include "BKE_editmesh.h"
 #include "BKE_effect.h"
@@ -701,7 +702,6 @@ static bool modifier_apply_shape(Main *bmain,
     BKE_id_free(nullptr, mesh_applied);
   }
   else {
-    /* TODO: implement for curves, point clouds and volumes. */
     BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
     return false;
   }
@@ -804,8 +804,41 @@ static bool modifier_apply_obdata(
 
     DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
   }
+  else if (ob->type == OB_CURVES) {
+    Curves &curves = *static_cast<Curves *>(ob->data);
+    if (mti->modifyGeometrySet == nullptr) {
+      BLI_assert_unreachable();
+      return false;
+    }
+
+    /* Create a temporary geometry set and component. */
+    GeometrySet geometry_set;
+    geometry_set.get_component_for_write<CurveComponent>().replace(
+        &curves, GeometryOwnershipType::Editable);
+
+    ModifierEvalContext mectx = {depsgraph, ob, (ModifierApplyFlag)0};
+    mti->modifyGeometrySet(md_eval, &mectx, &geometry_set);
+    if (!geometry_set.has_curves()) {
+      BKE_report(reports, RPT_ERROR, "Evaluated geometry from modifier does not contain curves");
+      return false;
+    }
+    CurveComponent &component = geometry_set.get_component_for_write<CurveComponent>();
+    Curves &curves_eval = *geometry_set.get_curves_for_write();
+
+    /* Anonymous attributes shouldn't be available on the applied geometry. */
+    component.attributes_remove_anonymous();
+
+    /* If the modifier's output is a different curves data-block, copy the relevant information to
+     * the original. */
+    if (&curves_eval != &curves) {
+      blender::bke::CurvesGeometry::wrap(curves.geometry) = std::move(
+          blender::bke::CurvesGeometry::wrap(curves_eval.geometry));
+      Main *bmain = DEG_get_bmain(depsgraph);
+      BKE_object_material_from_eval_data(bmain, ob, &curves_eval.id);
+    }
+  }
   else {
-    /* TODO: implement for curves, point clouds and volumes. */
+    /* TODO: implement for point clouds and volumes. */
     BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
     return false;
   }



More information about the Bf-blender-cvs mailing list