diff options
author | Sergey Sharybin <sergey@blender.org> | 2020-08-03 18:17:57 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2020-08-04 12:40:09 +0300 |
commit | 52c2f296bcd160b97f3c6eff756eacad362597aa (patch) | |
tree | 115eb73835473188af91bad7e9e614360276f2c9 /source/blender/blenkernel | |
parent | 51af20b8561b39d41ecd91abbeae7348dc1d4cdf (diff) |
Pose channel: Add session UUID
Allows to identify pose channels more reliably than by the pointer.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_action.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/action.c | 49 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/armature.c | 2 |
3 files changed, 54 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h index b7904ce1879..c3cfd4b33ea 100644 --- a/source/blender/blenkernel/BKE_action.h +++ b/source/blender/blenkernel/BKE_action.h @@ -129,6 +129,8 @@ void BKE_pose_channel_free(struct bPoseChannel *pchan); void BKE_pose_channel_free_ex(struct bPoseChannel *pchan, bool do_id_user); void BKE_pose_channel_runtime_reset(struct bPoseChannel_Runtime *runtime); +void BKE_pose_channel_runtime_reset_on_copy(struct bPoseChannel_Runtime *runtime); + void BKE_pose_channel_runtime_free(struct bPoseChannel_Runtime *runtime); void BKE_pose_channel_free_bbone_cache(struct bPoseChannel_Runtime *runtime); @@ -153,12 +155,15 @@ void BKE_pose_copy_data_ex(struct bPose **dst, const bool copy_constraints); void BKE_pose_copy_data(struct bPose **dst, const struct bPose *src, const bool copy_constraints); void BKE_pose_channel_copy_data(struct bPoseChannel *pchan, const struct bPoseChannel *pchan_from); +void BKE_pose_channel_session_uuid_generate(struct bPoseChannel *pchan); struct bPoseChannel *BKE_pose_channel_find_name(const struct bPose *pose, const char *name); struct bPoseChannel *BKE_pose_channel_active(struct Object *ob); struct bPoseChannel *BKE_pose_channel_active_or_first_selected(struct Object *ob); struct bPoseChannel *BKE_pose_channel_verify(struct bPose *pose, const char *name); struct bPoseChannel *BKE_pose_channel_get_mirrored(const struct bPose *pose, const char *name); +void BKE_pose_check_uuids_unique_and_report(const struct bPose *pose); + #ifndef NDEBUG bool BKE_pose_channels_is_valid(const struct bPose *pose); #endif diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index fa7eee83a68..85ac2c693cb 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -37,6 +37,7 @@ #include "BLI_blenlib.h" #include "BLI_ghash.h" #include "BLI_math.h" +#include "BLI_session_uuid.h" #include "BLI_string_utils.h" #include "BLI_utildefines.h" @@ -482,6 +483,11 @@ void action_groups_clear_tempflags(bAction *act) /* *************** Pose channels *************** */ +void BKE_pose_channel_session_uuid_generate(bPoseChannel *pchan) +{ + pchan->runtime.session_uuid = BLI_session_uuid_generate(); +} + /** * Return a pointer to the pose channel of the given name * from this pose. @@ -524,6 +530,8 @@ bPoseChannel *BKE_pose_channel_verify(bPose *pose, const char *name) /* If not, create it and add it */ chan = MEM_callocN(sizeof(bPoseChannel), "verifyPoseChannel"); + BKE_pose_channel_session_uuid_generate(chan); + BLI_strncpy(chan->name, name, sizeof(chan->name)); chan->custom_scale = 1.0f; @@ -698,6 +706,10 @@ void BKE_pose_copy_data_ex(bPose **dst, id_us_plus((ID *)pchan->custom); } + if ((flag & LIB_ID_CREATE_NO_MAIN) == 0) { + BKE_pose_channel_session_uuid_generate(pchan); + } + /* warning, O(n2) here, if done without the hash, but these are rarely used features. */ if (pchan->custom_tx) { pchan->custom_tx = BKE_pose_channel_find_name(outPose, pchan->custom_tx->name); @@ -726,7 +738,7 @@ void BKE_pose_copy_data_ex(bPose **dst, pchan->draw_data = NULL; /* Drawing cache, no need to copy. */ /* Runtime data, no need to copy. */ - memset(&pchan->runtime, 0, sizeof(pchan->runtime)); + BKE_pose_channel_runtime_reset_on_copy(&pchan->runtime); } /* for now, duplicate Bone Groups too when doing this */ @@ -956,6 +968,14 @@ void BKE_pose_channel_runtime_reset(bPoseChannel_Runtime *runtime) memset(runtime, 0, sizeof(*runtime)); } +/* Reset all non-persistent fields. */ +void BKE_pose_channel_runtime_reset_on_copy(bPoseChannel_Runtime *runtime) +{ + const SessionUUID uuid = runtime->session_uuid; + memset(runtime, 0, sizeof(*runtime)); + runtime->session_uuid = uuid; +} + /** Deallocates runtime cache of a pose channel */ void BKE_pose_channel_runtime_free(bPoseChannel_Runtime *runtime) { @@ -1692,3 +1712,30 @@ void what_does_obaction(Object *ob, BKE_animsys_evaluate_animdata(&workob->id, &adt, anim_eval_context, ADT_RECALC_ANIM, false); } } + +void BKE_pose_check_uuids_unique_and_report(const bPose *pose) +{ + if (pose == NULL) { + return; + } + + struct GSet *used_uuids = BLI_gset_new( + BLI_session_uuid_ghash_hash, BLI_session_uuid_ghash_compare, "sequencer used uuids"); + + LISTBASE_FOREACH (bPoseChannel *, pchan, &pose->chanbase) { + const SessionUUID *session_uuid = &pchan->runtime.session_uuid; + if (!BLI_session_uuid_is_generated(session_uuid)) { + printf("Pose channel %s does not have UUID generated.\n", pchan->name); + continue; + } + + if (BLI_gset_lookup(used_uuids, session_uuid) != NULL) { + printf("Pose channel %s has duplicate UUID generated.\n", pchan->name); + continue; + } + + BLI_gset_insert(used_uuids, (void *)session_uuid); + } + + BLI_gset_free(used_uuids, NULL); +} diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 000761ca8e7..985be4ac99f 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -2205,7 +2205,7 @@ static void pose_proxy_sync(Object *ob, Object *from, int layer_protected) pchan->mpath = NULL; /* Reset runtime data, we don't want to share that with the proxy. */ - BKE_pose_channel_runtime_reset(&pchanw.runtime); + BKE_pose_channel_runtime_reset_on_copy(&pchanw.runtime); /* this is freed so copy a copy, else undo crashes */ if (pchanw.prop) { |