[Bf-blender-cvs] [9cc5af64c65] master: Cleanup: Constraints, simplified ChildOf evaluation function

Sybren A. Stüvel noreply at git.blender.org
Tue Feb 25 18:16:46 CET 2020


Commit: 9cc5af64c65e146df95f33033a20992451967aa5
Author: Sybren A. Stüvel
Date:   Tue Feb 25 18:16:25 2020 +0100
Branches: master
https://developer.blender.org/rB9cc5af64c65e146df95f33033a20992451967aa5

Cleanup: Constraints, simplified ChildOf evaluation function

This un-indents the `childof_evaluate()` function by one level, making it
easier to add new functionality in an upcoming commit.

No functional changes.

===================================================================

M	source/blender/blenkernel/intern/constraint.c

===================================================================

diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index f8a4ae7ff28..8ba746e3493 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -855,95 +855,97 @@ static void childof_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar
   bConstraintTarget *ct = targets->first;
 
   /* only evaluate if there is a target */
-  if (VALID_CONS_TARGET(ct)) {
-    float parmat[4][4];
+  if (!VALID_CONS_TARGET(ct)) {
+    return;
+  }
 
-    /* simple matrix parenting */
-    if (data->flag == CHILDOF_ALL) {
+  float parmat[4][4];
 
-      /* multiply target (parent matrix) by offset (parent inverse) to get
-       * the effect of the parent that will be exerted on the owner
-       */
-      mul_m4_m4m4(parmat, ct->matrix, data->invmat);
+  /* simple matrix parenting */
+  if (data->flag == CHILDOF_ALL) {
 
-      /* now multiply the parent matrix by the owner matrix to get the
-       * the effect of this constraint (i.e. owner is 'parented' to parent)
-       */
-      mul_m4_m4m4(cob->matrix, parmat, cob->matrix);
-    }
-    else {
-      float invmat[4][4], tempmat[4][4];
-      float loc[3], eul[3], size[3];
-      float loco[3], eulo[3], sizo[3];
+    /* multiply target (parent matrix) by offset (parent inverse) to get
+     * the effect of the parent that will be exerted on the owner
+     */
+    mul_m4_m4m4(parmat, ct->matrix, data->invmat);
 
-      /* get offset (parent-inverse) matrix */
-      copy_m4_m4(invmat, data->invmat);
+    /* now multiply the parent matrix by the owner matrix to get the
+     * the effect of this constraint (i.e. owner is 'parented' to parent)
+     */
+    mul_m4_m4m4(cob->matrix, parmat, cob->matrix);
+  }
+  else {
+    float invmat[4][4], tempmat[4][4];
+    float loc[3], eul[3], size[3];
+    float loco[3], eulo[3], sizo[3];
 
-      /* extract components of both matrices */
-      copy_v3_v3(loc, ct->matrix[3]);
-      mat4_to_eulO(eul, ct->rotOrder, ct->matrix);
-      mat4_to_size(size, ct->matrix);
+    /* get offset (parent-inverse) matrix */
+    copy_m4_m4(invmat, data->invmat);
 
-      copy_v3_v3(loco, invmat[3]);
-      mat4_to_eulO(eulo, cob->rotOrder, invmat);
-      mat4_to_size(sizo, invmat);
+    /* extract components of both matrices */
+    copy_v3_v3(loc, ct->matrix[3]);
+    mat4_to_eulO(eul, ct->rotOrder, ct->matrix);
+    mat4_to_size(size, ct->matrix);
 
-      /* disable channels not enabled */
-      if (!(data->flag & CHILDOF_LOCX)) {
-        loc[0] = loco[0] = 0.0f;
-      }
-      if (!(data->flag & CHILDOF_LOCY)) {
-        loc[1] = loco[1] = 0.0f;
-      }
-      if (!(data->flag & CHILDOF_LOCZ)) {
-        loc[2] = loco[2] = 0.0f;
-      }
-      if (!(data->flag & CHILDOF_ROTX)) {
-        eul[0] = eulo[0] = 0.0f;
-      }
-      if (!(data->flag & CHILDOF_ROTY)) {
-        eul[1] = eulo[1] = 0.0f;
-      }
-      if (!(data->flag & CHILDOF_ROTZ)) {
-        eul[2] = eulo[2] = 0.0f;
-      }
-      if (!(data->flag & CHILDOF_SIZEX)) {
-        size[0] = sizo[0] = 1.0f;
-      }
-      if (!(data->flag & CHILDOF_SIZEY)) {
-        size[1] = sizo[1] = 1.0f;
-      }
-      if (!(data->flag & CHILDOF_SIZEZ)) {
-        size[2] = sizo[2] = 1.0f;
-      }
+    copy_v3_v3(loco, invmat[3]);
+    mat4_to_eulO(eulo, cob->rotOrder, invmat);
+    mat4_to_size(sizo, invmat);
 
-      /* make new target mat and offset mat */
-      loc_eulO_size_to_mat4(ct->matrix, loc, eul, size, ct->rotOrder);
-      loc_eulO_size_to_mat4(invmat, loco, eulo, sizo, cob->rotOrder);
+    /* disable channels not enabled */
+    if (!(data->flag & CHILDOF_LOCX)) {
+      loc[0] = loco[0] = 0.0f;
+    }
+    if (!(data->flag & CHILDOF_LOCY)) {
+      loc[1] = loco[1] = 0.0f;
+    }
+    if (!(data->flag & CHILDOF_LOCZ)) {
+      loc[2] = loco[2] = 0.0f;
+    }
+    if (!(data->flag & CHILDOF_ROTX)) {
+      eul[0] = eulo[0] = 0.0f;
+    }
+    if (!(data->flag & CHILDOF_ROTY)) {
+      eul[1] = eulo[1] = 0.0f;
+    }
+    if (!(data->flag & CHILDOF_ROTZ)) {
+      eul[2] = eulo[2] = 0.0f;
+    }
+    if (!(data->flag & CHILDOF_SIZEX)) {
+      size[0] = sizo[0] = 1.0f;
+    }
+    if (!(data->flag & CHILDOF_SIZEY)) {
+      size[1] = sizo[1] = 1.0f;
+    }
+    if (!(data->flag & CHILDOF_SIZEZ)) {
+      size[2] = sizo[2] = 1.0f;
+    }
 
-      /* multiply target (parent matrix) by offset (parent inverse) to get
-       * the effect of the parent that will be exerted on the owner
-       */
-      mul_m4_m4m4(parmat, ct->matrix, invmat);
+    /* make new target mat and offset mat */
+    loc_eulO_size_to_mat4(ct->matrix, loc, eul, size, ct->rotOrder);
+    loc_eulO_size_to_mat4(invmat, loco, eulo, sizo, cob->rotOrder);
 
-      /* now multiply the parent matrix by the owner matrix to get the
-       * the effect of this constraint (i.e.  owner is 'parented' to parent)
-       */
-      copy_m4_m4(tempmat, cob->matrix);
-      mul_m4_m4m4(cob->matrix, parmat, tempmat);
-
-      /* without this, changes to scale and rotation can change location
-       * of a parentless bone or a disconnected bone. Even though its set
-       * to zero above. */
-      if (!(data->flag & CHILDOF_LOCX)) {
-        cob->matrix[3][0] = tempmat[3][0];
-      }
-      if (!(data->flag & CHILDOF_LOCY)) {
-        cob->matrix[3][1] = tempmat[3][1];
-      }
-      if (!(data->flag & CHILDOF_LOCZ)) {
-        cob->matrix[3][2] = tempmat[3][2];
-      }
+    /* multiply target (parent matrix) by offset (parent inverse) to get
+     * the effect of the parent that will be exerted on the owner
+     */
+    mul_m4_m4m4(parmat, ct->matrix, invmat);
+
+    /* now multiply the parent matrix by the owner matrix to get the
+     * the effect of this constraint (i.e.  owner is 'parented' to parent)
+     */
+    copy_m4_m4(tempmat, cob->matrix);
+    mul_m4_m4m4(cob->matrix, parmat, tempmat);
+
+    /* without this, changes to scale and rotation can change location
+     * of a parentless bone or a disconnected bone. Even though its set
+     * to zero above. */
+    if (!(data->flag & CHILDOF_LOCX)) {
+      cob->matrix[3][0] = tempmat[3][0];
+    }
+    if (!(data->flag & CHILDOF_LOCY)) {
+      cob->matrix[3][1] = tempmat[3][1];
+    }
+    if (!(data->flag & CHILDOF_LOCZ)) {
+      cob->matrix[3][2] = tempmat[3][2];
     }
   }
 }



More information about the Bf-blender-cvs mailing list