[Bf-blender-cvs] [84b074b] master: Armature drawing: custom shape scale options

Campbell Barton noreply at git.blender.org
Mon Sep 21 16:02:26 CEST 2015


Commit: 84b074baedd9d472ff2f52759b15f119de4f69c2
Author: Campbell Barton
Date:   Mon Sep 21 23:49:58 2015 +1000
Branches: master
https://developer.blender.org/rB84b074baedd9d472ff2f52759b15f119de4f69c2

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.

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

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

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

diff --git a/release/scripts/startup/bl_ui/properties_data_bone.py b/release/scripts/startup/bl_ui/properties_data_bone.py
index a14e345..2c7f18b 100644
--- a/release/scripts/startup/bl_ui/properties_data_bone.py
+++ b/release/scripts/startup/bl_ui/properties_data_bone.py
@@ -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")
 
 
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 5b1a6ea..b77ae45 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -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);
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 29f2ad0..6afe7f1 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -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);
 				}
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 5518b15..1f4aa3c 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -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;
+					}
+				}
+			}
+		}
+	}
 }
diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c
index 2579972..f7698b0 100644
--- a/source/blender/editors/space_view3d/drawarmature.c
+++ b/source/blender/editors/space_view3d/drawarmature.c
@@ -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();
 						}
diff --git a/source/blender/makesdna/DNA_action_types.h b/source/blender/makesdna/DNA_action_types.h
index b8688e5..d574694 100644
--- a/source/blender/makesdna/DNA_action_types.h
+++ b/source/blender/makesdna/DNA_action_types.h
@@ -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) */
diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c
index e650231..27ff0a6 100644
--- a/source/blender/makesrna/intern/rna_pose.c
+++ b/source/blender/makesrna/intern/rna_pose.c
@@ -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");




More information about the Bf-blender-cvs mailing list