Patch [#24763] NLA Track & Strip methods

Submitted by: Dan Eicher (dna)

<quote>
Adds:

AnimData.nla_tracks.new(prev)
* (optional) prev -- add new track after this track

AnimData.nla_tracks.remove(track)

AnimData.nla_tracks.active(track)
* (optional) track -- track to set active
* returns active track

NlaTrack.strips.new(name, start, action)
NOTE: fails if the strip can't fit in the track as opposed to the
operator which will create a new track and add the strip to that.
* name -- name for new strip
* start -- start frame of new strip
* action -- action to assign to strip

NlaTrack.strips.remove(strip)
</quote>

---

I've resolved the issue (noted in the original patch) regarding the
validation of the created strip by creating and using a "dummy
AnimData" block to solve the missing dependencies.
This commit is contained in:
Joshua Leung 2011-01-12 01:17:13 +00:00
parent 144fb8ed1f
commit 610a759ecc
2 changed files with 159 additions and 2 deletions

@ -48,6 +48,10 @@ EnumPropertyItem keyingset_path_grouping_items[] = {
#ifdef RNA_RUNTIME
#include "BKE_animsys.h"
#include "BKE_nla.h"
#include "WM_api.h"
#include "WM_types.h"
static int rna_AnimData_action_editable(PointerRNA *ptr)
{
@ -381,6 +385,32 @@ static void rna_KeyingSet_paths_clear(KeyingSet *keyingset, ReportList *reports)
}
}
/* needs wrapper function to push notifier */
static NlaTrack *rna_NlaTrack_new(AnimData *adt, bContext *C, NlaTrack *track)
{
NlaTrack *new_track = add_nlatrack(adt, track);
WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_ADDED, NULL);
return new_track;
}
static void rna_NlaTrack_remove(AnimData *adt, bContext *C, NlaTrack *track)
{
free_nlatrack(&adt->nla_tracks, track);
WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_REMOVED, NULL);
}
static NlaTrack *rna_NlaTrack_active(AnimData *adt, bContext *C, NlaTrack *track)
{
if (track != NULL) {
BKE_nlatrack_set_active(&adt->nla_tracks, track);
/* XXX: should (but doesn't) update the active track in the NLA window */
WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_SELECTED, NULL);
}
return BKE_nlatrack_find_active(&adt->nla_tracks);
}
#else
@ -625,6 +655,40 @@ static void rna_def_keyingset(BlenderRNA *brna)
/* --- */
static void rna_api_animdata_nla_tracks(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
PropertyRNA *parm;
FunctionRNA *func;
RNA_def_property_srna(cprop, "NlaTracks");
srna= RNA_def_struct(brna, "NlaTracks", NULL);
RNA_def_struct_sdna(srna, "AnimData");
RNA_def_struct_ui_text(srna, "NLA Tracks", "Collection of NLA Tracks");
func = RNA_def_function(srna, "new", "rna_NlaTrack_new");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Add a new NLA Tracks");
parm = RNA_def_pointer(func, "prev", "NlaTrack", "", "NLA Track to add the new one after.");
/* return type */
parm = RNA_def_pointer(func, "track", "NlaTrack", "", "New NLA Track.");
RNA_def_function_return(func, parm);
func = RNA_def_function(srna, "remove", "rna_NlaTrack_remove");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Remove a NLA Track.");
parm = RNA_def_pointer(func, "track", "NlaTrack", "", "NLA Track to remove.");
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
func = RNA_def_function(srna, "active", "rna_NlaTrack_active");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Set active NLA Track");
parm = RNA_def_pointer(func, "track", "NlaTrack", "", "NLA Track set active.");
/* return type */
parm = RNA_def_pointer(func, "active_track", "NlaTrack", "", "Active NLA Track.");
RNA_def_function_return(func, parm);
}
void rna_def_animdata_common(StructRNA *srna)
{
PropertyRNA *prop;
@ -649,13 +713,14 @@ void rna_def_animdata(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "NlaTrack");
RNA_def_property_ui_text(prop, "NLA Tracks", "NLA Tracks (i.e. Animation Layers)");
rna_api_animdata_nla_tracks(brna, prop);
/* Active Action */
prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_EDITABLE); /* this flag as well as the dynamic test must be defined for this to be editable... */
RNA_def_property_editable_func(prop, "rna_AnimData_action_editable");
RNA_def_property_ui_text(prop, "Action", "Active Action for this datablock");
/* Active Action Settings */
prop= RNA_def_property(srna, "action_extrapolation", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "act_extendmode");

