Blender  V2.59
rna_nla.c
Go to the documentation of this file.
00001 /*
00002  * $Id: rna_nla.c 37031 2011-05-31 02:14:25Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * Contributor(s): Blender Foundation (2009), Joshua Leung
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #include <stdlib.h>
00031 
00032 #include "RNA_define.h"
00033 
00034 #include "rna_internal.h"
00035 
00036 #include "DNA_anim_types.h"
00037 #include "DNA_action_types.h"
00038 #include "DNA_scene_types.h"
00039 
00040 #include "MEM_guardedalloc.h"
00041 
00042 #include "WM_api.h"
00043 #include "WM_types.h"
00044 
00045 #ifdef RNA_RUNTIME
00046 
00047 #include <stdio.h>
00048 #include <math.h>
00049 
00050 /* needed for some of the validation stuff... */
00051 #include "BKE_animsys.h"
00052 #include "BKE_nla.h"
00053 
00054 #include "ED_anim_api.h"
00055 
00056 /* temp constant defined for these funcs only... */
00057 #define NLASTRIP_MIN_LEN_THRESH         0.1f
00058 
00059 static void rna_NlaStrip_name_set(PointerRNA *ptr, const char *value)
00060 {
00061         NlaStrip *data= (NlaStrip *)ptr->data;
00062         
00063         /* copy the name first */
00064         BLI_strncpy(data->name, value, sizeof(data->name));
00065         
00066         /* validate if there's enough info to do so */
00067         if (ptr->id.data) {
00068                 AnimData *adt= BKE_animdata_from_id(ptr->id.data);
00069                 BKE_nlastrip_validate_name(adt, data);
00070         }
00071 }
00072 
00073 static char *rna_NlaStrip_path(PointerRNA *ptr)
00074 {
00075         NlaStrip *strip= (NlaStrip *)ptr->data;
00076         AnimData *adt= BKE_animdata_from_id(ptr->id.data);
00077         
00078         /* if we're attached to AnimData, try to resolve path back to AnimData */
00079         if (adt) {
00080                 NlaTrack *nlt;
00081                 NlaStrip *nls;
00082                 
00083                 for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
00084                         for (nls = nlt->strips.first; nls; nls = nls->next) {
00085                                 if (nls == strip) {
00086                                         // XXX but if we animate like this, the control will never work...
00087                                         return BLI_sprintfN("animation_data.nla_tracks[\"%s\"].strips[\"%s\"]", nlt->name, strip->name);
00088                                 }
00089                         }
00090                 }
00091         }
00092         
00093         /* no path */
00094         return "";
00095 }
00096 
00097 static void rna_NlaStrip_transform_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
00098 {
00099         NlaStrip *strip= (NlaStrip*)ptr->data;
00100 
00101         BKE_nlameta_flush_transforms(strip);
00102 }
00103 
00104 static void rna_NlaStrip_start_frame_set(PointerRNA *ptr, float value)
00105 {
00106         NlaStrip *data= (NlaStrip*)ptr->data;
00107         
00108         /* clamp value to lie within valid limits 
00109          *      - cannot start past the end of the strip + some flexibility threshold
00110          *      - cannot start before the previous strip (if present) ends
00111          *              -> but if it was a transition, we could go up to the start of the strip + some flexibility threshold
00112          *              as long as we re-adjust the transition afterwards
00113          *      - minimum frame is -MAXFRAME so that we don't get clipping on frame 0
00114          */
00115         if (data->prev) {
00116                 if (data->prev->type == NLASTRIP_TYPE_TRANSITION) {
00117                         CLAMP(value, data->prev->start+NLASTRIP_MIN_LEN_THRESH, data->end-NLASTRIP_MIN_LEN_THRESH);
00118                         
00119                         /* readjust the transition to stick to the endpoints of the action-clips */
00120                         data->prev->end= value;
00121                 }
00122                 else {
00123                         CLAMP(value, data->prev->end, data->end-NLASTRIP_MIN_LEN_THRESH);
00124                 }
00125         }
00126         else {
00127                 CLAMP(value, MINAFRAME, data->end);
00128         }
00129         data->start= value;
00130 }
00131 
00132 static void rna_NlaStrip_end_frame_set(PointerRNA *ptr, float value)
00133 {
00134         NlaStrip *data= (NlaStrip*)ptr->data;
00135         
00136         /* clamp value to lie within valid limits
00137          *      - must not have zero or negative length strip, so cannot start before the first frame 
00138          *        + some minimum-strip-length threshold
00139          *      - cannot end later than the start of the next strip (if present)
00140          *              -> but if it was a transition, we could go up to the start of the end - some flexibility threshold
00141          *              as long as we re-adjust the transition afterwards
00142          */
00143         if (data->next) {
00144                 if (data->next->type == NLASTRIP_TYPE_TRANSITION) {
00145                         CLAMP(value, data->start+NLASTRIP_MIN_LEN_THRESH, data->next->end-NLASTRIP_MIN_LEN_THRESH);
00146                         
00147                         /* readjust the transition to stick to the endpoints of the action-clips */
00148                         data->next->start= value;
00149                 }
00150                 else {
00151                         CLAMP(value, data->start+NLASTRIP_MIN_LEN_THRESH, data->next->start);
00152                 }
00153         }
00154         else {
00155                 CLAMP(value, data->start+NLASTRIP_MIN_LEN_THRESH, MAXFRAME);
00156         }
00157         data->end= value;
00158         
00159         
00160         /* calculate the lengths the strip and its action (if applicable) */
00161         if (data->type == NLASTRIP_TYPE_CLIP) {
00162                 float len, actlen;
00163                 
00164                 len= data->end - data->start;
00165                 actlen= data->actend - data->actstart;
00166                 if (IS_EQF(actlen, 0.0f)) actlen= 1.0f;
00167                 
00168                 /* now, adjust the 'scale' setting to reflect this (so that this change can be valid) */
00169                 data->scale= len / ((actlen) * data->repeat);
00170         }
00171 }
00172 
00173 static void rna_NlaStrip_scale_set(PointerRNA *ptr, float value)
00174 {
00175         NlaStrip *data= (NlaStrip*)ptr->data;
00176         
00177         /* set scale value */
00178         CLAMP(value, 0.0001f, 1000.0f); /* NOTE: these need to be synced with the values in the property definition in rna_def_nlastrip() */
00179         data->scale= value;
00180         
00181         /* adjust the strip extents in response to this */
00182         BKE_nlastrip_recalculate_bounds(data);
00183 }
00184 
00185 static void rna_NlaStrip_repeat_set(PointerRNA *ptr, float value)
00186 {
00187         NlaStrip *data= (NlaStrip*)ptr->data;
00188         
00189         /* set repeat value */
00190         CLAMP(value, 0.01f, 1000.0f); /* NOTE: these need to be synced with the values in the property definition in rna_def_nlastrip() */
00191         data->repeat= value;
00192         
00193         /* adjust the strip extents in response to this */
00194         BKE_nlastrip_recalculate_bounds(data);
00195 }
00196 
00197 static void rna_NlaStrip_blend_in_set(PointerRNA *ptr, float value)
00198 {
00199         NlaStrip *data= (NlaStrip*)ptr->data;
00200         float len;
00201         
00202         /* blend-in is limited to the length of the strip, and also cannot overlap with blendout */
00203         len= (data->end - data->start) - data->blendout;
00204         CLAMP(value, 0, len);
00205         
00206         data->blendin= value;
00207 }
00208 
00209 static void rna_NlaStrip_blend_out_set(PointerRNA *ptr, float value)
00210 {
00211         NlaStrip *data= (NlaStrip*)ptr->data;
00212         float len;
00213         
00214         /* blend-out is limited to the length of the strip */
00215         len= (data->end - data->start);
00216         CLAMP(value, 0, len);
00217         
00218         /* it also cannot overlap with blendin */
00219         if ((len - value) < data->blendin)
00220                 value= len - data->blendin;
00221         
00222         data->blendout= value;
00223 }
00224 
00225 static void rna_NlaStrip_action_start_frame_set(PointerRNA *ptr, float value)
00226 {
00227         NlaStrip *data= (NlaStrip*)ptr->data;
00228         
00229         /* prevent start frame from occurring after end of action */
00230         CLAMP(value, MINAFRAME, data->actend);
00231         data->actstart= value;
00232         
00233         /* adjust the strip extents in response to this */
00234         // TODO: should the strip be moved backwards instead as a special case?
00235         BKE_nlastrip_recalculate_bounds(data);
00236 }
00237 
00238 static void rna_NlaStrip_action_end_frame_set(PointerRNA *ptr, float value)
00239 {
00240         NlaStrip *data= (NlaStrip*)ptr->data;
00241         
00242         /* prevent end frame from starting before start of action */
00243         CLAMP(value, data->actstart, MAXFRAME);
00244         data->actend= value;
00245         
00246         /* adjust the strip extents in response to this */
00247         BKE_nlastrip_recalculate_bounds(data);
00248 }
00249 
00250 static void rna_NlaStrip_animated_influence_set(PointerRNA *ptr, int value)
00251 {
00252         NlaStrip *data= (NlaStrip*)ptr->data;
00253         
00254         if (value) {
00255                 /* set the flag, then make sure a curve for this exists */
00256                 data->flag |= NLASTRIP_FLAG_USR_INFLUENCE;
00257                 BKE_nlastrip_validate_fcurves(data);
00258         }
00259         else
00260                 data->flag &= ~NLASTRIP_FLAG_USR_INFLUENCE;
00261 }
00262 
00263 static void rna_NlaStrip_animated_time_set(PointerRNA *ptr, int value)
00264 {
00265         NlaStrip *data= (NlaStrip*)ptr->data;
00266         
00267         if (value) {
00268                 /* set the flag, then make sure a curve for this exists */
00269                 data->flag |= NLASTRIP_FLAG_USR_TIME;
00270                 BKE_nlastrip_validate_fcurves(data);
00271         }
00272         else
00273                 data->flag &= ~NLASTRIP_FLAG_USR_TIME;
00274 }
00275 
00276 static NlaStrip *rna_NlaStrip_new(NlaTrack *track, bContext *C, ReportList *reports, const char *UNUSED(name), int start, bAction *action)
00277 {
00278         NlaStrip *strip = add_nlastrip(action);
00279         
00280         if (strip == NULL) {
00281                 BKE_reportf(reports, RPT_ERROR, "Unable to create new strip.");
00282                 return NULL;
00283         }
00284         
00285         strip->end += (start - strip->start);
00286         strip->start = start;
00287         
00288         if (BKE_nlastrips_add_strip(&track->strips, strip) == 0) {
00289                 BKE_reportf(reports, RPT_ERROR, "Unable to add strip. Track doesn't have any space to accommodate this new strip.");
00290                 free_nlastrip(NULL, strip);
00291                 return NULL;
00292         }
00293         
00294         /* create dummy AnimData block so that BKE_nlastrip_validate_name() 
00295          * can be used to ensure a valid name, as we don't have one here...
00296          *      - only the nla_tracks list is needed there, which we aim to reverse engineer here...
00297          */
00298         {
00299                 AnimData adt = {NULL};
00300                 NlaTrack *nlt, *nlt_p;
00301                 
00302                 /* 'first' NLA track is found by going back up chain of given track's parents until we fall off */
00303                 nlt_p = track; nlt = track;
00304                 while ((nlt = nlt->prev) != NULL)
00305                         nlt_p = nlt;
00306                 adt.nla_tracks.first = nlt_p;
00307                 
00308                 /* do the same thing to find the last track */
00309                 nlt_p = track; nlt = track;
00310                 while ((nlt = nlt->next) != NULL)
00311                         nlt_p = nlt;
00312                 adt.nla_tracks.last = nlt_p;
00313                 
00314                 /* now we can just auto-name as usual */
00315                 BKE_nlastrip_validate_name(&adt, strip);
00316         }
00317         
00318         WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_ADDED, NULL);
00319         
00320         return strip;
00321 }
00322 
00323 static void rna_NlaStrip_remove(NlaTrack *track, bContext *C, ReportList *reports, NlaStrip *strip)
00324 {
00325         if(BLI_findindex(&track->strips, strip) == -1) {
00326                 BKE_reportf(reports, RPT_ERROR, "NLA's Strip '%s' not found in track '%s'", strip->name, track->name);
00327                 return;
00328         }
00329         else {
00330                 free_nlastrip(&track->strips, strip);
00331                 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_REMOVED, NULL);
00332         }
00333 }
00334 
00335 #else
00336 
00337 /* enum defines exported for rna_animation.c */
00338 EnumPropertyItem nla_mode_blend_items[] = {
00339         {NLASTRIP_MODE_REPLACE, "REPLACE", 0, "Replace", "Result strip replaces the accumulated results by amount specified by influence"},
00340         {NLASTRIP_MODE_ADD, "ADD", 0, "Add", "Weighted result of strip is added to the accumulated results"},
00341         {NLASTRIP_MODE_SUBTRACT, "SUBTRACT", 0, "Subtract", "Weighted result of strip is removed from the accumulated results"},
00342         {NLASTRIP_MODE_MULTIPLY, "MULITPLY", 0, "Multiply", "Weighted result of strip is multiplied with the accumulated results"},
00343         {0, NULL, 0, NULL, NULL}};
00344 EnumPropertyItem nla_mode_extend_items[] = {
00345         {NLASTRIP_EXTEND_NOTHING, "NOTHING", 0, "Nothing", "Strip has no influence past its extents"},
00346         {NLASTRIP_EXTEND_HOLD, "HOLD", 0, "Hold", "Hold the first frame if no previous strips in track, and always hold last frame"},
00347         {NLASTRIP_EXTEND_HOLD_FORWARD, "HOLD_FORWARD", 0, "Hold Forward", "Only hold last frame"},
00348         {0, NULL, 0, NULL, NULL}};
00349 
00350 static void rna_def_nlastrip(BlenderRNA *brna)
00351 {
00352         StructRNA *srna;
00353         PropertyRNA *prop;
00354         
00355                 /* enum defs */
00356         static EnumPropertyItem prop_type_items[] = {
00357                 {NLASTRIP_TYPE_CLIP, "CLIP", 0, "Action Clip", "NLA Strip references some Action"},
00358                 {NLASTRIP_TYPE_TRANSITION, "TRANSITION", 0, "Transition", "NLA Strip 'transitions' between adjacent strips"},
00359                 {NLASTRIP_TYPE_META, "META", 0, "Meta", "NLA Strip acts as a container for adjacent strips"},
00360                 {0, NULL, 0, NULL, NULL}};
00361         
00362         /* struct definition */
00363         srna= RNA_def_struct(brna, "NlaStrip", NULL);
00364         RNA_def_struct_ui_text(srna, "NLA Strip", "A container referencing an existing Action");
00365         RNA_def_struct_path_func(srna, "rna_NlaStrip_path");
00366         RNA_def_struct_ui_icon(srna, ICON_NLA); // XXX
00367         
00368         /* name property */
00369         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
00370         RNA_def_property_ui_text(prop, "Name", "");
00371         RNA_def_property_string_funcs(prop, NULL, NULL, "rna_NlaStrip_name_set");
00372         RNA_def_struct_name_property(srna, prop);
00373         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00374         
00375         /* Enums */
00376         prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
00377         RNA_def_property_enum_sdna(prop, NULL, "type");
00378         RNA_def_property_clear_flag(prop, PROP_EDITABLE); // XXX for now, not editable, since this is dangerous
00379         RNA_def_property_enum_items(prop, prop_type_items);
00380         RNA_def_property_ui_text(prop, "Type", "Type of NLA Strip");
00381         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00382         
00383         prop= RNA_def_property(srna, "extrapolation", PROP_ENUM, PROP_NONE);
00384         RNA_def_property_enum_sdna(prop, NULL, "extendmode");
00385         RNA_def_property_enum_items(prop, nla_mode_extend_items);
00386         RNA_def_property_ui_text(prop, "Extrapolation", "Action to take for gaps past the strip extents");
00387         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00388         
00389         prop= RNA_def_property(srna, "blend_type", PROP_ENUM, PROP_NONE);
00390         RNA_def_property_enum_sdna(prop, NULL, "blendmode");
00391         RNA_def_property_enum_items(prop, nla_mode_blend_items);
00392         RNA_def_property_ui_text(prop, "Blending", "Method used for combining strip's result with accumulated result");
00393         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00394         
00395         /* Strip extents */
00396         prop= RNA_def_property(srna, "frame_start", PROP_FLOAT, PROP_TIME);
00397         RNA_def_property_float_sdna(prop, NULL, "start");
00398         RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_start_frame_set", NULL);
00399         RNA_def_property_ui_text(prop, "Start Frame", "");
00400         RNA_def_property_update(prop, 0, "rna_NlaStrip_transform_update");
00401         
00402         prop= RNA_def_property(srna, "frame_end", PROP_FLOAT, PROP_TIME);
00403         RNA_def_property_float_sdna(prop, NULL, "end");
00404         RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_end_frame_set", NULL);
00405         RNA_def_property_ui_text(prop, "End Frame", "");
00406         RNA_def_property_update(prop, 0, "rna_NlaStrip_transform_update");
00407         
00408         /* Blending */
00409         prop= RNA_def_property(srna, "blend_in", PROP_FLOAT, PROP_NONE);
00410         RNA_def_property_float_sdna(prop, NULL, "blendin");
00411         RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_blend_in_set", NULL);
00412         RNA_def_property_ui_text(prop, "Blend In", "Number of frames at start of strip to fade in influence");
00413         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00414         
00415         prop= RNA_def_property(srna, "blend_out", PROP_FLOAT, PROP_NONE);
00416         RNA_def_property_float_sdna(prop, NULL, "blendout");
00417         RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_blend_out_set", NULL);
00418         RNA_def_property_ui_text(prop, "Blend Out", "");
00419         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00420         
00421         prop= RNA_def_property(srna, "use_auto_blend", PROP_BOOLEAN, PROP_NONE);
00422         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_AUTO_BLENDS);
00423         RNA_def_property_ui_text(prop, "Auto Blend In/Out", "Number of frames for Blending In/Out is automatically determined from overlapping strips");
00424         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00425         
00426         /* Action */
00427         prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
00428         RNA_def_property_pointer_sdna(prop, NULL, "act");
00429         RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Action_id_poll");
00430         RNA_def_property_flag(prop, PROP_EDITABLE); 
00431         RNA_def_property_ui_text(prop, "Action", "Action referenced by this strip");
00432         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00433         
00434         /* Action extents */
00435         prop= RNA_def_property(srna, "action_frame_start", PROP_FLOAT, PROP_TIME);
00436         RNA_def_property_float_sdna(prop, NULL, "actstart");
00437         RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_action_start_frame_set", NULL);
00438         RNA_def_property_ui_text(prop, "Action Start Frame", "");
00439         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00440         
00441         prop= RNA_def_property(srna, "action_frame_end", PROP_FLOAT, PROP_TIME);
00442         RNA_def_property_float_sdna(prop, NULL, "actend");
00443         RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_action_end_frame_set", NULL);
00444         RNA_def_property_ui_text(prop, "Action End Frame", "");
00445         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00446         
00447         /* Action Reuse */
00448         prop= RNA_def_property(srna, "repeat", PROP_FLOAT, PROP_NONE);
00449         RNA_def_property_float_sdna(prop, NULL, "repeat"); 
00450         RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_repeat_set", NULL);
00451         RNA_def_property_range(prop, 0.1f, 1000.0f); /* these limits have currently be chosen arbitarily, but could be extended (minimum should still be > 0 though) if needed... */
00452         RNA_def_property_ui_text(prop, "Repeat", "Number of times to repeat the action range");
00453         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00454         
00455         prop= RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
00456         RNA_def_property_float_sdna(prop, NULL, "scale"); 
00457         RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_scale_set", NULL);
00458         RNA_def_property_range(prop, 0.0001f, 1000.0f); /* these limits can be extended, but beyond this, we can get some crazy+annoying bugs due to numeric errors */
00459         RNA_def_property_ui_text(prop, "Scale", "Scaling factor for action");
00460         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00461         
00462         /* Strip's F-Curves */
00463         prop= RNA_def_property(srna, "fcurves", PROP_COLLECTION, PROP_NONE);
00464         RNA_def_property_struct_type(prop, "FCurve");
00465         RNA_def_property_ui_text(prop, "F-Curves", "F-Curves for controlling the strip's influence and timing");
00466         
00467         /* Strip's F-Modifiers */
00468         prop= RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE);
00469         RNA_def_property_struct_type(prop, "FModifier");
00470         RNA_def_property_ui_text(prop, "Modifiers", "Modifiers affecting all the F-Curves in the referenced Action");
00471         
00472         /* Strip's Sub-Strips (for Meta-Strips) */
00473         prop= RNA_def_property(srna, "strips", PROP_COLLECTION, PROP_NONE);
00474         RNA_def_property_struct_type(prop, "NlaStrip");
00475         RNA_def_property_ui_text(prop, "NLA Strips", "NLA Strips that this strip acts as a container for (if it is of type Meta)");
00476         
00477         /* Settings - Values necessary for evaluation */
00478         prop= RNA_def_property(srna, "influence", PROP_FLOAT, PROP_NONE);
00479         RNA_def_property_range(prop, 0.0f, 1.0f);
00480         RNA_def_property_ui_text(prop, "Influence", "Amount the strip contributes to the current result");
00481         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00482         
00483         prop= RNA_def_property(srna, "strip_time", PROP_FLOAT, PROP_TIME);
00484         RNA_def_property_ui_text(prop, "Strip Time", "Frame of referenced Action to evaluate");
00485         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00486         
00487                 // TODO: should the animated_influence/time settings be animatable themselves?
00488         prop= RNA_def_property(srna, "use_animated_influence", PROP_BOOLEAN, PROP_NONE);
00489         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_USR_INFLUENCE);
00490         RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaStrip_animated_influence_set");
00491         RNA_def_property_ui_text(prop, "Animated Influence", "Influence setting is controlled by an F-Curve rather than automatically determined");
00492         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00493         
00494         prop= RNA_def_property(srna, "use_animated_time", PROP_BOOLEAN, PROP_NONE);
00495         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_USR_TIME);
00496         RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaStrip_animated_time_set");
00497         RNA_def_property_ui_text(prop, "Animated Strip Time", "Strip time is controlled by an F-Curve rather than automatically determined");
00498         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00499         
00500         prop= RNA_def_property(srna, "use_animated_time_cyclic", PROP_BOOLEAN, PROP_NONE);
00501         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_USR_TIME_CYCLIC);
00502         RNA_def_property_ui_text(prop, "Cyclic Strip Time", "Cycle the animated time within the action start & end");
00503         RNA_def_property_update(prop, 0, "rna_NlaStrip_transform_update"); // is there a better update flag?
00504         
00505         /* settings */
00506         prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
00507         RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* can be made editable by hooking it up to the necessary NLA API methods */
00508         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_ACTIVE);
00509         RNA_def_property_ui_text(prop, "Active", "NLA Strip is active");
00510         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00511         
00512         prop= RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
00513         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_SELECT);
00514         RNA_def_property_ui_text(prop, "Select", "NLA Strip is selected");
00515         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00516         
00517         prop= RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
00518         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_MUTED);
00519         RNA_def_property_ui_text(prop, "Muted", "NLA Strip is not evaluated");
00520         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00521         
00522         prop= RNA_def_property(srna, "use_reverse", PROP_BOOLEAN, PROP_NONE);
00523         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_REVERSE);
00524         RNA_def_property_ui_text(prop, "Reversed", "NLA Strip is played back in reverse order (only when timing is automatically determined)");
00525         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00526         
00527         // TODO: 
00528         // - sync length
00529 }
00530 
00531 static void rna_api_nlatrack_strips(BlenderRNA *brna, PropertyRNA *cprop)
00532 {
00533         StructRNA *srna;
00534         PropertyRNA *parm;
00535         FunctionRNA *func;
00536 
00537         RNA_def_property_srna(cprop, "NlaStrips");
00538         srna= RNA_def_struct(brna, "NlaStrips", NULL);
00539         RNA_def_struct_sdna(srna, "NlaTrack");
00540         RNA_def_struct_ui_text(srna, "Nla Strips", "Collection of Nla Strips");
00541 
00542         func = RNA_def_function(srna, "new", "rna_NlaStrip_new");
00543         RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
00544         RNA_def_function_ui_description(func, "Add a new Action-Clip strip to the track");
00545         parm= RNA_def_string(func, "name", "NlaStrip", 0, "", "Name for the NLA Strips.");
00546         RNA_def_property_flag(parm, PROP_REQUIRED);
00547         parm = RNA_def_int(func, "start", 0, INT_MIN, INT_MAX, "Start Frame", "Start frame for this strip.", INT_MIN, INT_MAX);
00548         RNA_def_property_flag(parm, PROP_REQUIRED);
00549         parm = RNA_def_pointer(func, "action", "Action", "", "Action to assign to this strip.");
00550         RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
00551         /* return type */
00552         parm = RNA_def_pointer(func, "strip", "NlaStrip", "", "New NLA Strip.");
00553         RNA_def_function_return(func, parm);
00554 
00555         func = RNA_def_function(srna, "remove", "rna_NlaStrip_remove");
00556         RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
00557         RNA_def_function_ui_description(func, "Remove a NLA Strip.");
00558         parm = RNA_def_pointer(func, "strip", "NlaStrip", "", "NLA Strip to remove.");
00559         RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
00560 }
00561 
00562 static void rna_def_nlatrack(BlenderRNA *brna)
00563 {
00564         StructRNA *srna;
00565         PropertyRNA *prop;
00566         
00567         srna= RNA_def_struct(brna, "NlaTrack", NULL);
00568         RNA_def_struct_ui_text(srna, "NLA Track", "A animation layer containing Actions referenced as NLA strips");
00569         RNA_def_struct_ui_icon(srna, ICON_NLA);
00570         
00571         /* strips collection */
00572         prop= RNA_def_property(srna, "strips", PROP_COLLECTION, PROP_NONE);
00573         RNA_def_property_struct_type(prop, "NlaStrip");
00574         RNA_def_property_ui_text(prop, "NLA Strips", "NLA Strips on this NLA-track");
00575 
00576         rna_api_nlatrack_strips(brna, prop);
00577 
00578         /* name property */
00579         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
00580         RNA_def_property_ui_text(prop, "Name", "");
00581         RNA_def_struct_name_property(srna, prop);
00582         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00583         
00584         /* settings */
00585         prop= RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
00586         RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* can be made editable by hooking it up to the necessary NLA API methods */
00587         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLATRACK_ACTIVE);
00588         RNA_def_property_ui_text(prop, "Active", "NLA Track is active");
00589         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00590         
00591         prop= RNA_def_property(srna, "is_solo", PROP_BOOLEAN, PROP_NONE);
00592         RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* can be made editable by hooking it up to the necessary NLA API methods */
00593         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLATRACK_SOLO);
00594         RNA_def_property_ui_text(prop, "Solo", "NLA Track is evaluated itself (i.e. active Action and all other NLA Tracks in the same AnimData block are disabled)");
00595         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00596         
00597         prop= RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
00598         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLATRACK_SELECTED);
00599         RNA_def_property_ui_text(prop, "Select", "NLA Track is selected");
00600         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00601         
00602         prop= RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
00603         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLATRACK_MUTED);
00604         RNA_def_property_ui_text(prop, "Muted", "NLA Track is not evaluated");
00605         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00606 
00607         prop= RNA_def_property(srna, "lock", PROP_BOOLEAN, PROP_NONE);
00608         RNA_def_property_boolean_sdna(prop, NULL, "flag", NLATRACK_PROTECTED);
00609         RNA_def_property_ui_text(prop, "Locked", "NLA Track is locked");
00610         RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */
00611 }
00612 
00613 /* --------- */
00614 
00615 void RNA_def_nla(BlenderRNA *brna)
00616 {
00617         rna_def_nlatrack(brna);
00618         rna_def_nlastrip(brna);
00619 }
00620 
00621 
00622 #endif