diff options
Diffstat (limited to 'source/blender/editors/object/object_modifier.cc')
-rw-r--r-- | source/blender/editors/object/object_modifier.cc | 37 |
1 files 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<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; } |