From 56b67d41aa7addd1aa1757e9870bc1e8ea4ad295 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Tue, 6 Apr 2010 04:25:48 +0000 Subject: [PATCH] Bugfix #21916: Baking NLA strips doesn't group transforms - Added an optional string arg to struct.keyframe_insert() and struct.keyframe_delete() for the name of the group to add the keyframes to (for newly created F-Curves), instead of doing this as post process. - Added error prints to the RNA function for setting an F-Curve's group. The old way of setting the groups afterwards couldn't be used anymore, since there was no way to find the action the F-Curve belonged to. This is necessary if the F-Curve list is to be kept in a valid state, since adding to any random group that may not be in the same Action does not work well. There were other issues with the list being iterated over changing while it was still being iterated over too... TODO: Find a way to allow the iterator there to still work ok? --- release/scripts/op/nla.py | 25 ++++---------------- source/blender/makesrna/intern/rna_fcurve.c | 2 ++ source/blender/python/intern/bpy_rna.c | 26 +++++++++++++-------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/release/scripts/op/nla.py b/release/scripts/op/nla.py index db8c0be053a..b362798a91d 100644 --- a/release/scripts/op/nla.py +++ b/release/scripts/op/nla.py @@ -110,33 +110,18 @@ def bake(frame_start, frame_end, step=1, only_selected=False): #pbone.rotation_quaternion = matrix.to_quat() pbone.matrix_local = [f for v in matrix for f in v] - pbone.keyframe_insert("location", -1, f) + pbone.keyframe_insert("location", -1, f, "Location") rotation_mode = pbone.rotation_mode if rotation_mode == 'QUATERNION': - pbone.keyframe_insert("rotation_quaternion", -1, f) + pbone.keyframe_insert("rotation_quaternion", -1, f, "Rotation") elif rotation_mode == 'AXIS_ANGLE': - pbone.keyframe_insert("rotation_axis_angle", -1, f) + pbone.keyframe_insert("rotation_axis_angle", -1, f, "Rotation") else: # euler, XYZ, ZXY etc - pbone.keyframe_insert("rotation_euler", -1, f) + pbone.keyframe_insert("rotation_euler", -1, f, "Rotation") - pbone.keyframe_insert("scale", -1, f) - - # assign groups, could become a more generic function - agrp_loc = action.groups.add("Location") - agrp_rot = action.groups.add("Rotation") - agrp_sca = action.groups.add("Scale") - - for fcu in action.fcurves: - path = fcu.data_path.rsplit(".", 1)[-1] - - if path.startswith("loc"): - fcu.group = agrp_loc - if path.startswith("rot"): - fcu.group = agrp_rot - if path.startswith("sca"): - fcu.group = agrp_sca + pbone.keyframe_insert("scale", -1, f, "Scale") return action diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index b67eebadac8..7946e73af0f 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -337,6 +337,7 @@ static void rna_FCurve_group_set(PointerRNA *ptr, PointerRNA value) /* already belongs to group? */ if (fcu->grp == value.data) { /* nothing to do */ + printf("ERROR: F-Curve already belongs to the group\n"); return; } @@ -345,6 +346,7 @@ static void rna_FCurve_group_set(PointerRNA *ptr, PointerRNA value) */ if (act == NULL) { /* can't change the grouping of F-Curve when it doesn't belong to an action */ + printf("ERROR: cannot assign F-Curve to group, since F-Curve is not attached to any ID\n"); return; } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index c39860eef7a..7d2351d013d 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1664,17 +1664,17 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self) /* internal use for insert and delete */ int pyrna_struct_keyframe_parse(PointerRNA *ptr, PyObject *args, char *error_prefix, - char **path_full, int *index, float *cfra) /* return values */ + char **group_name, char **path_full, int *index, float *cfra) /* return values */ { char *path; PropertyRNA *prop; int array_len; - if (!PyArg_ParseTuple(args, "s|if", &path, index, cfra)) { - PyErr_Format(PyExc_TypeError, "%.200s expected a string and optionally an int and float arguments", error_prefix); + if (!PyArg_ParseTuple(args, "s|ifs", &path, index, cfra, group_name)) { + PyErr_Format(PyExc_TypeError, "%.200s expected a string and optionally an int, float, and string arguments", error_prefix); return -1; } - + if (ptr->data==NULL) { PyErr_Format(PyExc_TypeError, "%.200s this struct has no data, can't be animated", error_prefix); return -1; @@ -1721,20 +1721,23 @@ static char pyrna_struct_keyframe_insert_doc[] = " :arg index: array index of the property to key. Defaults to -1 which will key all indicies or a single channel if the property is not an array.\n" " :type index: int\n" " :arg frame: The frame on which the keyframe is inserted, defaulting to the current frame.\n" -" :type frame: float"; +" :type frame: float\n" +" :arg group: The name of the group the F-Curve should be added to if it doesn't exist yet.\n" +" :type group: str\n"; static PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args) { PyObject *result; /* args, pyrna_struct_keyframe_parse handles these */ char *path_full= NULL; + char *group_name= NULL; int index= -1; float cfra= FLT_MAX; - if(pyrna_struct_keyframe_parse(&self->ptr, args, "bpy_struct.keyframe_insert():", &path_full, &index, &cfra) == -1) + if(pyrna_struct_keyframe_parse(&self->ptr, args, "bpy_struct.keyframe_insert():", &group_name, &path_full, &index, &cfra) == -1) return NULL; - result= PyBool_FromLong(insert_keyframe((ID *)self->ptr.id.data, NULL, NULL, path_full, index, cfra, 0)); + result= PyBool_FromLong(insert_keyframe((ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0)); MEM_freeN(path_full); return result; @@ -1750,20 +1753,23 @@ static char pyrna_struct_keyframe_delete_doc[] = " :arg index: array index of the property to remove a key. Defaults to -1 removing all indicies or a single channel if the property is not an array.\n" " :type index: int\n" " :arg frame: The frame on which the keyframe is deleted, defaulting to the current frame.\n" -" :type frame: float"; +" :type frame: float" +" :arg group: The name of the group the F-Curve should be added to if it doesn't exist yet.\n" +" :type group: str\n";; static PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args) { PyObject *result; /* args, pyrna_struct_keyframe_parse handles these */ char *path_full= NULL; + char *group_name= NULL; int index= -1; float cfra= FLT_MAX; - if(pyrna_struct_keyframe_parse(&self->ptr, args, "bpy_struct.keyframe_delete():", &path_full, &index, &cfra) == -1) + if(pyrna_struct_keyframe_parse(&self->ptr, args, "bpy_struct.keyframe_delete():", &group_name, &path_full, &index, &cfra) == -1) return NULL; - result= PyBool_FromLong(delete_keyframe((ID *)self->ptr.id.data, NULL, NULL, path_full, index, cfra, 0)); + result= PyBool_FromLong(delete_keyframe((ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0)); MEM_freeN(path_full); return result;