Armature drawing: custom shape scale options
authorCampbell Barton <ideasman42@gmail.com>
Mon, 21 Sep 2015 13:49:58 +0000 (23:49 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 21 Sep 2015 13:57:08 +0000 (23:57 +1000)
- Custom scale:
  Avoids having multiple custom-shapes at different sizes.
- Option not to use bones length:
  So changes in edit-mode don't resize the custom-shape.

release/scripts/startup/bl_ui/properties_data_bone.py
source/blender/blenkernel/intern/action.c
source/blender/blenkernel/intern/armature.c
source/blender/blenloader/intern/versioning_270.c
source/blender/editors/space_view3d/drawarmature.c
source/blender/makesdna/DNA_action_types.h
source/blender/makesrna/intern/rna_pose.c

index a14e34580c55d13b003b842c8694205b8856afac..2c7f18b3dfe88218080973dc1a8aa17ce108ac05 100644 (file)
@@ -229,6 +229,8 @@ class BONE_PT_display(BoneButtonsPanel, Panel):
                 col.label(text="Custom Shape:")
                 col.prop(pchan, "custom_shape", text="")
                 if pchan.custom_shape:
+                    col.prop(pchan, "use_custom_shape_bone_size", text="Bone Size")
+                    col.prop(pchan, "custom_shape_scale", text="Scale")
                     col.prop_search(pchan, "custom_shape_transform", ob.pose, "bones", text="At")
 
 
index 5b1a6ea7a51eacd3e855c94caf295a0076c20723..b77ae45e94d7ad41e484422bf44103d58936981c 100644 (file)
@@ -485,6 +485,9 @@ bPoseChannel *BKE_pose_channel_verify(bPose *pose, const char *name)
        chan = MEM_callocN(sizeof(bPoseChannel), "verifyPoseChannel");
        
        BLI_strncpy(chan->name, name, sizeof(chan->name));
+
+       chan->custom_scale = 1.0f;
+
        /* init vars to prevent math errors */
        unit_qt(chan->quat);
        unit_axis_angle(chan->rotAxis, &chan->rotAngle);
index 29f2ad0d5122e4b2d6f96e178640b43077874346..6afe7f1abe906d862652536e1307871b5ca95b9e 100644 (file)
@@ -2229,7 +2229,7 @@ bool BKE_pose_minmax(Object *ob, float r_min[3], float r_max[3], bool use_hidden
                                                      BKE_object_boundbox_get(pchan->custom) : NULL;
                                if (bb_custom) {
                                        float mat[4][4], smat[4][4];
-                                       scale_m4_fl(smat, pchan->bone->length);
+                                       scale_m4_fl(smat, PCHAN_CUSTOM_DRAW_SIZE(pchan));
                                        mul_m4_series(mat, ob->obmat, pchan_tx->pose_mat, smat);
                                        BKE_boundbox_minmax(bb_custom, mat, r_min, r_max);
                                }
index 5518b1513f4bfca4bd3fc46246af658d2730b510..1f4aa3c9f3cebbb76936b3ebd27175dfa772aab0 100644 (file)
@@ -853,4 +853,19 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                }
 #undef BRUSH_TORUS
        }
+
+       if (!MAIN_VERSION_ATLEAST(main, 276, 2)) {
+               if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale")) {
+                       Object *ob;
+
+                       for (ob = main->object.first; ob; ob = ob->id.next) {
+                               if (ob->pose) {
+                                       bPoseChannel *pchan;
+                                       for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+                                               pchan->custom_scale = 1.0f;
+                                       }
+                               }
+                       }
+               }
+       }
 }
