From 96bdd65e740e669eceb18258dbc4b27d268d10aa Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 26 Apr 2022 08:07:54 -0500 Subject: 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 --- source/blender/editors/object/object_modifier.cc | 37 ++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) 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(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().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(); + 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; } -- cgit v1.2.3