diff options
author | Jacques Lucke <jacques@blender.org> | 2022-04-15 10:07:00 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-04-15 10:08:50 +0300 |
commit | 2839fe9a4d30c5737ab5075d0610c54568688fcb (patch) | |
tree | b3d58776d83c985c6672ab1e3eb138e50448f8c3 /source/blender/blenkernel/intern/curves.cc | |
parent | db6287873cd2c79741439f4d141c4b2db517d73e (diff) |
Curves: initial geometry nodes support for curves objects
* Curves objects now support the geometry nodes modifier.
* It's possible to use the curves object with the Object Info node.
* The spreadsheet shows the curve data.
The main thing holding this back currently is that the drawing code
for the curves object is very incomplete. E.g. it resamples the curves
always in the end, which is not expected for curves in general.
Differential Revision: https://developer.blender.org/D14277
Diffstat (limited to 'source/blender/blenkernel/intern/curves.cc')
-rw-r--r-- | source/blender/blenkernel/intern/curves.cc | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/curves.cc b/source/blender/blenkernel/intern/curves.cc index ebbdff55a55..5b51fb8af31 100644 --- a/source/blender/blenkernel/intern/curves.cc +++ b/source/blender/blenkernel/intern/curves.cc @@ -27,6 +27,7 @@ #include "BKE_anim_data.h" #include "BKE_curves.hh" #include "BKE_customdata.h" +#include "BKE_geometry_set.hh" #include "BKE_global.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" @@ -282,13 +283,11 @@ Curves *BKE_curves_copy_for_eval(Curves *curves_src, bool reference) return result; } -static Curves *curves_evaluate_modifiers(struct Depsgraph *depsgraph, - struct Scene *scene, - Object *object, - Curves *curves_input) +static void curves_evaluate_modifiers(struct Depsgraph *depsgraph, + struct Scene *scene, + Object *object, + GeometrySet &geometry_set) { - Curves *curves = curves_input; - /* Modifier evaluation modes. */ const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER); const int required_mode = use_render ? eModifierMode_Render : eModifierMode_Realtime; @@ -308,27 +307,10 @@ static Curves *curves_evaluate_modifiers(struct Depsgraph *depsgraph, continue; } - if ((mti->type == eModifierTypeType_OnlyDeform) && - (mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly)) { - /* Ensure we are not modifying the input. */ - if (curves == curves_input) { - curves = BKE_curves_copy_for_eval(curves, true); - } - - /* Created deformed coordinates array on demand. */ - blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap( - curves->geometry); - MutableSpan<float3> positions = geometry.positions_for_write(); - - mti->deformVerts(md, - &mectx, - nullptr, - reinterpret_cast<float(*)[3]>(positions.data()), - curves->geometry.point_size); + if (mti->modifyGeometrySet != nullptr) { + mti->modifyGeometrySet(md, &mectx, &geometry_set); } } - - return curves; } void BKE_curves_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Object *object) @@ -338,11 +320,20 @@ void BKE_curves_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Ob /* Evaluate modifiers. */ Curves *curves = static_cast<Curves *>(object->data); - Curves *curves_eval = curves_evaluate_modifiers(depsgraph, scene, object, curves); + GeometrySet geometry_set = GeometrySet::create_with_curves(curves, + GeometryOwnershipType::ReadOnly); + curves_evaluate_modifiers(depsgraph, scene, object, geometry_set); /* Assign evaluated object. */ - const bool is_owned = (curves != curves_eval); - BKE_object_eval_assign_data(object, &curves_eval->id, is_owned); + Curves *curves_eval = const_cast<Curves *>(geometry_set.get_curves_for_read()); + if (curves_eval == nullptr) { + curves_eval = blender::bke::curves_new_nomain(0, 0); + BKE_object_eval_assign_data(object, &curves_eval->id, true); + } + else { + BKE_object_eval_assign_data(object, &curves_eval->id, false); + } + object->runtime.geometry_set_eval = new GeometrySet(std::move(geometry_set)); } /* Draw Cache */ |