Constraints: remove special meaning of Local Space for parentless Objects.
authorAlexander Gavrilov <angavrilov@gmail.com>
Fri, 18 Oct 2019 16:54:18 +0000 (19:54 +0300)
committerAlexander Gavrilov <angavrilov@gmail.com>
Wed, 6 Nov 2019 12:36:05 +0000 (15:36 +0300)
In 2011 special handling was introduced, apparently for no other
reason than to address a complaint in T25707 that World and Local
space are equivalent for objects without parent. This causes issues
and confusion, as mentioned in rB599c8a2c8e4.

This special meaning of Local Space is not documented in the manual,
and is not known to experienced riggers, so removing it should not
be a problem.

Differential Revision: https://developer.blender.org/D6095

source/blender/blenkernel/BKE_constraint.h
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/fcurve.c
source/blender/makesrna/intern/rna_object_api.c

index 8fe3bd77a2606a6ccecec082ff112b3b5ebc7f42..73bd36844ac8295e8cc5cc15cb8c5755f04ec770 100644 (file)
@@ -191,12 +191,8 @@ struct bConstraintOb *BKE_constraints_make_evalob(struct Depsgraph *depsgraph,
                                                   short datatype);
 void BKE_constraints_clear_evalob(struct bConstraintOb *cob);
 
-void BKE_constraint_mat_convertspace(struct Object *ob,
-                                     struct bPoseChannel *pchan,
-                                     float mat[4][4],
-                                     short from,
-                                     short to,
-                                     const bool keep_scale);
+void BKE_constraint_mat_convertspace(
+    struct Object *ob, struct bPoseChannel *pchan, float mat[4][4], short from, short to);
 
 void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph,
                                       struct Scene *scene,
index d59849695ff75ecfe98d97b618c8a4eabfaf0273..edfd60a1c6fb98b0110f631d803ac460fff2b48e 100644 (file)
@@ -255,7 +255,7 @@ void BKE_constraints_clear_evalob(bConstraintOb *cob)
  * For now, this is only implemented for Objects and PoseChannels.
  */
 void BKE_constraint_mat_convertspace(
-    Object *ob, bPoseChannel *pchan, float mat[4][4], short from, short to, const bool keep_scale)
+    Object *ob, bPoseChannel *pchan, float mat[4][4], short from, short to)
 {
   float diff_mat[4][4];
   float imat[4][4];
@@ -282,7 +282,7 @@ void BKE_constraint_mat_convertspace(
         /* use pose-space as stepping stone for other spaces... */
         if (ELEM(to, CONSTRAINT_SPACE_LOCAL, CONSTRAINT_SPACE_PARLOCAL)) {
           /* call self with slightly different values */
-          BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to, keep_scale);
+          BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
         }
         break;
       }
@@ -318,7 +318,7 @@ void BKE_constraint_mat_convertspace(
         /* use pose-space as stepping stone for other spaces */
         if (ELEM(to, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL)) {
           /* call self with slightly different values */
-          BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to, keep_scale);
+          BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
         }
         break;
       }
@@ -332,7 +332,7 @@ void BKE_constraint_mat_convertspace(
         /* use pose-space as stepping stone for other spaces */
         if (ELEM(to, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL)) {
           /* call self with slightly different values */
-          BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to, keep_scale);
+          BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
         }
         break;
       }
@@ -348,27 +348,6 @@ void BKE_constraint_mat_convertspace(
         invert_m4_m4_safe(imat, diff_mat);
         mul_m4_m4m4(mat, imat, mat);
       }
-      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.
-         */
-        /* XXX This is actually an ugly hack, local space of a parent-less object *is* the same as
-         *     global space!
-         *     Think what we want actually here is some kind of 'Final Space', i.e
-         *     . once transformations are applied - users are often confused about this too,
-         *     this is not consistent with bones
-         *     local space either... Meh :|
-         *     --mont29
-         */
-        BKE_object_to_mat4(ob, diff_mat);
-        if (!keep_scale) {
-          normalize_m4(diff_mat);
-        }
-        zero_v3(diff_mat[3]);
-
-        invert_m4_m4_safe(imat, diff_mat);
-        mul_m4_m4m4(mat, imat, mat);
-      }
     }
     else if (from == CONSTRAINT_SPACE_LOCAL && to == CONSTRAINT_SPACE_WORLD) {
       /* check that object has a parent - otherwise this won't work */
@@ -377,19 +356,6 @@ void BKE_constraint_mat_convertspace(
         mul_m4_m4m4(diff_mat, ob->parent->obmat, ob->parentinv);
         mul_m4_m4m4(mat, diff_mat, 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.
-         */
-        /* XXX See comment above for world->local case... */
-        BKE_object_to_mat4(ob, diff_mat);
-        if (!keep_scale) {
-          normalize_m4(diff_mat);
-        }
-        zero_v3(diff_mat[3]);
-
-        mul_m4_m4m4(mat, diff_mat, mat);
-      }
     }
   }
 }
