From 0e94d910489e2bd4a23573c315fee26b740af3a4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 28 Apr 2017 22:30:21 +1000 Subject: Draw Manager: pose-mode custom bone display --- source/blender/draw/intern/draw_armature.c | 102 +++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 28 deletions(-) (limited to 'source/blender/draw/intern/draw_armature.c') diff --git a/source/blender/draw/intern/draw_armature.c b/source/blender/draw/intern/draw_armature.c index 64568d92efc..9a4c996837f 100644 --- a/source/blender/draw/intern/draw_armature.c +++ b/source/blender/draw/intern/draw_armature.c @@ -107,6 +107,28 @@ static void DRW_shgroup_bone_octahedral_wire(const float (*bone_mat)[4], const f DRW_shgroup_call_dynamic_add(g_data.bone_octahedral_wire, bone_mat, color); } +/* Custom (geometry) */ + +static void DRW_shgroup_bone_custom_solid(const float (*bone_mat)[4], const float color[4], Object *custom) +{ + /* grr, not re-using instances! */ + struct Batch *geom = DRW_cache_object_surface_get(custom); + if (geom) { + DRWShadingGroup *shgrp_geom_solid = shgroup_instance_objspace_solid(g_data.bone_solid, geom, g_data.ob->obmat); + DRW_shgroup_call_dynamic_add(shgrp_geom_solid, bone_mat, color); + } +} + +static void DRW_shgroup_bone_custom_wire(const float (*bone_mat)[4], const float color[4], Object *custom) +{ + /* grr, not re-using instances! */ + struct Batch *geom = DRW_cache_object_wire_get(custom); + if (geom) { + DRWShadingGroup *shgrp_geom_wire = shgroup_instance_objspace_wire(g_data.bone_wire, geom, g_data.ob->obmat); + DRW_shgroup_call_dynamic_add(shgrp_geom_wire, bone_mat, color); + } +} + /* Head and tail sphere */ static void DRW_shgroup_bone_point_solid(const float (*bone_mat)[4], const float color[4]) { @@ -289,7 +311,7 @@ static const float *get_bone_wire_color(const EditBone *eBone, const bPoseChanne /** \name Helper Utils * \{ */ -static void draw_bone_update_disp_matrix(EditBone *eBone, bPoseChannel *pchan, int drawtype) +static void draw_bone_update_disp_matrix_default(EditBone *eBone, bPoseChannel *pchan) { float s[4][4], ebmat[4][4]; float length; @@ -316,27 +338,30 @@ static void draw_bone_update_disp_matrix(EditBone *eBone, bPoseChannel *pchan, i disp_tail_mat = eBone->disp_tail_mat; } - if (pchan && pchan->custom) { - /* TODO */ - } - else if (drawtype == ARM_ENVELOPE) { - /* TODO */ - } - else if (drawtype == ARM_LINE) { - /* TODO */ - } - else if (drawtype == ARM_WIRE) { - /* TODO */ - } - else if (drawtype == ARM_B_BONE) { - /* TODO */ - } - else { - scale_m4_fl(s, length); - mul_m4_m4m4(disp_mat, bone_mat, s); - copy_m4_m4(disp_tail_mat, disp_mat); - translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f); - } + scale_m4_fl(s, length); + mul_m4_m4m4(disp_mat, bone_mat, s); + copy_m4_m4(disp_tail_mat, disp_mat); + translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f); +} + +static void draw_bone_update_disp_matrix_custom(bPoseChannel *pchan) +{ + float s[4][4]; + float length; + float (*bone_mat)[4]; + float (*disp_mat)[4]; + float (*disp_tail_mat)[4]; + + /* See TODO above */ + length = PCHAN_CUSTOM_DRAW_SIZE(pchan); + bone_mat = pchan->pose_mat; + disp_mat = pchan->disp_mat; + disp_tail_mat = pchan->disp_tail_mat; + + scale_m4_fl(s, length); + mul_m4_m4m4(disp_mat, bone_mat, s); + copy_m4_m4(disp_tail_mat, disp_mat); + translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f); } static void draw_axes(EditBone *eBone, bPoseChannel *pchan) @@ -414,10 +439,23 @@ static void draw_points( * \{ */ static void draw_bone_custom_shape( - EditBone *UNUSED(eBone), bPoseChannel *UNUSED(pchan), bArmature *UNUSED(arm), - const int UNUSED(select_id)) + EditBone *eBone, bPoseChannel *pchan, bArmature *arm, + const int select_id) { - /* work in progress -- fclem */ + const float *col_solid = get_bone_solid_color(eBone, pchan, arm); + const float *col_wire = get_bone_wire_color(eBone, pchan, arm); + const float (*disp_mat)[4] = pchan->custom_tx ? pchan->custom_tx->disp_mat : pchan->disp_mat; + + if (select_id != -1) { + DRW_select_load_id(select_id | BONESEL_BONE); + } + + DRW_shgroup_bone_custom_solid(disp_mat, col_solid, pchan->custom); + DRW_shgroup_bone_custom_wire(disp_mat, col_wire, pchan->custom); + + if (select_id != -1) { + DRW_select_load_id(-1); + } } static void draw_bone_envelope( @@ -493,21 +531,24 @@ static void draw_armature_edit(Object *ob) if ((eBone->flag & BONE_HIDDEN_A) == 0) { const int select_id = is_select ? index : (unsigned int)-1; - draw_bone_update_disp_matrix(eBone, NULL, arm->drawtype); - if (arm->drawtype == ARM_ENVELOPE) { + draw_bone_update_disp_matrix_default(eBone, NULL); draw_bone_envelope(eBone, NULL, arm, select_id); } else if (arm->drawtype == ARM_LINE) { + draw_bone_update_disp_matrix_default(eBone, NULL); draw_bone_line(eBone, NULL, arm, select_id); } else if (arm->drawtype == ARM_WIRE) { + draw_bone_update_disp_matrix_default(eBone, NULL); draw_bone_wire(eBone, NULL, arm, select_id); } else if (arm->drawtype == ARM_B_BONE) { + draw_bone_update_disp_matrix_default(eBone, NULL); draw_bone_box(eBone, NULL, arm, select_id); } else { + draw_bone_update_disp_matrix_default(eBone, NULL); draw_bone_octahedral(eBone, NULL, arm, select_id); } @@ -576,24 +617,29 @@ static void draw_armature_pose(Object *ob, const float const_color[4]) if (bone->layer & arm->layer) { const int select_id = is_pose_select ? index : (unsigned int)-1; - draw_bone_update_disp_matrix(NULL, pchan, arm->drawtype); if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) { + draw_bone_update_disp_matrix_custom(pchan); draw_bone_custom_shape(NULL, pchan, arm, select_id); } else if (arm->drawtype == ARM_ENVELOPE) { + draw_bone_update_disp_matrix_default(NULL, pchan); draw_bone_envelope(NULL, pchan, arm, select_id); } else if (arm->drawtype == ARM_LINE) { + draw_bone_update_disp_matrix_default(NULL, pchan); draw_bone_line(NULL, pchan, arm, select_id); } else if (arm->drawtype == ARM_WIRE) { + draw_bone_update_disp_matrix_default(NULL, pchan); draw_bone_wire(NULL, pchan, arm, select_id); } else if (arm->drawtype == ARM_B_BONE) { + draw_bone_update_disp_matrix_default(NULL, pchan); draw_bone_box(NULL, pchan, arm, select_id); } else { + draw_bone_update_disp_matrix_default(NULL, pchan); draw_bone_octahedral(NULL, pchan, arm, select_id); } -- cgit v1.2.3