[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28030] trunk/blender: Bugfix #21916: Baking NLA strips doesn't group transforms

Joshua Leung aligorith at gmail.com
Tue Apr 6 06:25:50 CEST 2010


Revision: 28030
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28030
Author:   aligorith
Date:     2010-04-06 06:25:48 +0200 (Tue, 06 Apr 2010)

Log Message:
-----------
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?

Modified Paths:
--------------
    trunk/blender/release/scripts/op/nla.py
    trunk/blender/source/blender/makesrna/intern/rna_fcurve.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/release/scripts/op/nla.py
===================================================================
--- trunk/blender/release/scripts/op/nla.py	2010-04-06 02:36:37 UTC (rev 28029)
+++ trunk/blender/release/scripts/op/nla.py	2010-04-06 04:25:48 UTC (rev 28030)
@@ -110,34 +110,19 @@
             #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)
+            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
 
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_fcurve.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_fcurve.c	2010-04-06 02:36:37 UTC (rev 28029)
+++ trunk/blender/source/blender/makesrna/intern/rna_fcurve.c	2010-04-06 04:25:48 UTC (rev 28030)
@@ -337,6 +337,7 @@
 	/* 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 @@
 	 */
 	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;
 	}	
 	

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2010-04-06 02:36:37 UTC (rev 28029)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2010-04-06 04:25:48 UTC (rev 28030)
@@ -1664,17 +1664,17 @@
 
 /* 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 @@
 "   :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 @@
 "   :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;





More information about the Bf-blender-cvs mailing list