Armature drawing: custom shape scale options

- 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.
This commit is contained in:
Campbell Barton 2015-09-21 23:49:58 +10:00
parent 0dbde559cf
commit 84b074baed
Notes: blender-bot 2023-02-14 11:28:43 +01:00
Referenced by issue #46191, Make the use of bone length optional for custom shapes
7 changed files with 47 additions and 4 deletions

View 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")

View 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);

View 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);
}

View 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;
}
}
}
}
}
}

View 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();
}

View 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) */

View 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");