Bugfix [#28435] Key Visual transform and Parenting not working
authorJoshua Leung <aligorith@gmail.com>
Fri, 2 Sep 2011 12:26:57 +0000 (12:26 +0000)
committerJoshua Leung <aligorith@gmail.com>
Fri, 2 Sep 2011 12:26:57 +0000 (12:26 +0000)
After reviewing this code, it seems that this case can work after all.
However, several things needed to be tweaked:
1) Removed check which stopped parented objects from getting the
visual keying coordinates determined. This actually wasn't doing
anything, given that this case would never occur as...
2) Tweaked the visualkey_can_use() function to also consider parenting
as a cause for visual-keying to be necessary.

source/blender/editors/animation/keyframing.c

index 4e87409b7fd01d8aeced8b8086ac363004191686..53c9fc4d82c7807db1a2b67a168474c466d6cb53 100644 (file)
@@ -530,6 +530,7 @@ static short visualkey_can_use (PointerRNA *ptr, PropertyRNA *prop)
 {
        bConstraint *con= NULL;
        short searchtype= VISUALKEY_NONE;
+       short has_parent = FALSE;
        char *identifier= NULL;
        
        /* validate data */
@@ -548,6 +549,7 @@ static short visualkey_can_use (PointerRNA *ptr, PropertyRNA *prop)
                
                con= ob->constraints.first;
                identifier= (char *)RNA_property_identifier(prop);
+               has_parent= (ob->parent != NULL);
        }
        else if (ptr->type == &RNA_PoseBone) {
                /* Pose Channel */
@@ -555,10 +557,11 @@ static short visualkey_can_use (PointerRNA *ptr, PropertyRNA *prop)
                
                con= pchan->constraints.first;
                identifier= (char *)RNA_property_identifier(prop);
+               has_parent= (pchan->parent != NULL);
        }
        
        /* check if any data to search using */
-       if (ELEM(NULL, con, identifier))
+       if (ELEM(NULL, con, identifier) && (has_parent == FALSE))
                return 0;
                
        /* location or rotation identifiers only... */
@@ -573,7 +576,12 @@ static short visualkey_can_use (PointerRNA *ptr, PropertyRNA *prop)
        
        
        /* only search if a searchtype and initial constraint are available */
-       if (searchtype && con) {
+       if (searchtype) {
+               /* parent is always matching */
+               if (has_parent)
+                       return 1;
+               
+               /* constraints */
                for (; con; con= con->next) {
                        /* only consider constraint if it is not disabled, and has influence */
                        if (con->flag & CONSTRAINT_DISABLE) continue;
@@ -645,39 +653,34 @@ static float visualkey_get_value (PointerRNA *ptr, PropertyRNA *prop, int array_
        if (ptr->type == &RNA_Object) {
                Object *ob= (Object *)ptr->data;
                
-               /* parented objects are not supported, as the effects of the parent
-                * are included in the matrix, which kindof beats the point
-                */
-               if (ob->parent == NULL) {
-                       /* only Location or Rotation keyframes are supported now */
-                       if (strstr(identifier, "location")) {
-                               return ob->obmat[3][array_index];
-                       }
-                       else if (strstr(identifier, "rotation_euler")) {
-                               float eul[3];
-                               
-                               mat4_to_eulO(eul, ob->rotmode, ob->obmat);
-                               return eul[array_index];
-                       }
-                       else if (strstr(identifier, "rotation_quaternion")) {
-                               float trimat[3][3], quat[4];
-                               
-                               copy_m3_m4(trimat, ob->obmat);
-                               mat3_to_quat_is_ok(quat, trimat);
-                               
-                               return quat[array_index];
-                       }
-                       else if (strstr(identifier, "rotation_axis_angle")) {
-                               float axis[3], angle;
-                               
-                               mat4_to_axis_angle(axis, &angle, ob->obmat);
-                               
-                               /* w = 0, x,y,z = 1,2,3 */
-                               if (array_index == 0)
-                                       return angle;
-                               else
-                                       return axis[array_index - 1];
-                       }
+               /* only Location or Rotation keyframes are supported now */
+               if (strstr(identifier, "location")) {
+                       return ob->obmat[3][array_index];
+               }
+               else if (strstr(identifier, "rotation_euler")) {
+                       float eul[3];
+                       
+                       mat4_to_eulO(eul, ob->rotmode, ob->obmat);
+                       return eul[array_index];
+               }
+               else if (strstr(identifier, "rotation_quaternion")) {
+                       float trimat[3][3], quat[4];
+                       
+                       copy_m3_m4(trimat, ob->obmat);
+                       mat3_to_quat_is_ok(quat, trimat);
+                       
+                       return quat[array_index];
+               }
+               else if (strstr(identifier, "rotation_axis_angle")) {
+                       float axis[3], angle;
+                       
+                       mat4_to_axis_angle(axis, &angle, ob->obmat);
+                       
+                       /* w = 0, x,y,z = 1,2,3 */
+                       if (array_index == 0)
+                               return angle;
+                       else
+                               return axis[array_index - 1];
                }
        }
        else if (ptr->type == &RNA_PoseBone) {