[Bf-blender-cvs] [883706395ee] master: Drivers: support accessing Quaternion rotation channels.

Alexander Gavrilov noreply at git.blender.org
Sat Aug 31 19:54:17 CEST 2019


Commit: 883706395ee37188900e3ac2c00070c9a43246d2
Author: Alexander Gavrilov
Date:   Sat Aug 31 20:27:19 2019 +0300
Branches: master
https://developer.blender.org/rB883706395ee37188900e3ac2c00070c9a43246d2

Drivers: support accessing Quaternion rotation channels.

After adding the Euler order option, it's an easy addition to
the enum. The list of channels had of course to be expanded too.

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

M	source/blender/blenkernel/intern/fcurve.c
M	source/blender/makesdna/DNA_anim_types.h
M	source/blender/makesrna/intern/rna_fcurve.c

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

diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index dec410c8192..ef53c926daa 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -1714,7 +1714,10 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
      * of scale over all three axes unless the matrix includes shear. */
     return cbrtf(mat4_to_volume_scale(mat));
   }
-  else if (dtar->transChan >= DTAR_TRANSCHAN_SCALEX) {
+  else if (ELEM(dtar->transChan,
+                DTAR_TRANSCHAN_SCALEX,
+                DTAR_TRANSCHAN_SCALEY,
+                DTAR_TRANSCHAN_SCALEZ)) {
     /* Extract scale, and choose the right axis,
      * inline 'mat4_to_size'. */
     return len_v3(mat[dtar->transChan - DTAR_TRANSCHAN_SCALEX]);
@@ -1728,7 +1731,18 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
      *     b) [NOT USED] directly use the original values (no decomposition)
      *         - only an option for "transform space", if quality is really bad with a)
      */
-    float eul[3];
+    float quat[4];
+    float *const eul = quat + 1;
+    int channel;
+
+    if (dtar->transChan == DTAR_TRANSCHAN_ROTW) {
+      channel = 0;
+      quat[0] = 0.0f;
+    }
+    else {
+      channel = 1 + dtar->transChan - DTAR_TRANSCHAN_ROTX;
+      BLI_assert(channel < 4);
+    }
 
     if (dtar->rotation_mode == DTAR_ROTMODE_AUTO) {
       mat4_to_eulO(eul, rot_order, mat);
@@ -1741,12 +1755,15 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar)
              dtar->rotation_mode <= DTAR_ROTMODE_EULER_MAX) {
       mat4_to_eulO(eul, dtar->rotation_mode, mat);
     }
+    else if (dtar->rotation_mode == DTAR_ROTMODE_QUATERNION) {
+      mat4_to_quat(quat, mat);
+    }
     else {
       BLI_assert(false);
       zero_v3(eul);
     }
 
-    return eul[dtar->transChan - DTAR_TRANSCHAN_ROTX];
+    return quat[channel];
   }
   else {
     /* extract location and choose right axis */
diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h
index 8c25d470a36..be4850d6779 100644
--- a/source/blender/makesdna/DNA_anim_types.h
+++ b/source/blender/makesdna/DNA_anim_types.h
@@ -362,6 +362,7 @@ typedef enum eDriverTarget_TransformChannels {
   DTAR_TRANSCHAN_SCALEY,
   DTAR_TRANSCHAN_SCALEZ,
   DTAR_TRANSCHAN_SCALE_AVG,
+  DTAR_TRANSCHAN_ROTW,
 
   MAX_DTAR_TRANSCHAN_TYPES,
 } eDriverTarget_TransformChannels;
@@ -379,6 +380,8 @@ typedef enum eDriverTarget_RotationMode {
   DTAR_ROTMODE_EULER_ZXY,
   DTAR_ROTMODE_EULER_ZYX,
 
+  DTAR_ROTMODE_QUATERNION,
+
   DTAR_ROTMODE_EULER_MIN = DTAR_ROTMODE_EULER_XYZ,
   DTAR_ROTMODE_EULER_MAX = DTAR_ROTMODE_EULER_ZYX,
 } eDriverTarget_RotationMode;
diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c
index 6cb3a18605c..684c786b1b9 100644
--- a/source/blender/makesrna/intern/rna_fcurve.c
+++ b/source/blender/makesrna/intern/rna_fcurve.c
@@ -1674,6 +1674,7 @@ static void rna_def_drivertarget(BlenderRNA *brna)
       {DTAR_TRANSCHAN_ROTX, "ROT_X", 0, "X Rotation", ""},
       {DTAR_TRANSCHAN_ROTY, "ROT_Y", 0, "Y Rotation", ""},
       {DTAR_TRANSCHAN_ROTZ, "ROT_Z", 0, "Z Rotation", ""},
+      {DTAR_TRANSCHAN_ROTW, "ROT_W", 0, "W Rotation", ""},
       {DTAR_TRANSCHAN_SCALEX, "SCALE_X", 0, "X Scale", ""},
       {DTAR_TRANSCHAN_SCALEY, "SCALE_Y", 0, "Y Scale", ""},
       {DTAR_TRANSCHAN_SCALEZ, "SCALE_Z", 0, "Z Scale", ""},
@@ -1709,6 +1710,7 @@ static void rna_def_drivertarget(BlenderRNA *brna)
       {DTAR_ROTMODE_EULER_YZX, "YZX", 0, "YZX Euler", "Euler using the YZX rotation order"},
       {DTAR_ROTMODE_EULER_ZXY, "ZXY", 0, "ZXY Euler", "Euler using the ZXY rotation order"},
       {DTAR_ROTMODE_EULER_ZYX, "ZYX", 0, "ZYX Euler", "Euler using the ZYX rotation order"},
+      {DTAR_ROTMODE_QUATERNION, "QUATERNION", 0, "Quaternion", "Quaternion rotation"},
       {0, NULL, 0, NULL, NULL},
   };



More information about the Bf-blender-cvs mailing list