Page Menu
Home
Search
Configure Global Search
Log In
Files
F26738
envmod.diff
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Peter Staples (batfinger)
Nov 13 2013, 5:38 PM
Size
4 KB
Subscribers
None
envmod.diff
View Options
Index: rna_fcurve.c
===================================================================
--- rna_fcurve.c (revision 54078)
+++ rna_fcurve.c (working copy)
@@ -108,6 +108,8 @@
#include "BKE_depsgraph.h"
#include "BKE_animsys.h"
+#include "DNA_anim_types.h"
+
static void rna_ChannelDriver_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
{
ID *id = ptr->id.data;
@@ -633,6 +635,79 @@
calc_fcurve_range(fcu, range, range + 1, FALSE, FALSE);
}
+static FCM_EnvelopeData *rna_FModifierEnvelope_points_add(FModifier *fmod, float frame)
+{
+ FCM_EnvelopeData fed;
+ FMod_Envelope *env = (FMod_Envelope *)fmod->data;
+ FCM_EnvelopeData *fedn;
+ /* init template data */
+ fed.min = -1.0f;
+ fed.max = 1.0f;
+ fed.time = frame; // XXX make this int for ease of use?
+ fed.f1 = fed.f2 = 0;
+ if (env->data) {
+ /* add point to end of control points ^/
+ /* XXX deal with this later if needs to be ordered */
+ int length = env->totvert;
+
+ /* add new */
+ fedn = MEM_callocN((env->totvert + 1) * sizeof(FCM_EnvelopeData), "FCM_EnvelopeData");
+ memcpy(fedn, env->data, length * sizeof(FCM_EnvelopeData));
+ *(fedn + length) = fed;
+ /* replace (+ free) old with new */
+ MEM_freeN(env->data);
+ env->data = fedn;
+
+ env->totvert++;
+ return (env->data + length);
+
+ }
+ else {
+ env->data = MEM_callocN(sizeof(FCM_EnvelopeData), "FCM_EnvelopeData");
+ *(env->data) = fed;
+ env->totvert = 1;
+ return env->data;
+ }
+
+ return NULL;
+}
+
+void rna_FModifierEnvelope_points_remove(FModifier *fmod, ReportList *reports, PointerRNA *point)
+{
+ FCM_EnvelopeData *cp = point->data;
+ FMod_Envelope *env = (FMod_Envelope *)fmod->data;
+ FCM_EnvelopeData *fedn;
+
+ int index = (int)(cp - env->data);
+
+ /* test point is in range */
+ if (index < 0 || index >= env->totvert) {
+ BKE_report(reports, RPT_ERROR, "Control Point not in FEnvelopeModifier");
+ return;
+ }
+
+ if (env->totvert > 1) {
+ /* allocate a new smaller array */
+ fedn = MEM_callocN(sizeof(FCM_EnvelopeData) * (env->totvert - 1), "FCM_EnvelopeData");
+
+ memcpy(fedn, env->data, sizeof(FCM_EnvelopeData) * (index));
+ memcpy(fedn + index, env->data + (index + 1), sizeof(FCM_EnvelopeData) * ((env->totvert - index) - 1));
+
+ /* free old array, and set the new */
+ MEM_freeN(env->data);
+ env->data = fedn;
+ env->totvert--;
+ }
+ else {
+ /* just free array, since the only vert was deleted */
+ if (env->data) {
+ MEM_freeN(env->data);
+ env->data = NULL;
+ }
+ env->totvert = 0;
+ }
+ RNA_POINTER_INVALIDATE(point);
+}
#else
static void rna_def_fmodifier_generator(BlenderRNA *brna)
@@ -770,6 +845,35 @@
/* - selection flags (not implemented in UI yet though) */
}
+static void rna_def_fmodifier_envelope_control_points(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ RNA_def_property_srna(cprop, "FModifierEnvelopeControlPoints");
+ srna = RNA_def_struct(brna, "FModifierEnvelopeControlPoints", NULL);
+ RNA_def_struct_sdna(srna, "FModifier");
+
+ RNA_def_struct_ui_text(srna, "Control Points", "Control points defining the shape of the envelope");
+
+ func = RNA_def_function(srna, "add", "rna_FModifierEnvelope_points_add");
+ RNA_def_function_ui_description(func, "Add a control point to a FModifierEnvelope");
+ parm = RNA_def_float(func, "frame", 0.0f, -FLT_MAX, FLT_MAX, "",
+ "Frame to add this control-point", -FLT_MAX, FLT_MAX);
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ parm = RNA_def_pointer(func, "point", "FModifierEnvelopeControlPoint", "", "Newly created control-point");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "remove", "rna_FModifierEnvelope_points_remove");
+ RNA_def_function_ui_description(func, "Remove a control-point from an FModifierEnvelope");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "point", "FModifierEnvelopeControlPoint", "", "Control-point to remove");
+ RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
+}
+
+
static void rna_def_fmodifier_envelope(BlenderRNA *brna)
{
StructRNA *srna;
@@ -784,6 +888,7 @@
RNA_def_property_collection_sdna(prop, NULL, "data", "totvert");
RNA_def_property_struct_type(prop, "FModifierEnvelopeControlPoint");
RNA_def_property_ui_text(prop, "Control Points", "Control points defining the shape of the envelope");
+ rna_def_fmodifier_envelope_control_points(brna, prop);
/* Range Settings */
prop = RNA_def_property(srna, "reference_value", PROP_FLOAT, PROP_NONE);
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
0d/12/9de5fbb02f1a076665563f471ab3
Event Timeline
Log In to Comment