@@ -575,7 +541,7 @@ static void constraint_target_to_mat4(Object *ob,
   /* Case OBJECT */
   if (substring[0] == '\0') {
     copy_m4_m4(mat, ob->obmat);
-    BKE_constraint_mat_convertspace(ob, NULL, mat, from, to, false);
+    BKE_constraint_mat_convertspace(ob, NULL, mat, from, to);
   }
   /*  Case VERTEXGROUP */
   /* Current method just takes the average location of all the points in the
@@ -588,11 +554,11 @@ static void constraint_target_to_mat4(Object *ob,
    */
   else if (ob->type == OB_MESH) {
     contarget_get_mesh_mat(ob, substring, mat);
-    BKE_constraint_mat_convertspace(ob, NULL, mat, from, to, false);
+    BKE_constraint_mat_convertspace(ob, NULL, mat, from, to);
   }
   else if (ob->type == OB_LATTICE) {
     contarget_get_lattice_mat(ob, substring, mat);
-    BKE_constraint_mat_convertspace(ob, NULL, mat, from, to, false);
+    BKE_constraint_mat_convertspace(ob, NULL, mat, from, to);
   }
   /* Case BONE */
   else {
@@ -656,7 +622,7 @@ static void constraint_target_to_mat4(Object *ob,
     }
 
     /* convert matrix space as required */
-    BKE_constraint_mat_convertspace(ob, pchan, mat, from, to, false);
+    BKE_constraint_mat_convertspace(ob, pchan, mat, from, to);
   }
 }
 
@@ -4095,12 +4061,9 @@ static void shrinkwrap_get_tarmat(struct Depsgraph *UNUSED(depsgraph),
           }
 
           /* Transform normal into requested space */
-          /* Note that in this specific case, we need to keep scaling in non-parented 'local2world'
-           * object case, because SpaceTransform also takes it into account when handling normals.
-           * See T42447. */
           unit_m4(mat);
           BKE_constraint_mat_convertspace(
-              cob->ob, cob->pchan, mat, CONSTRAINT_SPACE_LOCAL, scon->projAxisSpace, true);
+              cob->ob, cob->pchan, mat, CONSTRAINT_SPACE_LOCAL, scon->projAxisSpace);
           invert_m4(mat);
           mul_mat3_m4_v3(mat, no);
 
@@ -5834,7 +5797,7 @@ void BKE_constraints_solve(struct Depsgraph *depsgraph,
 
     /* move owner matrix into right space */
     BKE_constraint_mat_convertspace(
-        cob->ob, cob->pchan, cob->matrix, CONSTRAINT_SPACE_WORLD, con->ownspace, false);
+        cob->ob, cob->pchan, cob->matrix, CONSTRAINT_SPACE_WORLD, con->ownspace);
 
     /* prepare targets for constraint solving */
     BKE_constraint_targets_for_solving_get(depsgraph, con, cob, &targets, ctime);
@@ -5853,7 +5816,7 @@ void BKE_constraints_solve(struct Depsgraph *depsgraph,
     /* move owner back into worldspace for next constraint/other business */
     if ((con->flag & CONSTRAINT_SPACEONCE) == 0) {
       BKE_constraint_mat_convertspace(
-          cob->ob, cob->pchan, cob->matrix, con->ownspace, CONSTRAINT_SPACE_WORLD, false);
+          cob->ob, cob->pchan, cob->matrix, con->ownspace, CONSTRAINT_SPACE_WORLD);
     }
 
     /* Interpolate the enforcement, to blend result of constraint into final owner transform
index b596eeb9e35c3b2b9d71958d9954482ff6fc7df9..0f4845a32c0be2cdf78434ffd1320fb6475a1b4f 100644 (file)
@@ -1560,7 +1560,7 @@ static float dvar_eval_locDiff(ChannelDriver *driver, DriverVar *dvar)
           /* extract transform just like how the constraints do it! */
           copy_m4_m4(mat, pchan->pose_mat);
           BKE_constraint_mat_convertspace(
-              ob, pchan, mat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL, false);
+              ob, pchan, mat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL);
 
           /* ... and from that, we get our transform */
           copy_v3_v3(tmp_loc, mat[3]);
@@ -1586,7 +1586,7 @@ static float dvar_eval_locDiff(ChannelDriver *driver, DriverVar *dvar)
           /* extract transform just like how the constraints do it! */
           copy_m4_m4(mat, ob->obmat);
           BKE_constraint_mat_convertspace(
-              ob, NULL, mat, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, false);
+              ob, NULL, mat, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL);
 
           /* ... and from that, we get our transform */
           copy_v3_v3(tmp_loc, mat[3]);
@@ -1663,7 +1663,7 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
         /* just like how the constraints do it! */
         copy_m4_m4(mat, pchan->pose_mat);
         BKE_constraint_mat_convertspace(
-            ob, pchan, mat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL, false);
+            ob, pchan, mat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL);
       }
       else {
         /* specially calculate local matrix, since chan_mat is not valid
@@ -1691,7 +1691,7 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
         /* just like how the constraints do it! */
         copy_m4_m4(mat, ob->obmat);
         BKE_constraint_mat_convertspace(
-            ob, NULL, mat, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, false);
+            ob, NULL, mat, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL);
       }
       else {
         /* transforms to matrix */
index babf388bfc76a9a34ae1546d5dfa54c3c243df54..81f653e73bef367b7014b723eb8752db7eb0e260 100644 (file)
@@ -323,7 +323,7 @@ static void rna_Object_mat_convert_space(Object *ob,
     }
   }
 
-  BKE_constraint_mat_convertspace(ob, pchan, (float(*)[4])mat_ret, from, to, false);
+  BKE_constraint_mat_convertspace(ob, pchan, (float(*)[4])mat_ret, from, to);
 }
 
 static void rna_Object_calc_matrix_camera(Object *ob,