[Bf-blender-cvs] [74d5a93b2bf] master: Armature: Add Display Axis Offset

Scott Wilson noreply at git.blender.org
Tue Mar 30 11:40:40 CEST 2021


Commit: 74d5a93b2bf7806993d9baa24fd35228e52c4970
Author: Scott Wilson
Date:   Tue Mar 30 11:16:45 2021 +0200
Branches: master
https://developer.blender.org/rB74d5a93b2bf7806993d9baa24fd35228e52c4970

Armature: Add Display Axis Offset

Display the bone axes at the head (root) of the bone by default, instead
of the tail (tip), and add a slider so that it's possible to adjust this
position.

Versioning code is in place to ensure existing files behave the same
(axes shown at tail), whereas new Armatures will be using the new
default (axes shown at head).

Reviewed By: #animation_rigging, #user_interface, Severin, Sybren

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

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

M	release/scripts/startup/bl_ui/properties_data_armature.py
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/draw/engines/overlay/overlay_armature.c
M	source/blender/makesdna/DNA_armature_types.h
M	source/blender/makesrna/intern/rna_armature.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_armature.py b/release/scripts/startup/bl_ui/properties_data_armature.py
index 4cdcab45926..87572fcd438 100644
--- a/release/scripts/startup/bl_ui/properties_data_armature.py
+++ b/release/scripts/startup/bl_ui/properties_data_armature.py
@@ -86,12 +86,19 @@ class DATA_PT_display(ArmatureButtonsPanel, Panel):
 
         col = layout.column(heading="Show")
         col.prop(arm, "show_names", text="Names")
-        col.prop(arm, "show_axes", text="Axes")
         col.prop(arm, "show_bone_custom_shapes", text="Shapes")
         col.prop(arm, "show_group_colors", text="Group Colors")
+
         if ob:
             col.prop(ob, "show_in_front", text="In Front")
 
+        col = layout.column(align=False, heading="Axes")
+        row = col.row(align=True)
+        row.prop(arm, "show_axes", text="")
+        sub = row.row(align=True)
+        sub.active = arm.show_axes
+        sub.prop(arm, "axes_position", text="Position")
+
 
 class DATA_MT_bone_group_context_menu(Menu):
     bl_label = "Bone Group Specials"
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index aae5a2ec190..2449e35055e 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -27,6 +27,7 @@
 #include "BLI_utildefines.h"
 
 #include "DNA_anim_types.h"
+#include "DNA_armature_types.h"
 #include "DNA_brush_types.h"
 #include "DNA_cachefile_types.h"
 #include "DNA_collection_types.h"
@@ -1948,5 +1949,12 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
    */
   {
     /* Keep this block, even when empty. */
+
+    if (!DNA_struct_elem_find(fd->filesdna, "bArmature", "float", "axes_position")) {
+      /* Convert the axes draw position to its old default (tip of bone). */
+      LISTBASE_FOREACH (struct bArmature *, arm, &bmain->armatures) {
+        arm->axes_position = 1.0;
+      }
+    }
   }
 }
diff --git a/source/blender/draw/engines/overlay/overlay_armature.c b/source/blender/draw/engines/overlay/overlay_armature.c
index 7042d095b56..54224071d23 100644
--- a/source/blender/draw/engines/overlay/overlay_armature.c
+++ b/source/blender/draw/engines/overlay/overlay_armature.c
@@ -1293,11 +1293,15 @@ static void draw_axes(ArmatureDrawContext *ctx,
     float length = pchan->bone->length;
     copy_m4_m4(axis_mat, pchan->custom_tx ? pchan->custom_tx->pose_mat : pchan->pose_mat);
     rescale_m4(axis_mat, (float[3]){length, length, length});
+    translate_m4(axis_mat, 0.0, arm->axes_position - 1.0, 0.0);
 
     drw_shgroup_bone_axes(ctx, axis_mat, final_col);
   }
   else {
-    drw_shgroup_bone_axes(ctx, BONE_VAR(eBone, pchan, disp_mat), final_col);
+    float disp_mat[4][4];
+    copy_m4_m4(disp_mat, BONE_VAR(eBone, pchan, disp_mat));
+    translate_m4(disp_mat, 0.0, arm->axes_position - 1.0, 0.0);
+    drw_shgroup_bone_axes(ctx, disp_mat, final_col);
   }
 }
 
diff --git a/source/blender/makesdna/DNA_armature_types.h b/source/blender/makesdna/DNA_armature_types.h
index 411fde13bb2..85780bc33c5 100644
--- a/source/blender/makesdna/DNA_armature_types.h
+++ b/source/blender/makesdna/DNA_armature_types.h
@@ -134,7 +134,7 @@ typedef struct bArmature {
 
   /** ID data is older than edit-mode data (TODO: move to edit-mode struct). */
   char needs_flush_to_id;
-  char _pad0[7];
+  char _pad0[3];
 
   int flag;
   int drawtype;
@@ -146,6 +146,9 @@ typedef struct bArmature {
   unsigned int layer_used;
   /** For buttons to work, both variables in this order together. */
   unsigned int layer, layer_protected;
+
+  /** Relative position of the axes on the bone, from head (0.0f) to tail (1.0f). */
+  float axes_position;
 } bArmature;
 
 /* armature->flag */
diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c
index 554f04ca23c..c54621372ba 100644
--- a/source/blender/makesrna/intern/rna_armature.c
+++ b/source/blender/makesrna/intern/rna_armature.c
@@ -1537,6 +1537,16 @@ static void rna_def_armature(BlenderRNA *brna)
   RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
   RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
 
+  prop = RNA_def_property(srna, "axes_position", PROP_FLOAT, PROP_FACTOR);
+  RNA_def_property_float_sdna(prop, NULL, "axes_position");
+  RNA_def_property_range(prop, 0.0, 1.0);
+  RNA_def_property_ui_range(prop, 0.0, 1.0, 10, 1);
+  RNA_def_property_ui_text(prop,
+                           "Axes Position",
+                           "The position for the axes on the bone. Increasing the value moves it "
+                           "closer to the tip; decreasing moves it closer to the root");
+  RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
+
   prop = RNA_def_property(srna, "show_names", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "flag", ARM_DRAWNAMES);
   RNA_def_property_ui_text(prop, "Display Names", "Display bone names");



More information about the Bf-blender-cvs mailing list