#include <stdio.h>
#include <math.h>
+/* needed for some of the validation stuff... */
+#include "BKE_animsys.h"
+#include "BKE_nla.h"
+
/* temp constant defined for these funcs only... */
#define NLASTRIP_MIN_LEN_THRESH 0.1f
+static void rna_NlaStrip_name_set(PointerRNA *ptr, const char *value)
+{
+ NlaStrip *data= (NlaStrip *)ptr->data;
+
+ /* copy the name first */
+ BLI_strncpy(data->name, value, sizeof(data->name));
+
+ /* validate if there's enough info to do so */
+ if (ptr->id.data) {
+ AnimData *adt= BKE_animdata_from_id(ptr->id.data);
+ BKE_nlastrip_validate_name(adt, data);
+ }
+}
+
+static char *rna_NlaStrip_path(PointerRNA *ptr)
+{
+ NlaStrip *strip= (NlaStrip *)ptr->data;
+ AnimData *adt= BKE_animdata_from_id(ptr->id.data);
+
+ /* if we're attached to AnimData, try to resolve path back to AnimData */
+ if (adt) {
+ NlaTrack *nlt;
+ NlaStrip *nls;
+
+ for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
+ for (nls = nlt->strips.first; nls; nls = nls->next) {
+ if (nls == strip) {
+ // XXX but if we animate like this, the control will never work...
+ return BLI_sprintfN("animation_data.nla_tracks[\"%s\"].strips[\"%s\"]", nlt->name, strip->name);
+ }
+ }
+ }
+ }
+
+ /* no path */
+ return "";
+}
+
+
static void rna_NlaStrip_start_frame_set(PointerRNA *ptr, float value)
{
NlaStrip *data= (NlaStrip*)ptr->data;
}
}
else {
- CLAMP(value, -MAXFRAME, data->end);
+ CLAMP(value, MINAFRAME, data->end);
}
data->start= value;
}
static void rna_NlaStrip_action_start_frame_set(PointerRNA *ptr, float value)
{
NlaStrip *data= (NlaStrip*)ptr->data;
- CLAMP(value, -MAXFRAME, data->actend);
+ CLAMP(value, MINAFRAME, data->actend);
data->actstart= value;
}
data->actend= value;
}
+static void rna_NlaStrip_animated_influence_set(PointerRNA *ptr, int value)
+{
+ NlaStrip *data= (NlaStrip*)ptr->data;
+
+ if (value) {
+ /* set the flag, then make sure a curve for this exists */
+ data->flag |= NLASTRIP_FLAG_USR_INFLUENCE;
+ BKE_nlastrip_validate_fcurves(data);
+ }
+ else
+ data->flag &= ~NLASTRIP_FLAG_USR_INFLUENCE;
+}
+
+static void rna_NlaStrip_animated_time_set(PointerRNA *ptr, int value)
+{
+ NlaStrip *data= (NlaStrip*)ptr->data;
+
+ if (value) {
+ /* set the flag, then make sure a curve for this exists */
+ data->flag |= NLASTRIP_FLAG_USR_TIME;
+ BKE_nlastrip_validate_fcurves(data);
+ }
+ else
+ data->flag &= ~NLASTRIP_FLAG_USR_TIME;
+}
+
#else
-void rna_def_nlastrip(BlenderRNA *brna)
+/* enum defines exported for rna_animation.c */
+EnumPropertyItem nla_mode_blend_items[] = {
+ {NLASTRIP_MODE_REPLACE, "REPLACE", 0, "Replace", "Result strip replaces the accumulated results by amount specified by influence."},
+ {NLASTRIP_MODE_ADD, "ADD", 0, "Add", "Weighted result of strip is added to the accumlated results."},
+ {NLASTRIP_MODE_SUBTRACT, "SUBTRACT", 0, "Subtract", "Weighted result of strip is removed from the accumlated results."},
+ {NLASTRIP_MODE_MULTIPLY, "MULITPLY", 0, "Multiply", "Weighted result of strip is multiplied with the accumlated results."},
+ {0, NULL, 0, NULL, NULL}};
+EnumPropertyItem nla_mode_extend_items[] = {
+ {NLASTRIP_EXTEND_NOTHING, "NOTHING", 0, "Nothing", "Strip has no influence past its extents."},
+ {NLASTRIP_EXTEND_HOLD, "HOLD", 0, "Hold", "Hold the first frame if no previous strips in track, and always hold last frame."},
+ {NLASTRIP_EXTEND_HOLD_FORWARD, "HOLD_FORWARD", 0, "Hold Forward", "Only hold last frame."},
+ {0, NULL, 0, NULL, NULL}};
+
+static void rna_def_nlastrip(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
static EnumPropertyItem prop_type_items[] = {
{NLASTRIP_TYPE_CLIP, "CLIP", 0, "Action Clip", "NLA Strip references some Action."},
{NLASTRIP_TYPE_TRANSITION, "TRANSITION", 0, "Transition", "NLA Strip 'transitions' between adjacent strips."},
- {0, NULL, 0, NULL, NULL}};
- static EnumPropertyItem prop_mode_blend_items[] = {
- {NLASTRIP_MODE_BLEND, "BLEND", 0, "Blend", "Results of strip and accumulated results are combined in ratio governed by influence."},
- {NLASTRIP_MODE_ADD, "ADD", 0, "Add", "Weighted result of strip is added to the accumlated results."},
- {NLASTRIP_MODE_SUBTRACT, "SUBTRACT", 0, "Subtract", "Weighted result of strip is removed from the accumlated results."},
- {NLASTRIP_MODE_MULTIPLY, "MULITPLY", 0, "Multiply", "Weighted result of strip is multiplied with the accumlated results."},
- {0, NULL, 0, NULL, NULL}};
- static EnumPropertyItem prop_mode_extend_items[] = {
- {NLASTRIP_EXTEND_NOTHING, "NOTHING", 0, "Nothing", "Strip has no influence past its extents."},
- {NLASTRIP_EXTEND_HOLD, "HOLD", 0, "Hold", "Hold the first frame if no previous strips in track, and always hold last frame."},
- {NLASTRIP_EXTEND_HOLD_FORWARD, "HOLD_FORWARD", 0, "Hold Forward", "Only hold last frame."},
+ {NLASTRIP_TYPE_META, "META", 0, "Meta", "NLA Strip acts as a container for adjacent strips."},
{0, NULL, 0, NULL, NULL}};
/* struct definition */
srna= RNA_def_struct(brna, "NlaStrip", NULL);
RNA_def_struct_ui_text(srna, "NLA Strip", "A container referencing an existing Action.");
+ RNA_def_struct_path_func(srna, "rna_NlaStrip_path");
RNA_def_struct_ui_icon(srna, ICON_NLA); // XXX
+ /* name property */
+ prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Name", "");
+ RNA_def_property_string_funcs(prop, NULL, NULL, "rna_NlaStrip_name_set");
+ RNA_def_struct_name_property(srna, prop);
+
/* Enums */
prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "type");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE); // XXX for now, not editable, since this is dangerous
RNA_def_property_enum_items(prop, prop_type_items);
RNA_def_property_ui_text(prop, "Type", "Type of NLA Strip.");
prop= RNA_def_property(srna, "extrapolation", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "extendmode");
- RNA_def_property_enum_items(prop, prop_mode_extend_items);
+ RNA_def_property_enum_items(prop, nla_mode_extend_items);
RNA_def_property_ui_text(prop, "Extrapolation", "Action to take for gaps past the strip extents.");
prop= RNA_def_property(srna, "blending", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "blendmode");
- RNA_def_property_enum_items(prop, prop_mode_blend_items);
+ RNA_def_property_enum_items(prop, nla_mode_blend_items);
RNA_def_property_ui_text(prop, "Blending", "Method used for combining strip's result with accumulated result.");
/* Strip extents */
- prop= RNA_def_property(srna, "start_frame", PROP_FLOAT, PROP_NONE);
+ prop= RNA_def_property(srna, "start_frame", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "start");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_start_frame_set", NULL);
RNA_def_property_ui_text(prop, "Start Frame", "");
- prop= RNA_def_property(srna, "end_frame", PROP_FLOAT, PROP_NONE);
+ prop= RNA_def_property(srna, "end_frame", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "end");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_end_frame_set", NULL);
RNA_def_property_ui_text(prop, "End Frame", "");
/* Action */
prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "act");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Action", "Action referenced by this strip.");
/* Action extents */
- prop= RNA_def_property(srna, "action_start_frame", PROP_FLOAT, PROP_NONE);
+ prop= RNA_def_property(srna, "action_start_frame", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "actstart");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_action_start_frame_set", NULL);
RNA_def_property_ui_text(prop, "Action Start Frame", "");
- prop= RNA_def_property(srna, "action_end_frame", PROP_FLOAT, PROP_NONE);
+ prop= RNA_def_property(srna, "action_end_frame", PROP_FLOAT, PROP_TIME);
RNA_def_property_float_sdna(prop, NULL, "actend");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_action_end_frame_set", NULL);
RNA_def_property_ui_text(prop, "Action End Frame", "");
RNA_def_property_float_sdna(prop, NULL, "repeat");
RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_repeat_set", NULL);
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... */
- RNA_def_property_ui_text(prop, "Repeat", "Number of times to repeat the ");
+ RNA_def_property_ui_text(prop, "Repeat", "Number of times to repeat the action range.");
prop= RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "scale");
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 */
RNA_def_property_ui_text(prop, "Scale", "Scaling factor for action.");
- // TODO: strip's F-Curves?
+ /* Strip's F-Curves */
+ prop= RNA_def_property(srna, "fcurves", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_struct_type(prop, "FCurve");
+ RNA_def_property_ui_text(prop, "F-Curves", "F-Curves for controlling the strip's influence and timing.");
/* Strip's F-Modifiers */
prop= RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "FModifier");
RNA_def_property_ui_text(prop, "Modifiers", "Modifiers affecting all the F-Curves in the referenced Action.");
+ /* Strip's Sub-Strips (for Meta-Strips) */
+ prop= RNA_def_property(srna, "strips", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_struct_type(prop, "NlaStrip");
+ RNA_def_property_ui_text(prop, "NLA Strips", "NLA Strips that this strip acts as a container for (if it is of type Meta).");
+
/* Settings - Values necessary for evaluation */
prop= RNA_def_property(srna, "influence", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Influence", "Amount the strip contributes to the current result.");
- prop= RNA_def_property(srna, "strip_time", PROP_FLOAT, PROP_NONE);
+ prop= RNA_def_property(srna, "strip_time", PROP_FLOAT, PROP_TIME);
RNA_def_property_ui_text(prop, "Strip Time", "Frame of referenced Action to evaluate.");
+ // TODO: should the animated_influence/time settings be animatable themselves?
prop= RNA_def_property(srna, "animated_influence", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE); // XXX for now, not editable
RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_USR_INFLUENCE);
+ RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaStrip_animated_influence_set");
RNA_def_property_ui_text(prop, "Animated Influence", "Influence setting is controlled by an F-Curve rather than automatically determined.");
prop= RNA_def_property(srna, "animated_time", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE); // XXX for now, not editable
- RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_USR_INFLUENCE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", NLASTRIP_FLAG_USR_TIME);
+ RNA_def_property_boolean_funcs(prop, NULL, "rna_NlaStrip_animated_time_set");
RNA_def_property_ui_text(prop, "Animated Strip Time", "Strip time is controlled by an F-Curve rather than automatically determined.");
/* settings */
// - sync length
}
-void rna_def_nlatrack(BlenderRNA *brna)
+static void rna_def_nlatrack(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;