2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-01-07 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2009-05-22 01:16:26 +00:00
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
|
2002-10-12 11:37:38 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
2009-05-22 01:16:26 +00:00
|
|
|
* Contributor(s): Joshua Leung (full recode)
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2009-05-22 01:16:26 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-02-18 15:57:46 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2006-02-18 15:57:46 +00:00
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_action_types.h"
|
2006-02-18 15:57:46 +00:00
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
#include "BKE_animsys.h"
|
2006-02-18 15:57:46 +00:00
|
|
|
#include "BKE_action.h"
|
2009-05-22 01:16:26 +00:00
|
|
|
#include "BKE_fcurve.h"
|
|
|
|
#include "BKE_nla.h"
|
2006-02-18 15:57:46 +00:00
|
|
|
#include "BKE_blender.h"
|
|
|
|
#include "BKE_library.h"
|
2009-05-22 01:16:26 +00:00
|
|
|
#include "BKE_object.h"
|
|
|
|
#include "BKE_utildefines.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-02-18 15:57:46 +00:00
|
|
|
|
2002-11-25 12:02:15 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
Big commit with work on Groups & Libraries:
-> Any Group Duplicate now can get local timing and local NLA override. This
enables to control the entire animation system of the Group.
Two methods for this have been implemented.
1) The quick way: just give the duplicator a "Startframe" offset.
2) Advanced: in the NLA Editor you can add ActionStrips to the duplicator
to override NLA/action of any Grouped Object.
For "Group NLA" to work, an ActionStrip needs to know which Object in a
group it controls. On adding a strip, the code checks if an Action was
already used by an Object in the Group, and assigns it automatic to that
Object.
You can also set this in the Nkey "Properties" panel for the strip.
Change in NLA: the SHIFT+A "Add strip" command now always adds strips to
the active Object. (It used to check where mouse was). This allows to add
NLA strips to Objects that didn't have actions/nla yet.
Important note: In Blender, duplicates are fully procedural and generated
on the fly for each redraw. This means that redraw speed equals to stepping
through frames, when using animated Duplicated Groups.
-> Recoded entire duplicator system
The old method was antique and clumsy, using globals and full temporal
copies of Object. The new system is nicer in control, faster, and since it
doesn't use temporal object copies anymore, it works better with Derived
Mesh and DisplayList and rendering.
By centralizing the code for duplicating, more options can be easier added.
Features to note:
- Duplicates now draw selected/unselected based on its Duplicator setting.
- Same goes for the drawtype (wire, solid, selection outline, etc)
- Duplicated Groups can be normally selected too
Bonus goodie: SHIFT+A (Toolbox) now has entry "Add group" too, with a
listing of all groups, allowing to add Group instances immediate.
-> Library System
- SHIFT+F4 data browse now shows the entire path for linked data
- Outliner draws Library Icons to denote linked data
- Outliner operation added: "Make Local" for library data.
- Outliner now also draws Groups in regular view, allowing to unlink too.
-> Fixes
- depsgraph missed signal update for bone-parented Objects
- on reading file, the entire database was tagged to "recalc" fully,
causing unnecessary slowdown on reading.
Might have missed stuff... :)
2005-12-11 13:23:30 +00:00
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* *************************************************** */
|
|
|
|
/* Data Management */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* Freeing ------------------------------------------- */
|
|
|
|
|
|
|
|
/* Remove the given NLA strip from the NLA track it occupies, free the strip's data,
|
|
|
|
* and the strip itself.
|
|
|
|
*/
|
|
|
|
// TODO: with things like transitions, should these get freed too? Maybe better as a UI tool
|
|
|
|
void free_nlastrip (ListBase *strips, NlaStrip *strip)
|
|
|
|
{
|
|
|
|
FModifier *fcm, *fmn;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if (strip == NULL)
|
2002-10-12 11:37:38 +00:00
|
|
|
return;
|
2009-05-22 01:16:26 +00:00
|
|
|
|
|
|
|
/* remove reference to action */
|
|
|
|
if (strip->act)
|
|
|
|
strip->act->id.us--;
|
|
|
|
|
|
|
|
/* free remapping info */
|
|
|
|
//if (strip->remap)
|
|
|
|
// BKE_animremap_free();
|
|
|
|
|
|
|
|
/* free own F-Curves */
|
|
|
|
free_fcurves(&strip->fcurves);
|
|
|
|
|
|
|
|
/* free F-Modifiers */
|
|
|
|
for (fcm= strip->modifiers.first; fcm; fcm= fmn) {
|
|
|
|
fmn= fcm->next;
|
|
|
|
|
|
|
|
BLI_remlink(&strip->modifiers, fcm);
|
|
|
|
fcurve_remove_modifier(NULL, fcm);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-05-22 01:16:26 +00:00
|
|
|
|
|
|
|
/* free the strip itself */
|
|
|
|
if (strips)
|
|
|
|
BLI_freelinkN(strips, strip);
|
|
|
|
else
|
|
|
|
MEM_freeN(strip);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* Remove the given NLA track from the set of NLA tracks, free the track's data,
|
|
|
|
* and the track itself.
|
|
|
|
*/
|
|
|
|
void free_nlatrack (ListBase *tracks, NlaTrack *nlt)
|
|
|
|
{
|
|
|
|
NlaStrip *strip, *stripn;
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* sanity checks */
|
|
|
|
if (nlt == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* free strips */
|
|
|
|
for (strip= nlt->strips.first; strip; strip= stripn) {
|
|
|
|
stripn= strip->next;
|
|
|
|
free_nlastrip(&nlt->strips, strip);
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* free NLA track itself now */
|
|
|
|
if (tracks)
|
|
|
|
BLI_freelinkN(tracks, nlt);
|
|
|
|
else
|
|
|
|
MEM_freeN(nlt);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* Free the elements of type NLA Tracks provided in the given list, but do not free
|
|
|
|
* the list itself since that is not free-standing
|
|
|
|
*/
|
|
|
|
void free_nladata (ListBase *tracks)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-05-22 01:16:26 +00:00
|
|
|
NlaTrack *nlt, *nltn;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if ELEM(NULL, tracks, tracks->first)
|
2002-10-12 11:37:38 +00:00
|
|
|
return;
|
2009-05-22 01:16:26 +00:00
|
|
|
|
|
|
|
/* free tracks one by one */
|
|
|
|
for (nlt= tracks->first; nlt; nlt= nltn) {
|
|
|
|
nltn= nlt->next;
|
|
|
|
free_nlatrack(tracks, nlt);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-05-22 01:16:26 +00:00
|
|
|
|
|
|
|
/* clear the list's pointers to be safe */
|
|
|
|
tracks->first= tracks->last= NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* Copying ------------------------------------------- */
|
|
|
|
|
2009-05-23 09:36:18 +00:00
|
|
|
/* Copy NLA strip */
|
|
|
|
NlaStrip *copy_nlastrip (NlaStrip *strip)
|
|
|
|
{
|
|
|
|
NlaStrip *strip_d;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (strip == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* make a copy */
|
|
|
|
strip_d= MEM_dupallocN(strip);
|
|
|
|
strip_d->next= strip_d->prev= NULL;
|
|
|
|
|
|
|
|
/* increase user-count of action */
|
|
|
|
if (strip_d->act)
|
|
|
|
strip_d->act->id.us++;
|
|
|
|
|
|
|
|
/* copy F-Curves and modifiers */
|
|
|
|
copy_fcurves(&strip_d->fcurves, &strip->fcurves);
|
|
|
|
fcurve_copy_modifiers(&strip_d->modifiers, &strip->modifiers);
|
|
|
|
|
|
|
|
/* return the strip */
|
|
|
|
return strip_d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy NLA Track */
|
|
|
|
NlaTrack *copy_nlatrack (NlaTrack *nlt)
|
|
|
|
{
|
|
|
|
NlaStrip *strip, *strip_d;
|
|
|
|
NlaTrack *nlt_d;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (nlt == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* make a copy */
|
|
|
|
nlt_d= MEM_dupallocN(nlt);
|
|
|
|
nlt_d->next= nlt_d->prev= NULL;
|
|
|
|
|
|
|
|
/* make a copy of all the strips, one at a time */
|
|
|
|
nlt_d->strips.first= nlt_d->strips.last= NULL;
|
|
|
|
|
|
|
|
for (strip= nlt->strips.first; strip; strip= strip->next) {
|
|
|
|
strip_d= copy_nlastrip(strip);
|
|
|
|
BLI_addtail(&nlt_d->strips, strip_d);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return the copy */
|
|
|
|
return nlt_d;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy all NLA data */
|
|
|
|
void copy_nladata (ListBase *dst, ListBase *src)
|
|
|
|
{
|
|
|
|
NlaTrack *nlt, *nlt_d;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if ELEM(NULL, dst, src)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* copy each NLA-track, one at a time */
|
|
|
|
for (nlt= src->first; nlt; nlt= nlt->next) {
|
|
|
|
/* make a copy, and add the copy to the destination list */
|
|
|
|
nlt_d= copy_nlatrack(nlt);
|
|
|
|
BLI_addtail(dst, nlt_d);
|
|
|
|
}
|
|
|
|
}
|
2009-05-22 01:16:26 +00:00
|
|
|
|
|
|
|
/* Adding ------------------------------------------- */
|
|
|
|
|
|
|
|
/* Add a NLA Strip referencing the given Action, to the given NLA Track */
|
|
|
|
// TODO: any extra parameters to control how this is done?
|
|
|
|
NlaStrip *add_nlastrip (NlaTrack *nlt, bAction *act)
|
2006-02-08 16:58:12 +00:00
|
|
|
{
|
2009-05-22 01:16:26 +00:00
|
|
|
NlaStrip *strip;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if ELEM(NULL, nlt, act)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* allocate new strip */
|
|
|
|
strip= MEM_callocN(sizeof(NlaStrip), "NlaStrip");
|
|
|
|
BLI_addtail(&nlt->strips, strip);
|
|
|
|
|
|
|
|
/* generic settings
|
|
|
|
* - selected flag to highlight this to the user
|
|
|
|
* - auto-blends to ensure that blend in/out values are automatically
|
|
|
|
* determined by overlaps of strips
|
|
|
|
* - (XXX) synchronisation of strip-length in accordance with changes to action-length
|
|
|
|
* is not done though, since this should only really happens in editmode for strips now
|
|
|
|
* though this decision is still subject to further review...
|
|
|
|
*/
|
|
|
|
strip->flag = NLASTRIP_FLAG_SELECT|NLASTRIP_FLAG_AUTO_BLENDS;
|
|
|
|
|
|
|
|
/* assign the action reference */
|
|
|
|
strip->act= act;
|
|
|
|
id_us_plus(&act->id);
|
|
|
|
|
|
|
|
/* determine initial range
|
|
|
|
* - strip length cannot be 0... ever...
|
|
|
|
*/
|
|
|
|
calc_action_range(strip->act, &strip->actstart, &strip->actend, 1);
|
|
|
|
|
|
|
|
strip->start = strip->actstart;
|
|
|
|
strip->end = (IS_EQ(strip->actstart, strip->actend)) ? (strip->actstart + 1.0f): (strip->actend);
|
|
|
|
|
|
|
|
/* strip should be referenced as-is */
|
|
|
|
strip->scale= 1.0f;
|
|
|
|
strip->repeat = 1.0f;
|
|
|
|
|
|
|
|
/* return the new strip */
|
|
|
|
return strip;
|
2006-02-08 16:58:12 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* Add a NLA Track to the given AnimData */
|
|
|
|
NlaTrack *add_nlatrack (AnimData *adt)
|
2006-02-08 16:58:12 +00:00
|
|
|
{
|
2009-05-22 01:16:26 +00:00
|
|
|
NlaTrack *nlt;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if (adt == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* allocate new track */
|
|
|
|
nlt= MEM_callocN(sizeof(NlaTrack), "NlaTrack");
|
|
|
|
|
|
|
|
/* set settings requiring the track to not be part of the stack yet */
|
|
|
|
nlt->flag = NLATRACK_SELECTED;
|
|
|
|
nlt->index= BLI_countlist(&adt->nla_tracks);
|
|
|
|
|
|
|
|
/* add track to stack, and make it the active one */
|
|
|
|
BLI_addtail(&adt->nla_tracks, nlt);
|
|
|
|
BKE_nlatrack_set_active(&adt->nla_tracks, nlt);
|
|
|
|
|
|
|
|
/* must have unique name, but we need to seed this */
|
|
|
|
sprintf(nlt->name, "NlaTrack");
|
|
|
|
BLI_uniquename(&adt->nla_tracks, nlt, "NlaTrack", '.', offsetof(NlaTrack, name), 64);
|
2006-02-08 16:58:12 +00:00
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* return the new track */
|
|
|
|
return nlt;
|
2006-02-08 16:58:12 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* *************************************************** */
|
|
|
|
/* Basic Utilities */
|
2006-02-08 16:58:12 +00:00
|
|
|
|
2009-05-23 09:36:18 +00:00
|
|
|
/* NLA-Tracks ---------------------------------------- */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* Find the active NLA-track for the given stack */
|
|
|
|
NlaTrack *BKE_nlatrack_find_active (ListBase *tracks)
|
|
|
|
{
|
|
|
|
NlaTrack *nlt;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if ELEM(NULL, tracks, tracks->first)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* try to find the first active track */
|
|
|
|
for (nlt= tracks->first; nlt; nlt= nlt->next) {
|
|
|
|
if (nlt->flag & NLATRACK_ACTIVE)
|
|
|
|
return nlt;
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* none found */
|
|
|
|
return NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* Make the given NLA-track the active one for the given stack. If no track is provided,
|
|
|
|
* this function can be used to simply deactivate all the NLA tracks in the given stack too.
|
|
|
|
*/
|
|
|
|
void BKE_nlatrack_set_active (ListBase *tracks, NlaTrack *nlt_a)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-05-22 01:16:26 +00:00
|
|
|
NlaTrack *nlt;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if ELEM(NULL, tracks, tracks->first)
|
2002-10-12 11:37:38 +00:00
|
|
|
return;
|
2009-05-22 01:16:26 +00:00
|
|
|
|
|
|
|
/* deactive all the rest */
|
|
|
|
for (nlt= tracks->first; nlt; nlt= nlt->next)
|
|
|
|
nlt->flag &= ~NLATRACK_ACTIVE;
|
|
|
|
|
|
|
|
/* set the given one as the active one */
|
|
|
|
if (nlt_a)
|
|
|
|
nlt_a->flag |= NLATRACK_ACTIVE;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-05-23 09:36:18 +00:00
|
|
|
/* Check if there is any space in the last track to add the given strip */
|
|
|
|
short BKE_nlatrack_has_space (NlaTrack *nlt, float start, float end)
|
|
|
|
{
|
|
|
|
NlaStrip *strip;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if ((nlt == NULL) || IS_EQ(start, end))
|
|
|
|
return 0;
|
|
|
|
if (start > end) {
|
|
|
|
puts("BKE_nlatrack_has_space error... start and end arguments swapped");
|
|
|
|
SWAP(float, start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop over NLA strips checking for any overlaps with this area... */
|
|
|
|
for (strip= nlt->strips.first; strip; strip= strip->next) {
|
|
|
|
/* if start frame of strip is past the target end-frame, that means that
|
|
|
|
* we've gone past the window we need to check for, so things are fine
|
|
|
|
*/
|
|
|
|
if (strip->start > end)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* if the end of the strip is greater than either of the boundaries, the range
|
|
|
|
* must fall within the extents of the strip
|
|
|
|
*/
|
|
|
|
if ((strip->end > start) || (strip->end > end))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we are still here, we haven't encountered any overlapping strips */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Rearrange the strips in the track so that they are always in order
|
|
|
|
* (usually only needed after a strip has been moved)
|
|
|
|
*/
|
|
|
|
void BKE_nlatrack_sort_strips (NlaTrack *nlt)
|
|
|
|
{
|
|
|
|
ListBase tmp = {NULL, NULL};
|
|
|
|
NlaStrip *strip, *sstrip;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if ELEM(NULL, nlt, nlt->strips.first)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* we simply perform insertion sort on this list, since it is assumed that per track,
|
|
|
|
* there are only likely to be at most 5-10 strips
|
|
|
|
*/
|
|
|
|
for (strip= nlt->strips.first; strip; strip= strip->next) {
|
|
|
|
short not_added = 1;
|
|
|
|
|
|
|
|
/* remove this strip from the list, and add it to the new list, searching from the end of
|
|
|
|
* the list, assuming that the lists are in order
|
|
|
|
*/
|
|
|
|
BLI_remlink(&nlt->strips, strip);
|
|
|
|
|
|
|
|
for (sstrip= tmp.last; not_added && sstrip; sstrip= sstrip->prev) {
|
|
|
|
/* check if add after */
|
|
|
|
if (sstrip->end < strip->start) {
|
|
|
|
BLI_insertlinkafter(&tmp, sstrip, strip);
|
|
|
|
not_added= 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add before first? */
|
|
|
|
if (not_added)
|
|
|
|
BLI_addhead(&tmp, strip);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reassign the start and end points of the strips */
|
|
|
|
nlt->strips.first= tmp.first;
|
|
|
|
nlt->strips.last= tmp.last;
|
|
|
|
}
|
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* Tools ------------------------------------------- */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-05-22 01:16:26 +00:00
|
|
|
/* For the given AnimData block, add the active action to the NLA
|
|
|
|
* stack (i.e. 'push-down' action). The UI should only allow this
|
|
|
|
* for normal editing only (i.e. not in editmode for some strip's action),
|
|
|
|
* so no checks for this are performed.
|
|
|
|
*/
|
|
|
|
// TODO: maybe we should have checks for this too...
|
|
|
|
void BKE_nla_action_pushdown (AnimData *adt)
|
|
|
|
{
|
|
|
|
NlaTrack *nlt;
|
|
|
|
NlaStrip *strip;
|
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
// TODO: need to report the error for this
|
|
|
|
if ELEM(NULL, adt, adt->action)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* if the action is empty, we also shouldn't try to add to stack,
|
|
|
|
* as that will cause us grief down the track
|
|
|
|
*/
|
2009-05-23 09:36:18 +00:00
|
|
|
// TODO: what about modifiers?
|
2009-05-30 11:05:29 +00:00
|
|
|
if (action_has_motion(adt->action) == 0) {
|
|
|
|
printf("BKE_nla_action_pushdown(): action has no data \n");
|
2009-05-23 09:36:18 +00:00
|
|
|
return;
|
2009-05-30 11:05:29 +00:00
|
|
|
}
|
2009-05-22 01:16:26 +00:00
|
|
|
|
|
|
|
/* add a new NLA track to house this action
|
|
|
|
* - we could investigate trying to fit the action into an appropriately
|
|
|
|
* sized gap in the existing tracks, however, this may result in unexpected
|
|
|
|
* changes in blending behaviour...
|
|
|
|
*/
|
|
|
|
nlt= add_nlatrack(adt);
|
2009-05-30 11:05:29 +00:00
|
|
|
if (nlt == NULL) {
|
|
|
|
printf("BKE_nla_action_pushdown(): no NLA-track added \n");
|
2009-05-22 01:16:26 +00:00
|
|
|
return;
|
2009-05-30 11:05:29 +00:00
|
|
|
}
|
2009-05-22 01:16:26 +00:00
|
|
|
|
|
|
|
/* add a new NLA strip to the track, which references the active action */
|
|
|
|
strip= add_nlastrip(nlt, adt->action);
|
|
|
|
|
|
|
|
/* clear reference to action now that we've pushed it onto the stack */
|
|
|
|
if (strip) {
|
|
|
|
adt->action->id.us--;
|
|
|
|
adt->action= NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: set any other flags necessary here...
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-05-22 01:16:26 +00:00
|
|
|
|
|
|
|
/* *************************************************** */
|