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?
This commit is contained in:
2010-04-06 04:25:48 +00:00
parent 825c162167
commit 56b67d41aa
3 changed files with 23 additions and 30 deletions

View File

@@ -110,33 +110,18 @@ def bake(frame_start, frame_end, step=1, only_selected=False):
#pbone.rotation_quaternion = matrix.to_quat() #pbone.rotation_quaternion = matrix.to_quat()
pbone.matrix_local = [f for v in matrix for f in v] 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 rotation_mode = pbone.rotation_mode
if rotation_mode == 'QUATERNION': if rotation_mode == 'QUATERNION':
pbone.keyframe_insert("rotation_quaternion", -1, f) pbone.keyframe_insert("rotation_quaternion", -1, f, "Rotation")
elif rotation_mode == 'AXIS_ANGLE': 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 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) pbone.keyframe_insert("scale", -1, f, "Scale")
# 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
return action return action

View File

@@ -337,6 +337,7 @@ static void rna_FCurve_group_set(PointerRNA *ptr, PointerRNA value)
/* already belongs to group? */ /* already belongs to group? */
if (fcu->grp == value.data) { if (fcu->grp == value.data) {
/* nothing to do */ /* nothing to do */
printf("ERROR: F-Curve already belongs to the group\n");
return; return;
} }
@@ -345,6 +346,7 @@ static void rna_FCurve_group_set(PointerRNA *ptr, PointerRNA value)
*/ */
if (act == NULL) { if (act == NULL) {
/* can't change the grouping of F-Curve when it doesn't belong to an action */ /* 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; return;
} }

View File

@@ -1664,17 +1664,17 @@ static PyObject *pyrna_struct_values(BPy_PropertyRNA *self)
/* internal use for insert and delete */ /* internal use for insert and delete */
int pyrna_struct_keyframe_parse(PointerRNA *ptr, PyObject *args, char *error_prefix, 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; char *path;
PropertyRNA *prop; PropertyRNA *prop;
int array_len; int array_len;
if (!PyArg_ParseTuple(args, "s|if", &path, index, cfra)) { if (!PyArg_ParseTuple(args, "s|ifs", &path, index, cfra, group_name)) {
PyErr_Format(PyExc_TypeError, "%.200s expected a string and optionally an int and float arguments", error_prefix); PyErr_Format(PyExc_TypeError, "%.200s expected a string and optionally an int, float, and string arguments", error_prefix);
return -1; return -1;
} }
if (ptr->data==NULL) { if (ptr->data==NULL) {
PyErr_Format(PyExc_TypeError, "%.200s this struct has no data, can't be animated", error_prefix); PyErr_Format(PyExc_TypeError, "%.200s this struct has no data, can't be animated", error_prefix);
return -1; 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" " :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" " :type index: int\n"
" :arg frame: The frame on which the keyframe is inserted, defaulting to the current frame.\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) static PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args)
{ {
PyObject *result; PyObject *result;
/* args, pyrna_struct_keyframe_parse handles these */ /* args, pyrna_struct_keyframe_parse handles these */
char *path_full= NULL; char *path_full= NULL;
char *group_name= NULL;
int index= -1; int index= -1;
float cfra= FLT_MAX; 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; 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); MEM_freeN(path_full);
return result; 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" " :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" " :type index: int\n"
" :arg frame: The frame on which the keyframe is deleted, defaulting to the current frame.\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) static PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args)
{ {
PyObject *result; PyObject *result;
/* args, pyrna_struct_keyframe_parse handles these */ /* args, pyrna_struct_keyframe_parse handles these */
char *path_full= NULL; char *path_full= NULL;
char *group_name= NULL;
int index= -1; int index= -1;
float cfra= FLT_MAX; 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; 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); MEM_freeN(path_full);
return result; return result;