@ -43,6 +43,11 @@
#include "BKE_animsys.h"
#include "BKE_nla.h"
#include "WM_api.h"
#include "WM_types.h"
#include "ED_anim_api.h"
/* temp constant defined for these funcs only... */
#define NLASTRIP_MIN_LEN_THRESH 0.1f
@ -263,6 +268,60 @@ static void rna_NlaStrip_animated_time_set(PointerRNA *ptr, int value)
data->flag &= ~NLASTRIP_FLAG_USR_TIME;
}
static NlaStrip *rna_NlaStrip_new(NlaTrack *track, bContext *C, ReportList *reports, const char *name, int start, bAction *action)
{
NlaStrip *strip = add_nlastrip(action);
if (strip == NULL) {
BKE_reportf(reports, RPT_ERROR, "Unable to create new strip.");
return NULL;
}
strip->end += (start - strip->start);
strip->start = start;
if (BKE_nlastrips_add_strip(&track->strips, strip) == 0) {
BKE_reportf(reports, RPT_ERROR, "Unable to add strip. Track doesn't have any space to accommodate this new strip.");
free_nlastrip(NULL, strip);
return NULL;
}
/* create dummy AnimData block so that BKE_nlastrip_validate_name()
* can be used to ensure a valid name, as we don't have one here...
* - only the nla_tracks list is needed there, which we aim to reverse engineer here...
*/
{
AnimData adt = {0};
NlaTrack *nlt, *nlt_p;
/* 'first' NLA track is found by going back up chain of given track's parents until we fall off */
nlt_p = track; nlt = track;
while ((nlt = nlt->prev) != NULL)
nlt_p = nlt;
adt.nla_tracks.first = nlt_p;
/* do the same thing to find the last track */
nlt_p = track; nlt = track;
while ((nlt = nlt->next) != NULL)
nlt_p = nlt;
adt.nla_tracks.last = nlt_p;
/* now we can just auto-name as usual */
BKE_nlastrip_validate_name(&adt, strip);
}
WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_ADDED, NULL);
return strip;
}
static void rna_NlaStrip_remove(NlaTrack *track, bContext *C, ReportList *reports, NlaStrip *strip)
{
free_nlastrip(&track->strips, strip);
WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_REMOVED, NULL);
}
#else
/* enum defines exported for rna_animation.c */
@ -438,6 +497,37 @@ static void rna_def_nlastrip(BlenderRNA *brna)
// - sync length
}
static void rna_api_nlatrack_strips(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
PropertyRNA *parm;
FunctionRNA *func;
RNA_def_property_srna(cprop, "NlaStrips");
srna= RNA_def_struct(brna, "NlaStrips", NULL);
RNA_def_struct_sdna(srna, "NlaTrack");
RNA_def_struct_ui_text(srna, "Nla Strips", "Collection of Nla Strips");
func = RNA_def_function(srna, "new", "rna_NlaStrip_new");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
RNA_def_function_ui_description(func, "Add a new Action-Clip strip to the track");
parm= RNA_def_string(func, "name", "NlaStrip", 0, "", "Name for the NLA Strips.");
RNA_def_property_flag(parm, PROP_REQUIRED);
parm = RNA_def_int(func, "start", 0, INT_MIN, INT_MAX, "Start Frame", "Start frame for this strip.", INT_MIN, INT_MAX);
RNA_def_property_flag(parm, PROP_REQUIRED);
parm = RNA_def_pointer(func, "action", "Action", "", "Action to assign to this strip.");
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
/* return type */
parm = RNA_def_pointer(func, "strip", "NlaStrip", "", "New NLA Strip.");
RNA_def_function_return(func, parm);
func = RNA_def_function(srna, "remove", "rna_NlaStrip_remove");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
RNA_def_function_ui_description(func, "Remove a NLA Strip.");
parm = RNA_def_pointer(func, "strip", "NlaStrip", "", "NLA Strip to remove.");
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
}
static void rna_def_nlatrack(BlenderRNA *brna)
{
StructRNA *srna;
@ -452,6 +542,8 @@ static void rna_def_nlatrack(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "NlaStrip");
RNA_def_property_ui_text(prop, "NLA Strips", "NLA Strips on this NLA-track");
rna_api_nlatrack_strips(brna, prop);
/* name property */
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(prop, "Name", "");