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
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
#include "BKE_context.h"
|
#include "BKE_context.h"
|
||||||
#include "BKE_curve.h"
|
#include "BKE_curve.h"
|
||||||
#include "BKE_curves.h"
|
#include "BKE_curves.h"
|
||||||
|
#include "BKE_curves.hh"
|
||||||
#include "BKE_displist.h"
|
#include "BKE_displist.h"
|
||||||
#include "BKE_editmesh.h"
|
#include "BKE_editmesh.h"
|
||||||
#include "BKE_effect.h"
|
#include "BKE_effect.h"
|
||||||
@@ -701,7 +702,6 @@ static bool modifier_apply_shape(Main *bmain,
|
|||||||
BKE_id_free(nullptr, mesh_applied);
|
BKE_id_free(nullptr, mesh_applied);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* TODO: implement for curves, point clouds and volumes. */
|
|
||||||
BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
|
BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -804,8 +804,41 @@ static bool modifier_apply_obdata(
|
|||||||
|
|
||||||
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
|
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 {
|
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");
|
BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user