From 2397ccc583afbd908e54237f29c80bbc99b43740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 4 Feb 2021 14:17:50 +0100 Subject: Animation: Add PreviewImage to bAction struct Make it possible to attach a preview image to an Action. In the #asset_browser_pose_libraries project, poses will be stored as individual Action datablocks. Having a thumbnail for each pose is of course essential. Reviewed By: mont29 Differential Revision: https://developer.blender.org/D10306 --- source/blender/blenkernel/intern/action.c | 20 ++++++++++++++++---- source/blender/blenkernel/intern/icons.cc | 1 + source/blender/makesdna/DNA_action_types.h | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index db8fe75b6d1..94680dc5c0c 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -54,6 +54,7 @@ #include "BKE_constraint.h" #include "BKE_deform.h" #include "BKE_fcurve.h" +#include "BKE_icons.h" #include "BKE_idprop.h" #include "BKE_idtype.h" #include "BKE_lib_id.h" @@ -101,10 +102,7 @@ static CLG_LogRef LOG = {"bke.action"}; * * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more). */ -static void action_copy_data(Main *UNUSED(bmain), - ID *id_dst, - const ID *id_src, - const int UNUSED(flag)) +static void action_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag) { bAction *action_dst = (bAction *)id_dst; const bAction *action_src = (const bAction *)id_src; @@ -145,6 +143,13 @@ static void action_copy_data(Main *UNUSED(bmain), } } } + + if (flag & LIB_ID_COPY_NO_PREVIEW) { + action_dst->preview = NULL; + } + else { + BKE_previewimg_id_copy(&action_dst->id, &action_src->id); + } } /** Free (or release) any data used by this action (does not free the action itself). */ @@ -161,6 +166,8 @@ static void action_free_data(struct ID *id) /* Free pose-references (aka local markers). */ BLI_freelistN(&action->markers); + + BKE_previewimg_free(&action->preview); } static void action_foreach_id(ID *id, LibraryForeachIDData *data) @@ -192,6 +199,8 @@ static void action_blend_write(BlendWriter *writer, ID *id, const void *id_addre LISTBASE_FOREACH (TimeMarker *, marker, &act->markers) { BLO_write_struct(writer, TimeMarker, marker); } + + BKE_previewimg_blend_write(writer, act->preview); } } @@ -218,6 +227,9 @@ static void action_blend_read_data(BlendDataReader *reader, ID *id) BLO_read_data_address(reader, &agrp->channels.first); BLO_read_data_address(reader, &agrp->channels.last); } + + BLO_read_data_address(reader, &act->preview); + BKE_previewimg_blend_read(reader, act->preview); } static void blend_read_lib_constraint_channels(BlendLibReader *reader, ID *id, ListBase *chanbase) diff --git a/source/blender/blenkernel/intern/icons.cc b/source/blender/blenkernel/intern/icons.cc index cba1726a1b9..afb009b66cd 100644 --- a/source/blender/blenkernel/intern/icons.cc +++ b/source/blender/blenkernel/intern/icons.cc @@ -374,6 +374,7 @@ PreviewImage **BKE_previewimg_id_get_p(const ID *id) ID_PRV_CASE(ID_GR, Collection); ID_PRV_CASE(ID_SCE, Scene); ID_PRV_CASE(ID_SCR, bScreen); + ID_PRV_CASE(ID_AC, bAction); #undef ID_PRV_CASE default: break; diff --git a/source/blender/makesdna/DNA_action_types.h b/source/blender/makesdna/DNA_action_types.h index 790a7a36288..96245e3b067 100644 --- a/source/blender/makesdna/DNA_action_types.h +++ b/source/blender/makesdna/DNA_action_types.h @@ -676,6 +676,8 @@ typedef struct bAction { */ int idroot; char _pad[4]; + + PreviewImage *preview; } bAction; /* Flags for the action */ -- cgit v1.2.3