Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2009-06-23 17:25:31 +0400
committerJoshua Leung <aligorith@gmail.com>2009-06-23 17:25:31 +0400
commitb4acd77526f32faab0c3d86436eef56096985c3d (patch)
tree9b0212ceb39f1299b5e49508ed40bffb1bbf5318 /source/blender/blenkernel
parentaa267976b86f90423204e11a30eec4e0def0f296 (diff)
NLA SoC: Big Commit - Restored NLA-Mapping Corrections
In TweakMode, the keyframes of the Active Action are now shown (and can be edited) in NLA-mapped time, with appropriate corrections applied when editing. This works in the DopeSheet and Graph Editors :) To do this, got rid of the old wrappers/API-methods, replacing them with new-style ones. A few methods previously (in this branch) used only for evaluation are now used for this purpose too. As the same code is used for editing + evaluation, this should now be much better to work with. I've only done a few brief tests now, but I think I might've muddled the invert-flags on one or two cases which I'll need to check out tomorrow. So, beware that there may be some weird and critical bugs for the next few days here... Also, added proper license headers to new NLA files. TODO: - testing + bugfixing due to this commit - show range of keyframes in NLA Editor active-action line
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_action.h6
-rw-r--r--source/blender/blenkernel/BKE_nla.h2
-rw-r--r--source/blender/blenkernel/intern/action.c42
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c158
-rw-r--r--source/blender/blenkernel/intern/fcurve.c29
-rw-r--r--source/blender/blenkernel/intern/nla.c136
-rw-r--r--source/blender/blenkernel/nla_private.h78
7 files changed, 274 insertions, 177 deletions
diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h
index 1fb200b94a8..0c9bba5e413 100644
--- a/source/blender/blenkernel/BKE_action.h
+++ b/source/blender/blenkernel/BKE_action.h
@@ -148,12 +148,6 @@ void copy_pose_result(struct bPose *to, struct bPose *from);
/* clear all transforms */
void rest_pose(struct bPose *pose);
-/* map global time (frame nr) to strip converted time, doesn't clip */
-float get_action_frame(struct Object *ob, float cframe);
-/* map strip time to global time (frame nr) */
-float get_action_frame_inv(struct Object *ob, float cframe);
-
-
/* functions used by the game engine */
void game_copy_pose(struct bPose **dst, struct bPose *src);
void game_free_pose(struct bPose *pose);
diff --git a/source/blender/blenkernel/BKE_nla.h b/source/blender/blenkernel/BKE_nla.h
index 5200ca6d4d7..cc73ac02690 100644
--- a/source/blender/blenkernel/BKE_nla.h
+++ b/source/blender/blenkernel/BKE_nla.h
@@ -73,5 +73,7 @@ void BKE_nla_action_pushdown(struct AnimData *adt);
short BKE_nla_tweakmode_enter(struct AnimData *adt);
void BKE_nla_tweakmode_exit(struct AnimData *adt);
+float BKE_nla_tweakedit_remap(struct AnimData *adt, float cframe, short invert);
+
#endif
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index f88e249d38c..96896509f60 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -769,48 +769,6 @@ void framechange_poses_clear_unkeyed(void)
/* ************** time ****************** */
-static bActionStrip *get_active_strip(Object *ob)
-{
-#if 0 // XXX old animation system
- bActionStrip *strip;
-
- if(ob->action==NULL)
- return NULL;
-
- for (strip=ob->nlastrips.first; strip; strip=strip->next)
- if(strip->flag & ACTSTRIP_ACTIVE)
- break;
-
- if(strip && strip->act==ob->action)
- return strip;
-#endif // XXX old animation system
-
- return NULL;
-}
-
-/* if the conditions match, it converts current time to strip time */
-// TODO: change this adt
-float get_action_frame(Object *ob, float cframe)
-{
- bActionStrip *strip= get_active_strip(ob);
-
- //if(strip)
- // return get_actionstrip_frame(strip, cframe, 0);
- return cframe;
-}
-
-/* inverted, strip time to current time */
-// TODO: change this to adt
-float get_action_frame_inv(Object *ob, float cframe)
-{
- bActionStrip *strip= get_active_strip(ob);
-
- //if(strip)
- // return get_actionstrip_frame(strip, cframe, 1);
- return cframe;
-}
-
-
/* Check if the given action has any keyframes */
short action_has_motion(const bAction *act)
{
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index 7a6706b7c5a..877353a85e9 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -1,5 +1,30 @@
-/* Testing code for new animation system in 2.5
- * Copyright 2009, Joshua Leung
+/**
+ * $Id: anim_sys.c 21023 2009-06-20 04:02:49Z aligorith $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Joshua Leung (full recode)
+ *
+ * ***** END GPL LICENSE BLOCK *****
*/
#include <stdio.h>
@@ -14,6 +39,8 @@
#include "BLI_arithb.h"
#include "BLI_dynstr.h"
+#include "DNA_anim_types.h"
+
#include "BKE_animsys.h"
#include "BKE_action.h"
#include "BKE_fcurve.h"
@@ -25,7 +52,7 @@
#include "RNA_access.h"
#include "RNA_types.h"
-#include "DNA_anim_types.h"
+#include "nla_private.h"
/* ***************************************** */
/* AnimData API */
@@ -549,129 +576,6 @@ void animsys_evaluate_action (PointerRNA *ptr, bAction *act, AnimMapper *remap,
/* ***************************************** */
/* NLA System - Evaluation */
-/* used for list of strips to accumulate at current time */
-typedef struct NlaEvalStrip {
- struct NlaEvalStrip *next, *prev;
-
- NlaTrack *track; /* track that this strip belongs to */
- NlaStrip *strip; /* strip that's being used */
-
- short track_index; /* the index of the track within the list */
- short strip_mode; /* which end of the strip are we looking at */
-
- float strip_time; /* time at which which strip is being evaluated */
-} NlaEvalStrip;
-
-/* NlaEvalStrip->strip_mode */
-enum {
- /* standard evaluation */
- NES_TIME_BEFORE = -1,
- NES_TIME_WITHIN,
- NES_TIME_AFTER,
-
- /* transition-strip evaluations */
- NES_TIME_TRANSITION_START,
- NES_TIME_TRANSITION_END,
-} eNlaEvalStrip_StripMode;
-
-
-/* temp channel for accumulating data from NLA (avoids needing to clear all values first) */
-// TODO: maybe this will be used as the 'cache' stuff needed for editable values too?
-typedef struct NlaEvalChannel {
- struct NlaEvalChannel *next, *prev;
-
- PointerRNA ptr; /* pointer to struct containing property to use */
- PropertyRNA *prop; /* RNA-property type to use (should be in the struct given) */
- int index; /* array index (where applicable) */
-
- float value; /* value of this channel */
-} NlaEvalChannel;
-
-
-/* ---------------------- */
-
-/* non clipped mapping for strip-time <-> global time (for Action-Clips)
- * invert = convert action-strip time to global time
- */
-static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short invert)
-{
- float length, actlength, repeat, scale;
-
- /* get number of repeats */
- if (IS_EQ(strip->repeat, 0.0f)) strip->repeat = 1.0f;
- repeat = strip->repeat;
-
- /* scaling */
- if (IS_EQ(strip->scale, 0.0f)) strip->scale= 1.0f;
- scale = (float)fabs(strip->scale); /* scale must be positive - we've got a special flag for reversing */
-
- /* length of referenced action */
- actlength = strip->actend - strip->actstart;
- if (IS_EQ(actlength, 0.0f)) actlength = 1.0f;
-
- /* length of strip */
- length= actlength * scale * repeat;
- if (IS_EQ(length, 0.0f)) length= strip->end - strip->start;
-
- /* reversed = play strip backwards */
- if (strip->flag & NLASTRIP_FLAG_REVERSE) {
- /* invert = convert action-strip time to global time */
- if (invert)
- return length*(strip->actend - cframe)/(repeat*actlength) + strip->start;
- else
- return strip->actend - repeat*actlength*(cframe - strip->start)/length;
- }
- else {
- /* invert = convert action-strip time to global time */
- if (invert)
- return length*(cframe - strip->actstart)/(repeat*actlength) + strip->start;
- else
- return repeat*actlength*(cframe - strip->start)/length + strip->actstart;
- }
-}
-
-/* non clipped mapping for strip-time <-> global time (for Transitions)
- * invert = convert action-strip time to global time
- */
-static float nlastrip_get_frame_transition (NlaStrip *strip, float cframe, short invert)
-{
- float length;
-
- /* length of strip */
- length= strip->end - strip->start;
-
- /* reversed = play strip backwards */
- if (strip->flag & NLASTRIP_FLAG_REVERSE) {
- /* invert = convert within-strip-time to global time */
- if (invert)
- return strip->end - (length * cframe);
- else
- return (strip->end - cframe) / length;
- }
- else {
- /* invert = convert within-strip-time to global time */
- if (invert)
- return (length * cframe) + strip->start;
- else
- return (cframe - strip->start) / length;
- }
-}
-
-/* non clipped mapping for strip-time <-> global time
- * invert = convert action-strip time to global time
- */
-static float nlastrip_get_frame (NlaStrip *strip, float cframe, short invert)
-{
- switch (strip->type) {
- case NLASTRIP_TYPE_TRANSITION: /* transition */
- return nlastrip_get_frame_transition(strip, cframe, invert);
-
- case NLASTRIP_TYPE_CLIP: /* action-clip (default) */
- default:
- return nlastrip_get_frame_actionclip(strip, cframe, invert);
- }
-}
-
/* calculate influence of strip based for given frame based on blendin/out values */
static float nlastrip_get_influence (NlaStrip *strip, float cframe)
{
@@ -695,7 +599,7 @@ static float nlastrip_get_influence (NlaStrip *strip, float cframe)
}
/* evaluate the evaluation time and influence for the strip, storing the results in the strip */
-void nlastrip_evaluate_controls (NlaStrip *strip, float ctime)
+static void nlastrip_evaluate_controls (NlaStrip *strip, float ctime)
{
/* firstly, analytically generate values for influence and time (if applicable) */
if ((strip->flag & NLASTRIP_FLAG_USR_TIME) == 0)
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 856930e5a44..27ca6332cdc 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -1,5 +1,30 @@
-/* Testing code for new animation system in 2.5
- * Copyright 2009, Joshua Leung
+/**
+ * $Id: fcurve.c 21023 2009-06-20 04:02:49Z aligorith $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Joshua Leung (full recode)
+ *
+ * ***** END GPL LICENSE BLOCK *****
*/
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index 1ce6d9f98c7..a5b3b59d310 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -49,6 +49,9 @@
#include "BKE_object.h"
#include "BKE_utildefines.h"
+#include "RNA_access.h"
+#include "nla_private.h"
+
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -319,6 +322,135 @@ NlaStrip *add_nlastrip_to_stack (AnimData *adt, bAction *act)
}
/* *************************************************** */
+/* NLA Evaluation <-> Editing Stuff */
+
+/* Strip Mapping ------------------------------------- */
+
+/* non clipped mapping for strip-time <-> global time (for Action-Clips)
+ * invert = convert action-strip time to global time
+ */
+static float nlastrip_get_frame_actionclip (NlaStrip *strip, float cframe, short invert)
+{
+ float length, actlength, repeat, scale;
+
+ /* get number of repeats */
+ if (IS_EQ(strip->repeat, 0.0f)) strip->repeat = 1.0f;
+ repeat = strip->repeat;
+
+ /* scaling */
+ if (IS_EQ(strip->scale, 0.0f)) strip->scale= 1.0f;
+ scale = (float)fabs(strip->scale); /* scale must be positive - we've got a special flag for reversing */
+
+ /* length of referenced action */
+ actlength = strip->actend - strip->actstart;
+ if (IS_EQ(actlength, 0.0f)) actlength = 1.0f;
+
+ /* length of strip */
+ length= actlength * scale * repeat;
+ if (IS_EQ(length, 0.0f)) length= strip->end - strip->start;
+
+ /* reversed = play strip backwards */
+ if (strip->flag & NLASTRIP_FLAG_REVERSE) {
+ /* invert = convert action-strip time to global time */
+ if (invert)
+ return length*(strip->actend - cframe)/(repeat*actlength) + strip->start;
+ else
+ return strip->actend - repeat*actlength*(cframe - strip->start)/length;
+ }
+ else {
+ /* invert = convert action-strip time to global time */
+ if (invert)
+ return length*(cframe - strip->actstart)/(repeat*actlength) + strip->start;
+ else
+ return repeat*actlength*(cframe - strip->start)/length + strip->actstart;
+ }
+}
+
+/* non clipped mapping for strip-time <-> global time (for Transitions)
+ * invert = convert action-strip time to global time
+ */
+static float nlastrip_get_frame_transition (NlaStrip *strip, float cframe, short invert)
+{
+ float length;
+
+ /* length of strip */
+ length= strip->end - strip->start;
+
+ /* reversed = play strip backwards */
+ if (strip->flag & NLASTRIP_FLAG_REVERSE) {
+ /* invert = convert within-strip-time to global time */
+ if (invert)
+ return strip->end - (length * cframe);
+ else
+ return (strip->end - cframe) / length;
+ }
+ else {
+ /* invert = convert within-strip-time to global time */
+ if (invert)
+ return (length * cframe) + strip->start;
+ else
+ return (cframe - strip->start) / length;
+ }
+}
+
+/* non clipped mapping for strip-time <-> global time
+ * invert = convert action-strip time to global time
+ *
+ * only secure for 'internal' (i.e. within AnimSys evaluation) operations,
+ * but should not be directly relied on for stuff which interacts with editors
+ */
+float nlastrip_get_frame (NlaStrip *strip, float cframe, short invert)
+{
+ switch (strip->type) {
+ case NLASTRIP_TYPE_TRANSITION: /* transition */
+ return nlastrip_get_frame_transition(strip, cframe, invert);
+
+ case NLASTRIP_TYPE_CLIP: /* action-clip (default) */
+ default:
+ return nlastrip_get_frame_actionclip(strip, cframe, invert);
+ }
+}
+
+
+/* Non clipped mapping for strip-time <-> global time
+ * invert = convert strip-time to global time
+ *
+ * Public API method - perform this mapping using the given AnimData block
+ * and perform any necessary sanity checks on the value
+ */
+float BKE_nla_tweakedit_remap (AnimData *adt, float cframe, short invert)
+{
+ NlaStrip *strip;
+
+ /* sanity checks
+ * - obviously we've got to have some starting data
+ * - when not in tweakmode, the active Action does not have any scaling applied :)
+ */
+ if ((adt == NULL) || (adt->flag & ADT_NLA_EDIT_ON)==0)
+ return cframe;
+
+ /* if the active-strip info has been stored already, access this, otherwise look this up
+ * and store for (very probable) future usage
+ */
+ if (adt->actstrip == NULL) {
+ NlaTrack *nlt= BKE_nlatrack_find_active(adt);
+ adt->actstrip= BKE_nlastrip_find_active(nlt);
+ }
+ strip= adt->actstrip;
+
+ /* sanity checks
+ * - in rare cases, we may not be able to find this strip for some reason (internal error)
+ * - for now, if the user has defined a curve to control the time, this correction cannot be performed
+ * reliably...
+ */
+ if ((strip == NULL) || (strip->flag & NLASTRIP_FLAG_USR_TIME))
+ return cframe;
+
+ /* perform the correction now... */
+ return nlastrip_get_frame(strip, cframe, invert);
+}
+
+/* *************************************************** */
/* Basic Utilities */
/* NLA-Tracks ---------------------------------------- */
@@ -693,9 +825,11 @@ short BKE_nla_tweakmode_enter (AnimData *adt)
* - 'real' active action to temp storage (no need to change user-counts)
* - action of active strip set to be the 'active action', and have its usercount incremented
* - editing-flag for this AnimData block should also get turned on (for more efficient restoring)
+ * - take note of the active strip for mapping-correction of keyframes in the action being edited
*/
adt->tmpact= adt->action;
adt->action= activeStrip->act;
+ adt->actstrip= activeStrip;
id_us_plus(&activeStrip->act->id);
adt->flag |= ADT_NLA_EDIT_ON;
@@ -734,10 +868,12 @@ void BKE_nla_tweakmode_exit (AnimData *adt)
* - 'real' active action is restored from storage
* - storage pointer gets cleared (to avoid having bad notes hanging around)
* - editing-flag for this AnimData block should also get turned off
+ * - clear pointer to active strip
*/
if (adt->action) adt->action->id.us--;
adt->action= adt->tmpact;
adt->tmpact= NULL;
+ adt->actstrip= NULL;
adt->flag &= ~ADT_NLA_EDIT_ON;
}
diff --git a/source/blender/blenkernel/nla_private.h b/source/blender/blenkernel/nla_private.h
new file mode 100644
index 00000000000..af886fb7de8
--- /dev/null
+++ b/source/blender/blenkernel/nla_private.h
@@ -0,0 +1,78 @@
+/**
+ * $Id: BKE_nla.h 20999 2009-06-19 04:45:56Z aligorith $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Joshua Leung (full recode)
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef NLA_PRIVATE
+#define NLA_PRIVATE
+
+/* --------------- NLA Evaluation DataTypes ----------------------- */
+
+/* used for list of strips to accumulate at current time */
+typedef struct NlaEvalStrip {
+ struct NlaEvalStrip *next, *prev;
+
+ NlaTrack *track; /* track that this strip belongs to */
+ NlaStrip *strip; /* strip that's being used */
+
+ short track_index; /* the index of the track within the list */
+ short strip_mode; /* which end of the strip are we looking at */
+
+ float strip_time; /* time at which which strip is being evaluated */
+} NlaEvalStrip;
+
+/* NlaEvalStrip->strip_mode */
+enum {
+ /* standard evaluation */
+ NES_TIME_BEFORE = -1,
+ NES_TIME_WITHIN,
+ NES_TIME_AFTER,
+
+ /* transition-strip evaluations */
+ NES_TIME_TRANSITION_START,
+ NES_TIME_TRANSITION_END,
+} eNlaEvalStrip_StripMode;
+
+
+/* temp channel for accumulating data from NLA (avoids needing to clear all values first) */
+// TODO: maybe this will be used as the 'cache' stuff needed for editable values too?
+typedef struct NlaEvalChannel {
+ struct NlaEvalChannel *next, *prev;
+
+ PointerRNA ptr; /* pointer to struct containing property to use */
+ PropertyRNA *prop; /* RNA-property type to use (should be in the struct given) */
+ int index; /* array index (where applicable) */
+
+ float value; /* value of this channel */
+} NlaEvalChannel;
+
+/* --------------- NLA Functions (not to be used as a proper API) ----------------------- */
+
+/* convert from strip time <-> global time */
+float nlastrip_get_frame(NlaStrip *strip, float cframe, short invert);
+
+#endif // NLA_PRIVATE