index 2579972cf0ff62667dd323f989d4ba1d92537134..f7698b0e9f3c4997fb019e01b451f2fac97d3aba 100644 (file)
@@ -1778,7 +1778,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                                        }
 
                                                        draw_custom_bone(scene, v3d, rv3d, pchan->custom,
-                                                                        OB_SOLID, arm->flag, flag, index, bone->length);
+                                                                        OB_SOLID, arm->flag, flag, index, PCHAN_CUSTOM_DRAW_SIZE(pchan));
                                                }
                                        }
                                        else {
@@ -1869,7 +1869,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
                                                                flag |= BONE_DRAW_ACTIVE;
                                                        
                                                        draw_custom_bone(scene, v3d, rv3d, pchan->custom,
-                                                                        OB_WIRE, arm->flag, flag, index, bone->length);
+                                                                        OB_WIRE, arm->flag, flag, index, PCHAN_CUSTOM_DRAW_SIZE(pchan));
                                                        
                                                        glPopMatrix();
                                                }
index b8688e5e12a151ac6fbd257d0f7b535196692997..d574694c70dfd73d7f8c6e4271544b1379fa57b0 100644 (file)
@@ -198,7 +198,8 @@ typedef struct bPoseChannel {
        short agrp_index;               /* index of action-group this bone belongs to (0 = default/no group) */
        char constflag;                 /* for quick detecting which constraints affect this channel */
        char selectflag;                /* copy of bone flag, so you can work with library armatures, not for runtime use */
-       char pad0[6];
+       char drawflag;
+       char pad0[5];
 
        struct Bone         *bone;      /* set on read file or rebuild pose */
        struct bPoseChannel *parent;    /* set on read file or rebuild pose */
@@ -212,6 +213,9 @@ typedef struct bPoseChannel {
        struct bPoseChannel *custom_tx; /* odd feature, display with another bones transform.
                                         * needed in rare cases for advanced rigs,
                                         * since the alternative is highly complicated - campbell */
+       float custom_scale;
+
+       char pad1[4];
 
        /* transforms - written in by actions or transform */
        float loc[3];
@@ -306,6 +310,14 @@ typedef enum ePchan_IkFlag {
        BONE_IK_NO_ZDOF_TEMP = (1 << 12)
 } ePchan_IkFlag;
 
+/* PoseChannel->drawflag */
+typedef enum ePchan_DrawFlag {
+       PCHAN_DRAW_NO_CUSTOM_BONE_SIZE = (1 << 0),
+} ePchan_DrawFlag;
+
+#define PCHAN_CUSTOM_DRAW_SIZE(pchan) \
+       (pchan)->custom_scale * (((pchan)->drawflag & PCHAN_DRAW_NO_CUSTOM_BONE_SIZE) ? 1.0f : (pchan)->bone->length)
+
 /* PoseChannel->rotmode and Object->rotmode */
 typedef enum eRotationModes {
        /* quaternion rotations (default, and for older Blender versions) */
index e65023132c9b31855a81f1cdc09d3128ca1e076a..27ff0a63e75a86375b16e7ce8fb7b0fe03216b11 100644 (file)
@@ -1062,6 +1062,17 @@ static void rna_def_pose_channel(BlenderRNA *brna)
        RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
        RNA_def_property_update(prop, NC_OBJECT | ND_POSE, "rna_Pose_update");
        
+       prop = RNA_def_property(srna, "custom_shape_scale", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "custom_scale");
+       RNA_def_property_range(prop, 0.0f, 1000.0f);
+       RNA_def_property_ui_text(prop, "Custom Shape Scale", "Adjust the size of the custom shape");
+       RNA_def_property_update(prop, NC_OBJECT | ND_POSE, "rna_Pose_update");
+
+       prop = RNA_def_property(srna, "use_custom_shape_bone_size", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "drawflag", PCHAN_DRAW_NO_CUSTOM_BONE_SIZE);
+       RNA_def_property_ui_text(prop, "Use Bone Size", "Scale the custom object by the bone length");
+       RNA_def_property_update(prop, NC_OBJECT | ND_POSE, "rna_Pose_update");
+
        prop = RNA_def_property(srna, "custom_shape_transform", PROP_POINTER, PROP_NONE);
        RNA_def_property_pointer_sdna(prop, NULL, "custom_tx");
        RNA_def_property_struct_type(prop, "PoseBone");