diff options
Diffstat (limited to 'source/blender/blenkernel/intern/mball.c')
-rw-r--r-- | source/blender/blenkernel/intern/mball.c | 96 |
1 files changed, 53 insertions, 43 deletions
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 15a3229aaa7..3154e4c8af9 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -46,10 +46,13 @@ #include "BLI_string_utils.h" #include "BLI_utildefines.h" +#include "BLT_translation.h" + #include "BKE_main.h" #include "BKE_animsys.h" #include "BKE_curve.h" +#include "BKE_idtype.h" #include "BKE_scene.h" #include "BKE_lib_id.h" #include "BKE_displist.h" @@ -59,65 +62,77 @@ #include "DEG_depsgraph.h" -/* Functions */ +static void metaball_init_data(ID *id) +{ + MetaBall *metaball = (MetaBall *)id; + + BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(metaball, id)); -/** Free (or release) any data used by this mball (does not free the mball itself). */ -void BKE_mball_free(MetaBall *mb) + MEMCPY_STRUCT_AFTER(metaball, DNA_struct_default_get(MetaBall), id); +} + +static void metaball_copy_data(Main *UNUSED(bmain), + ID *id_dst, + const ID *id_src, + const int UNUSED(flag)) { - BKE_animdata_free((ID *)mb, false); + MetaBall *metaball_dst = (MetaBall *)id_dst; + const MetaBall *metaball_src = (const MetaBall *)id_src; - BKE_mball_batch_cache_free(mb); + BLI_duplicatelist(&metaball_dst->elems, &metaball_src->elems); - MEM_SAFE_FREE(mb->mat); + metaball_dst->mat = MEM_dupallocN(metaball_src->mat); - BLI_freelistN(&mb->elems); - if (mb->disp.first) { - BKE_displist_free(&mb->disp); - } + metaball_dst->editelems = NULL; + metaball_dst->lastelem = NULL; + metaball_dst->batch_cache = NULL; } -void BKE_mball_init(MetaBall *mb) +static void metaball_free_data(ID *id) { - BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(mb, id)); + MetaBall *metaball = (MetaBall *)id; - MEMCPY_STRUCT_AFTER(mb, DNA_struct_default_get(MetaBall), id); + BKE_animdata_free((ID *)metaball, false); + + BKE_mball_batch_cache_free(metaball); + + MEM_SAFE_FREE(metaball->mat); + + BLI_freelistN(&metaball->elems); + if (metaball->disp.first) { + BKE_displist_free(&metaball->disp); + } } +IDTypeInfo IDType_ID_MB = { + .id_code = ID_MB, + .id_filter = FILTER_ID_MB, + .main_listbase_index = INDEX_ID_MB, + .struct_size = sizeof(MetaBall), + .name = "Metaball", + .name_plural = "metaballs", + .translation_context = BLT_I18NCONTEXT_ID_METABALL, + .flags = 0, + + .init_data = metaball_init_data, + .copy_data = metaball_copy_data, + .free_data = metaball_free_data, + .make_local = NULL, +}; + +/* Functions */ + MetaBall *BKE_mball_add(Main *bmain, const char *name) { MetaBall *mb; mb = BKE_libblock_alloc(bmain, ID_MB, name, 0); - BKE_mball_init(mb); + metaball_init_data(&mb->id); return mb; } -/** - * Only copy internal data of MetaBall ID from source - * to already allocated/initialized destination. - * You probably never want to use that directly, - * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. - * - * WARNING! This function will not handle ID user count! - * - * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more). - */ -void BKE_mball_copy_data(Main *UNUSED(bmain), - MetaBall *mb_dst, - const MetaBall *mb_src, - const int UNUSED(flag)) -{ - BLI_duplicatelist(&mb_dst->elems, &mb_src->elems); - - mb_dst->mat = MEM_dupallocN(mb_src->mat); - - mb_dst->editelems = NULL; - mb_dst->lastelem = NULL; - mb_dst->batch_cache = NULL; -} - MetaBall *BKE_mball_copy(Main *bmain, const MetaBall *mb) { MetaBall *mb_copy; @@ -125,11 +140,6 @@ MetaBall *BKE_mball_copy(Main *bmain, const MetaBall *mb) return mb_copy; } -void BKE_mball_make_local(Main *bmain, MetaBall *mb, const int flags) -{ - BKE_lib_id_make_local_generic(bmain, &mb->id, flags); -} - /* most simple meta-element adding function * don't do context manipulation here (rna uses) */ MetaElem *BKE_mball_element_add(MetaBall *mb, const int type) |