diff options
Diffstat (limited to 'source/blender/blenkernel/intern/curves.cc')
-rw-r--r-- | source/blender/blenkernel/intern/curves.cc | 123 |
1 files changed, 86 insertions, 37 deletions
diff --git a/source/blender/blenkernel/intern/curves.cc b/source/blender/blenkernel/intern/curves.cc index 7ad83263b73..c6e7bb72f53 100644 --- a/source/blender/blenkernel/intern/curves.cc +++ b/source/blender/blenkernel/intern/curves.cc @@ -53,8 +53,6 @@ using blender::Vector; static const char *ATTR_POSITION = "position"; -static void update_custom_data_pointers(Curves &curves); - static void curves_init_data(ID *id) { Curves *curves = (Curves *)id; @@ -97,8 +95,6 @@ static void curves_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, dst.runtime->type_counts = src.runtime->type_counts; - dst.update_customdata_pointers(); - curves_dst->batch_cache = nullptr; } @@ -170,7 +166,6 @@ static void curves_blend_read_data(BlendDataReader *reader, ID *id) /* Geometry */ CustomData_blend_read(reader, &curves->geometry.point_data, curves->geometry.point_num); CustomData_blend_read(reader, &curves->geometry.curve_data, curves->geometry.curve_num); - update_custom_data_pointers(*curves); BLO_read_int32_array(reader, curves->geometry.curve_num + 1, &curves->geometry.curve_offsets); @@ -204,40 +199,35 @@ static void curves_blend_read_expand(BlendExpander *expander, ID *id) } IDTypeInfo IDType_ID_CV = { - /*id_code */ ID_CV, - /*id_filter */ FILTER_ID_CV, - /*main_listbase_index */ INDEX_ID_CV, - /*struct_size */ sizeof(Curves), - /*name */ "Curves", - /*name_plural */ "curves", - /*translation_context */ BLT_I18NCONTEXT_ID_CURVES, - /*flags */ IDTYPE_FLAGS_APPEND_IS_REUSABLE, - /*asset_type_info */ nullptr, - - /*init_data */ curves_init_data, - /*copy_data */ curves_copy_data, - /*free_data */ curves_free_data, - /*make_local */ nullptr, - /*foreach_id */ curves_foreach_id, - /*foreach_cache */ nullptr, - /*foreach_path */ nullptr, - /*owner_get */ nullptr, - - /*blend_write */ curves_blend_write, - /*blend_read_data */ curves_blend_read_data, - /*blend_read_lib */ curves_blend_read_lib, - /*blend_read_expand */ curves_blend_read_expand, - - /*blend_read_undo_preserve */ nullptr, - - /*lib_override_apply_post */ nullptr, + /* id_code */ ID_CV, + /* id_filter */ FILTER_ID_CV, + /* main_listbase_index */ INDEX_ID_CV, + /* struct_size */ sizeof(Curves), + /* name*/ "Curves", + /* name_plural */ "hair_curves", + /* translation_context */ BLT_I18NCONTEXT_ID_CURVES, + /* flags */ IDTYPE_FLAGS_APPEND_IS_REUSABLE, + /* asset_type_info */ nullptr, + + /* init_data */ curves_init_data, + /* copy_data */ curves_copy_data, + /* free_data */ curves_free_data, + /* make_local */ nullptr, + /* foreach_id */ curves_foreach_id, + /* foreach_cache */ nullptr, + /* foreach_path */ nullptr, + /* owner_get */ nullptr, + + /* blend_write */ curves_blend_write, + /* blend_read_data */ curves_blend_read_data, + /* blend_read_lib */ curves_blend_read_lib, + /* blend_read_expand */ curves_blend_read_expand, + + /* blend_read_undo_preserve */ nullptr, + + /* lib_override_apply_post */ nullptr, }; -static void update_custom_data_pointers(Curves &curves) -{ - blender::bke::CurvesGeometry::wrap(curves.geometry).update_customdata_pointers(); -} - void *BKE_curves_add(Main *bmain, const char *name) { Curves *curves = static_cast<Curves *>(BKE_id_new(bmain, ID_CV, name)); @@ -301,6 +291,8 @@ static void curves_evaluate_modifiers(struct Depsgraph *depsgraph, ModifierApplyFlag apply_flag = use_render ? MOD_APPLY_RENDER : MOD_APPLY_USECACHE; const ModifierEvalContext mectx = {depsgraph, object, apply_flag}; + BKE_modifiers_clear_errors(object); + /* Get effective list of modifiers to execute. Some effects like shape keys * are added as virtual modifiers before the user created modifiers. */ VirtualModifierData virtualModifierData; @@ -329,6 +321,14 @@ void BKE_curves_data_update(struct Depsgraph *depsgraph, struct Scene *scene, Ob Curves *curves = static_cast<Curves *>(object->data); GeometrySet geometry_set = GeometrySet::create_with_curves(curves, GeometryOwnershipType::ReadOnly); + if (object->mode == OB_MODE_SCULPT_CURVES) { + /* Try to propagate deformation data through modifier evaluation, so that sculpt mode can work + * on evaluated curves. */ + GeometryComponentEditData &edit_component = + geometry_set.get_component_for_write<GeometryComponentEditData>(); + edit_component.curves_edit_hints_ = std::make_unique<blender::bke::CurvesEditHints>( + *static_cast<const Curves *>(DEG_get_original_object(object)->data)); + } curves_evaluate_modifiers(depsgraph, scene, object, geometry_set); /* Assign evaluated object. */ @@ -366,6 +366,8 @@ namespace blender::bke { Curves *curves_new_nomain(const int points_num, const int curves_num) { + BLI_assert(points_num >= 0); + BLI_assert(curves_num >= 0); Curves *curves_id = static_cast<Curves *>(BKE_id_new_nomain(ID_CV, nullptr)); CurvesGeometry &curves = CurvesGeometry::wrap(curves_id->geometry); curves.resize(points_num, curves_num); @@ -388,4 +390,51 @@ Curves *curves_new_nomain(CurvesGeometry curves) return curves_id; } +void curves_copy_parameters(const Curves &src, Curves &dst) +{ + dst.flag = src.flag; + dst.attributes_active_index = src.attributes_active_index; + MEM_SAFE_FREE(dst.mat); + dst.mat = static_cast<Material **>(MEM_malloc_arrayN(src.totcol, sizeof(Material *), __func__)); + dst.totcol = src.totcol; + MutableSpan(dst.mat, dst.totcol).copy_from(Span(src.mat, src.totcol)); + dst.symmetry = src.symmetry; + dst.selection_domain = src.selection_domain; + dst.surface = src.surface; + MEM_SAFE_FREE(dst.surface_uv_map); + if (src.surface_uv_map != nullptr) { + dst.surface_uv_map = BLI_strdup(src.surface_uv_map); + } +} + +CurvesSurfaceTransforms::CurvesSurfaceTransforms(const Object &curves_ob, const Object *surface_ob) +{ + this->curves_to_world = curves_ob.obmat; + this->world_to_curves = this->curves_to_world.inverted(); + + if (surface_ob != nullptr) { + this->surface_to_world = surface_ob->obmat; + this->world_to_surface = this->surface_to_world.inverted(); + this->surface_to_curves = this->world_to_curves * this->surface_to_world; + this->curves_to_surface = this->world_to_surface * this->curves_to_world; + this->surface_to_curves_normal = this->surface_to_curves.inverted().transposed(); + } +} + +bool CurvesEditHints::is_valid() const +{ + const int point_num = this->curves_id_orig.geometry.point_num; + if (this->positions.has_value()) { + if (this->positions->size() != point_num) { + return false; + } + } + if (this->deform_mats.has_value()) { + if (this->deform_mats->size() != point_num) { + return false; + } + } + return true; +} + } // namespace blender::bke |