diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-16 08:27:37 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-16 08:35:17 +0300 |
commit | 2f94b170e4e2f62c069eb2ece1f39bace89338fa (patch) | |
tree | c8870cf18fd8ed3659fd32521e66f5f61ee947be /source/blender/blenkernel | |
parent | 5498e7f193e2399b8693ef17803f864103307b4b (diff) |
Cleanup: move motion paths into editors/animation
Having this in blenkernel caused bad level calls to bf_editors_anim,
causing tests that use 'blenkernel' to require almost all libraries.
(complicating gtest linking & causing large binaries).
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_anim.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/anim.c | 292 |
3 files changed, 0 insertions, 302 deletions
diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h index 7670d5a04a0..d5bd729cc4e 100644 --- a/source/blender/blenkernel/BKE_anim.h +++ b/source/blender/blenkernel/BKE_anim.h @@ -46,14 +46,6 @@ void animviz_free_motionpath(struct bMotionPath *mpath); struct bMotionPath *animviz_verify_motionpaths(struct ReportList *reports, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan); -void animviz_get_object_motionpaths(struct Object *ob, ListBase *targets); -void animviz_calc_motionpaths(struct Depsgraph *depsgraph, - struct Main *bmain, - struct Scene *scene, - ListBase *targets, - bool restore, - bool current_frame_only); - /* ---------------------------------------------------- */ /* Curve Paths */ diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 696d252c81d..33c0d435c69 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -355,8 +355,6 @@ set(SRC ) set(LIB - bf_editor_animation # FIXME, bad level (compare_ak_cfraPtr) - bf_blenfont bf_blenlib bf_blenloader diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index a4ebfec657c..25a657c4745 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -57,11 +57,6 @@ static CLG_LogRef LOG = {"bke.anim"}; -// XXX bad level call... -extern short compare_ak_cfraPtr(void *node, void *data); -extern void agroup_to_keylist(struct AnimData *adt, struct bActionGroup *agrp, struct DLRBT_Tree *keys, int saction_flag); -extern void action_to_keylist(struct AnimData *adt, struct bAction *act, struct DLRBT_Tree *keys, int saction_flag); - /* --------------------- */ /* forward declarations */ @@ -244,293 +239,6 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, Scene *scene, Objec return mpath; } -/* ------------------- */ - -/* Motion path needing to be baked (mpt) */ -typedef struct MPathTarget { - struct MPathTarget *next, *prev; - - bMotionPath *mpath; /* motion path in question */ - - DLRBT_Tree keys; /* temp, to know where the keyframes are */ - - /* Original (Source Objects) */ - Object *ob; /* source object */ - bPoseChannel *pchan; /* source posechannel (if applicable) */ - - /* "Evaluated" Copies (these come from the background COW copie - * that provide all the coordinates we want to save off) - */ - Object *ob_eval; /* evaluated object */ -} MPathTarget; - -/* ........ */ - -/* get list of motion paths to be baked for the given object - * - assumes the given list is ready to be used - */ -/* TODO: it would be nice in future to be able to update objects dependent on these bones too? */ -void animviz_get_object_motionpaths(Object *ob, ListBase *targets) -{ - MPathTarget *mpt; - - /* object itself first */ - if ((ob->avs.recalc & ANIMVIZ_RECALC_PATHS) && (ob->mpath)) { - /* new target for object */ - mpt = MEM_callocN(sizeof(MPathTarget), "MPathTarget Ob"); - BLI_addtail(targets, mpt); - - mpt->mpath = ob->mpath; - mpt->ob = ob; - } - - /* bones */ - if ((ob->pose) && (ob->pose->avs.recalc & ANIMVIZ_RECALC_PATHS)) { - bArmature *arm = ob->data; - bPoseChannel *pchan; - - for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - if ((pchan->bone) && (arm->layer & pchan->bone->layer) && (pchan->mpath)) { - /* new target for bone */ - mpt = MEM_callocN(sizeof(MPathTarget), "MPathTarget PoseBone"); - BLI_addtail(targets, mpt); - - mpt->mpath = pchan->mpath; - mpt->ob = ob; - mpt->pchan = pchan; - } - } - } -} - -/* ........ */ - -/* update scene for current frame */ -static void motionpaths_calc_update_scene(Main *bmain, - struct Depsgraph *depsgraph) -{ - /* Do all updates - * - if this is too slow, resort to using a more efficient way - * that doesn't force complete update, but for now, this is the - * most accurate way! - * - * TODO(segey): Bring back partial updates, which became impossible - * with the new depsgraph due to unsorted nature of bases. - * - * TODO(sergey): Use evaluation context dedicated to motion paths. - */ - BKE_scene_graph_update_for_newframe(depsgraph, bmain); -} - -/* ........ */ - -/* perform baking for the targets on the current frame */ -static void motionpaths_calc_bake_targets(ListBase *targets, int cframe) -{ - MPathTarget *mpt; - - /* for each target, check if it can be baked on the current frame */ - for (mpt = targets->first; mpt; mpt = mpt->next) { - bMotionPath *mpath = mpt->mpath; - - /* current frame must be within the range the cache works for - * - is inclusive of the first frame, but not the last otherwise we get buffer overruns - */ - if ((cframe < mpath->start_frame) || (cframe >= mpath->end_frame)) { - continue; - } - - /* get the relevant cache vert to write to */ - bMotionPathVert *mpv = mpath->points + (cframe - mpath->start_frame); - - Object *ob_eval = mpt->ob_eval; - - /* Lookup evaluated pose channel, here because the depsgraph - * evaluation can change them so they are not cached in mpt. */ - bPoseChannel *pchan_eval = NULL; - if (mpt->pchan) { - pchan_eval = BKE_pose_channel_find_name(ob_eval->pose, mpt->pchan->name); - } - - /* pose-channel or object path baking? */ - if (pchan_eval) { - /* heads or tails */ - if (mpath->flag & MOTIONPATH_FLAG_BHEAD) { - copy_v3_v3(mpv->co, pchan_eval->pose_head); - } - else { - copy_v3_v3(mpv->co, pchan_eval->pose_tail); - } - - /* result must be in worldspace */ - mul_m4_v3(ob_eval->obmat, mpv->co); - } - else { - /* worldspace object location */ - copy_v3_v3(mpv->co, ob_eval->obmat[3]); - } - - float mframe = (float)(cframe); - - /* Tag if it's a keyframe */ - if (BLI_dlrbTree_search_exact(&mpt->keys, compare_ak_cfraPtr, &mframe)) { - mpv->flag |= MOTIONPATH_VERT_KEY; - } - else { - mpv->flag &= ~MOTIONPATH_VERT_KEY; - } - - /* Incremental update on evaluated object if possible, for fast updating - * while dragging in transform. */ - bMotionPath *mpath_eval = NULL; - if (mpt->pchan) { - mpath_eval = (pchan_eval) ? pchan_eval->mpath : NULL; - } - else { - mpath_eval = ob_eval->mpath; - } - - if (mpath_eval && mpath_eval->length == mpath->length) { - bMotionPathVert *mpv_eval = mpath_eval->points + (cframe - mpath_eval->start_frame); - *mpv_eval = *mpv; - - GPU_VERTBUF_DISCARD_SAFE(mpath_eval->points_vbo); - GPU_BATCH_DISCARD_SAFE(mpath_eval->batch_line); - GPU_BATCH_DISCARD_SAFE(mpath_eval->batch_points); - } - } -} - -/* Perform baking of the given object's and/or its bones' transforms to motion paths - * - scene: current scene - * - ob: object whose flagged motionpaths should get calculated - * - recalc: whether we need to - */ -/* TODO: include reports pointer? */ -void animviz_calc_motionpaths(Depsgraph *depsgraph, - Main *bmain, - Scene *scene, - ListBase *targets, - bool restore, - bool current_frame_only) -{ - /* sanity check */ - if (ELEM(NULL, targets, targets->first)) - return; - - /* Compute frame range to bake within. - * TODO: this method could be improved... - * 1) max range for standard baking - * 2) minimum range for recalc baking (i.e. between keyframes, but how?) */ - int sfra = INT_MAX; - int efra = INT_MIN; - - for (MPathTarget *mpt = targets->first; mpt; mpt = mpt->next) { - /* try to increase area to do (only as much as needed) */ - sfra = MIN2(sfra, mpt->mpath->start_frame); - efra = MAX2(efra, mpt->mpath->end_frame); - } - - if (efra <= sfra) { - return; - } - - /* Limit frame range if we are updating just the current frame. */ - /* set frame values */ - int cfra = CFRA; - if (current_frame_only) { - if (cfra < sfra || cfra > efra) { - return; - } - sfra = efra = cfra; - } - - /* get copies of objects/bones to get the calculated results from - * (for copy-on-write evaluation), so that we actually get some results - */ - // TODO: Create a copy of background depsgraph that only contain these entities, and only evaluates them.. - for (MPathTarget *mpt = targets->first; mpt; mpt = mpt->next) { - mpt->ob_eval = DEG_get_evaluated_object(depsgraph, mpt->ob); - - AnimData *adt = BKE_animdata_from_id(&mpt->ob_eval->id); - - /* build list of all keyframes in active action for object or pchan */ - BLI_dlrbTree_init(&mpt->keys); - - if (adt) { - bAnimVizSettings *avs; - - /* get pointer to animviz settings for each target */ - if (mpt->pchan) - avs = &mpt->ob->pose->avs; - else - avs = &mpt->ob->avs; - - /* it is assumed that keyframes for bones are all grouped in a single group - * unless an option is set to always use the whole action - */ - if ((mpt->pchan) && (avs->path_viewflag & MOTIONPATH_VIEW_KFACT) == 0) { - bActionGroup *agrp = BKE_action_group_find_name(adt->action, mpt->pchan->name); - - if (agrp) { - agroup_to_keylist(adt, agrp, &mpt->keys, 0); - } - } - else { - action_to_keylist(adt, adt->action, &mpt->keys, 0); - } - } - } - - /* calculate path over requested range */ - CLOG_INFO(&LOG, 1, "Calculating MotionPaths between frames %d - %d (%d frames)", sfra, efra, efra - sfra + 1); - for (CFRA = sfra; CFRA <= efra; CFRA++) { - if (current_frame_only) { - /* For current frame, only update tagged. */ - BKE_scene_graph_update_tagged(depsgraph, bmain); - } - else { - /* Update relevant data for new frame. */ - motionpaths_calc_update_scene(bmain, depsgraph); - } - - /* perform baking for targets */ - motionpaths_calc_bake_targets(targets, CFRA); - } - - /* reset original environment */ - /* NOTE: We don't always need to reevaluate the main scene, as the depsgraph - * may be a temporary one that works on a subset of the data. We always have - * to resoture the current frame though. */ - CFRA = cfra; - if (!current_frame_only && restore) { - motionpaths_calc_update_scene(bmain, depsgraph); - } - - /* clear recalc flags from targets */ - for (MPathTarget *mpt = targets->first; mpt; mpt = mpt->next) { - bAnimVizSettings *avs; - bMotionPath *mpath = mpt->mpath; - - /* get pointer to animviz settings for each target */ - if (mpt->pchan) - avs = &mpt->ob->pose->avs; - else - avs = &mpt->ob->avs; - - /* clear the flag requesting recalculation of targets */ - avs->recalc &= ~ANIMVIZ_RECALC_PATHS; - - /* Clean temp data */ - BLI_dlrbTree_free(&mpt->keys); - - /* Free previous batches to force update. */ - GPU_VERTBUF_DISCARD_SAFE(mpath->points_vbo); - GPU_BATCH_DISCARD_SAFE(mpath->batch_line); - GPU_BATCH_DISCARD_SAFE(mpath->batch_points); - } -} - /* ******************************************************************** */ /* Curve Paths - for curve deforms and/or curve following */ |