Bugfix [#25707] / Todo Item: "Local Space" for Object constraining
authorJoshua Leung <aligorith@gmail.com>
Wed, 26 Jan 2011 23:33:08 +0000 (23:33 +0000)
committerJoshua Leung <aligorith@gmail.com>
Wed, 26 Jan 2011 23:33:08 +0000 (23:33 +0000)
For Constraints, there's now a working "Local" Space for Objects
without parents. This is defined as relative to the object's rotated
set of axes which results from rotation that gets set via "rotation"
transform properties.

I'm not sure whether this different behaviour between parented and
unparented objects will be too confusing (and thus require separate
settings + a round of version patching), so I'll wait until we get
proper testing from experienced riggers first.

source/blender/blenkernel/intern/constraint.c
source/blender/makesrna/intern/rna_constraint.c

index c497132fa9995c848c0eb3c023f9ab72fac33c89..c61f3ba368379f877995b31d09bf1902da3d463c 100644 (file)
@@ -372,7 +372,7 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4
        else {
                /* objects */
                if (from==CONSTRAINT_SPACE_WORLD && to==CONSTRAINT_SPACE_LOCAL) {
-                       /* check if object has a parent - otherwise this won't work */
+                       /* check if object has a parent */
                        if (ob->parent) {
                                /* 'subtract' parent's effects from owner */
                                mul_m4_m4m4(diff_mat, ob->parentinv, ob->parent->obmat);
@@ -380,6 +380,18 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4
                                copy_m4_m4(tempmat, mat);
                                mul_m4_m4m4(mat, tempmat, imat);
                        }
+                       else {
+                               /* Local space in this case will have to be defined as local to the owner's 
+                                * transform-property-rotated axes. So subtract this rotation component.
+                                */
+                               object_to_mat4(ob, diff_mat);
+                               normalize_m4(diff_mat);
+                               zero_v3(diff_mat[3]);
+                               
+                               invert_m4_m4(imat, diff_mat);
+                               copy_m4_m4(tempmat, mat);
+                               mul_m4_m4m4(mat, tempmat, imat);
+                       }
                }
                else if (from==CONSTRAINT_SPACE_LOCAL && to==CONSTRAINT_SPACE_WORLD) {
                        /* check that object has a parent - otherwise this won't work */
@@ -389,6 +401,17 @@ void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4
                                mul_m4_m4m4(diff_mat, ob->parentinv, ob->parent->obmat);
                                mul_m4_m4m4(mat, tempmat, diff_mat);
                        }
+                       else {
+                               /* Local space in this case will have to be defined as local to the owner's 
+                                * transform-property-rotated axes. So add back this rotation component.
+                                */
+                               object_to_mat4(ob, diff_mat);
+                               normalize_m4(diff_mat);
+                               zero_v3(diff_mat[3]);
+                               
+                               copy_m4_m4(tempmat, mat);
+                               mul_m4_m4m4(mat, tempmat, diff_mat);
+                       }
                }
        }
 }
index 112526cec469576bc8cc0281bc4c3d148c936249..692ebb59240f0d64e5e6d2881d3b84e86319e9d1 100644 (file)
@@ -79,7 +79,7 @@ EnumPropertyItem space_pchan_items[] = {
 
 EnumPropertyItem space_object_items[] = {
        {0, "WORLD", 0, "World Space", ""},
-       {1, "LOCAL", 0, "Local (Without Parent) Space", ""},
+       {1, "LOCAL", 0, "Local Space", ""},
        {0, NULL, 0, NULL, NULL}};
 
 EnumPropertyItem constraint_ik_type_items[] ={