Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/overlay_armature.c
| Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
| #include "overlay_private.h" | #include "overlay_private.h" | ||||
| #define BONE_VAR(eBone, pchan, var) ((eBone) ? (eBone->var) : (pchan->var)) | #define BONE_VAR(eBone, pchan, var) ((eBone) ? (eBone->var) : (pchan->var)) | ||||
| #define BONE_FLAG(eBone, pchan) ((eBone) ? (eBone->flag) : (pchan->bone->flag)) | #define BONE_FLAG(eBone, pchan) ((eBone) ? (eBone->flag) : (pchan->bone->flag)) | ||||
| #define PT_DEFAULT_RAD 0.05f /* radius of the point batch. */ | #define PT_DEFAULT_RAD 0.05f /* radius of the point batch. */ | ||||
| #define DRAW_FLAG_LOCKED 1 | |||||
| typedef struct ArmatureDrawContext { | typedef struct ArmatureDrawContext { | ||||
| /* Current armature object */ | /* Current armature object */ | ||||
| Object *ob; | Object *ob; | ||||
| /* bArmature *arm; */ /* TODO */ | /* bArmature *arm; */ /* TODO */ | ||||
| union { | union { | ||||
| struct { | struct { | ||||
| DRWCallBuffer *outline; | DRWCallBuffer *outline; | ||||
| ▲ Show 20 Lines • Show All 903 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Drawing Color Helpers | /** \name Drawing Color Helpers | ||||
| * \{ */ | * \{ */ | ||||
| static void bone_locked_color_shade(float color[4]) | |||||
| { | |||||
| float tmp[3], locked_color[4]; | |||||
| UI_GetThemeColor4fv(TH_BONE_LOCKED_WEIGHT, locked_color); | |||||
| mul_v3_v3v3(tmp, color, locked_color); | |||||
| interp_v3_v3v3(tmp, tmp, locked_color, locked_color[3]); | |||||
| interp_v3_v3v3(color, color, tmp, locked_color[3]); | |||||
| } | |||||
| static const float *get_bone_solid_color(const ArmatureDrawContext *ctx, | static const float *get_bone_solid_color(const ArmatureDrawContext *ctx, | ||||
| const EditBone *UNUSED(eBone), | const EditBone *UNUSED(eBone), | ||||
| const bPoseChannel *pchan, | const bPoseChannel *pchan, | ||||
| const bArmature *arm, | const bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag) | const short constflag, | ||||
| const int drawflag) | |||||
| { | { | ||||
| if (ctx->const_color) { | if (ctx->const_color) { | ||||
| return ctx->color.bone_solid; | return ctx->color.bone_solid; | ||||
| } | } | ||||
| if (arm->flag & ARM_POSEMODE) { | if (arm->flag & ARM_POSEMODE) { | ||||
| static float disp_color[4]; | static float disp_color[4]; | ||||
| copy_v4_v4(disp_color, pchan->draw_data->solid_color); | copy_v4_v4(disp_color, pchan->draw_data->solid_color); | ||||
| set_pchan_color(ctx, PCHAN_COLOR_SOLID, boneflag, constflag, disp_color); | set_pchan_color(ctx, PCHAN_COLOR_SOLID, boneflag, constflag, disp_color); | ||||
| if (drawflag & DRAW_FLAG_LOCKED) { | |||||
| bone_locked_color_shade(disp_color); | |||||
| } | |||||
| return disp_color; | return disp_color; | ||||
| } | } | ||||
| return ctx->color.bone_solid; | return ctx->color.bone_solid; | ||||
| } | } | ||||
| static const float *get_bone_solid_with_consts_color(const ArmatureDrawContext *ctx, | static const float *get_bone_solid_with_consts_color(const ArmatureDrawContext *ctx, | ||||
| const EditBone *eBone, | const EditBone *eBone, | ||||
| const bPoseChannel *pchan, | const bPoseChannel *pchan, | ||||
| const bArmature *arm, | const bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag) | const short constflag, | ||||
| const int drawflag) | |||||
| { | { | ||||
| if (ctx->const_color) { | if (ctx->const_color) { | ||||
| return ctx->color.bone_solid; | return ctx->color.bone_solid; | ||||
| } | } | ||||
| const float *col = get_bone_solid_color(ctx, eBone, pchan, arm, boneflag, constflag); | const float *col = get_bone_solid_color(ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | ||||
| static float consts_color[4]; | static float consts_color[4]; | ||||
| if ((arm->flag & ARM_POSEMODE) && | if ((arm->flag & ARM_POSEMODE) && !(drawflag & DRAW_FLAG_LOCKED) && | ||||
| set_pchan_color(ctx, PCHAN_COLOR_CONSTS, boneflag, constflag, consts_color)) { | set_pchan_color(ctx, PCHAN_COLOR_CONSTS, boneflag, constflag, consts_color)) { | ||||
| interp_v3_v3v3(consts_color, col, consts_color, 0.5f); | interp_v3_v3v3(consts_color, col, consts_color, 0.5f); | ||||
| } | } | ||||
| else { | else { | ||||
| copy_v4_v4(consts_color, col); | copy_v4_v4(consts_color, col); | ||||
| } | } | ||||
| return consts_color; | return consts_color; | ||||
| } | } | ||||
| Show All 11 Lines | static float get_bone_wire_thickness(const ArmatureDrawContext *ctx, int boneflag) | ||||
| } | } | ||||
| } | } | ||||
| static const float *get_bone_wire_color(const ArmatureDrawContext *ctx, | static const float *get_bone_wire_color(const ArmatureDrawContext *ctx, | ||||
| const EditBone *eBone, | const EditBone *eBone, | ||||
| const bPoseChannel *pchan, | const bPoseChannel *pchan, | ||||
| const bArmature *arm, | const bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag) | const short constflag, | ||||
| const int drawflag) | |||||
| { | { | ||||
| static float disp_color[4]; | static float disp_color[4]; | ||||
| if (ctx->const_color) { | if (ctx->const_color) { | ||||
| copy_v3_v3(disp_color, ctx->const_color); | copy_v3_v3(disp_color, ctx->const_color); | ||||
| } | } | ||||
| else if (eBone) { | else if (eBone) { | ||||
| if (boneflag & BONE_SELECTED) { | if (boneflag & BONE_SELECTED) { | ||||
| Show All 11 Lines | else { | ||||
| else { | else { | ||||
| copy_v3_v3(disp_color, ctx->color.wire_edit); | copy_v3_v3(disp_color, ctx->color.wire_edit); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (arm->flag & ARM_POSEMODE) { | else if (arm->flag & ARM_POSEMODE) { | ||||
| copy_v4_v4(disp_color, pchan->draw_data->wire_color); | copy_v4_v4(disp_color, pchan->draw_data->wire_color); | ||||
| set_pchan_color(ctx, PCHAN_COLOR_NORMAL, boneflag, constflag, disp_color); | set_pchan_color(ctx, PCHAN_COLOR_NORMAL, boneflag, constflag, disp_color); | ||||
| if (drawflag & DRAW_FLAG_LOCKED) { | |||||
| bone_locked_color_shade(disp_color); | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| copy_v3_v3(disp_color, ctx->color.vertex); | copy_v3_v3(disp_color, ctx->color.vertex); | ||||
| } | } | ||||
| disp_color[3] = get_bone_wire_thickness(ctx, boneflag); | disp_color[3] = get_bone_wire_thickness(ctx, boneflag); | ||||
| return disp_color; | return disp_color; | ||||
| Show All 9 Lines | static void bone_hint_color_shade(float hint_color[4], const float color[4]) | ||||
| hint_color[3] = 1.0f; | hint_color[3] = 1.0f; | ||||
| } | } | ||||
| static const float *get_bone_hint_color(const ArmatureDrawContext *ctx, | static const float *get_bone_hint_color(const ArmatureDrawContext *ctx, | ||||
| const EditBone *eBone, | const EditBone *eBone, | ||||
| const bPoseChannel *pchan, | const bPoseChannel *pchan, | ||||
| const bArmature *arm, | const bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag) | const short constflag, | ||||
| const int drawflag) | |||||
| { | { | ||||
| static float hint_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; | static float hint_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; | ||||
| if (ctx->const_color) { | if (ctx->const_color) { | ||||
| bone_hint_color_shade(hint_color, ctx->color.bone_solid); | bone_hint_color_shade(hint_color, ctx->color.bone_solid); | ||||
| } | } | ||||
| else { | else { | ||||
| const float *wire_color = get_bone_wire_color(ctx, eBone, pchan, arm, boneflag, constflag); | const float *wire_color = get_bone_wire_color( | ||||
| ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | |||||
| bone_hint_color_shade(hint_color, wire_color); | bone_hint_color_shade(hint_color, wire_color); | ||||
| } | } | ||||
| return hint_color; | return hint_color; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| ▲ Show 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void draw_points(ArmatureDrawContext *ctx, | static void draw_points(ArmatureDrawContext *ctx, | ||||
| const EditBone *eBone, | const EditBone *eBone, | ||||
| const bPoseChannel *pchan, | const bPoseChannel *pchan, | ||||
| const bArmature *arm, | const bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag, | const short constflag, | ||||
| const int drawflag, | |||||
| const int select_id) | const int select_id) | ||||
| { | { | ||||
| float col_solid_root[4], col_solid_tail[4], col_wire_root[4], col_wire_tail[4]; | float col_solid_root[4], col_solid_tail[4], col_wire_root[4], col_wire_tail[4]; | ||||
| float col_hint_root[4], col_hint_tail[4]; | float col_hint_root[4], col_hint_tail[4]; | ||||
| copy_v4_v4(col_solid_root, ctx->color.bone_solid); | copy_v4_v4(col_solid_root, ctx->color.bone_solid); | ||||
| copy_v4_v4(col_solid_tail, ctx->color.bone_solid); | copy_v4_v4(col_solid_tail, ctx->color.bone_solid); | ||||
| copy_v4_v4(col_wire_root, (ctx->const_color) ? ctx->const_color : ctx->color.vertex); | copy_v4_v4(col_wire_root, (ctx->const_color) ? ctx->const_color : ctx->color.vertex); | ||||
| Show All 9 Lines | if (eBone) { | ||||
| if (eBone->flag & BONE_ROOTSEL) { | if (eBone->flag & BONE_ROOTSEL) { | ||||
| copy_v3_v3(col_wire_root, ctx->color.vertex_select); | copy_v3_v3(col_wire_root, ctx->color.vertex_select); | ||||
| } | } | ||||
| if (eBone->flag & BONE_TIPSEL) { | if (eBone->flag & BONE_TIPSEL) { | ||||
| copy_v3_v3(col_wire_tail, ctx->color.vertex_select); | copy_v3_v3(col_wire_tail, ctx->color.vertex_select); | ||||
| } | } | ||||
| } | } | ||||
| else if (arm->flag & ARM_POSEMODE) { | else if (arm->flag & ARM_POSEMODE) { | ||||
| const float *solid_color = get_bone_solid_color(ctx, eBone, pchan, arm, boneflag, constflag); | const float *solid_color = get_bone_solid_color( | ||||
| const float *wire_color = get_bone_wire_color(ctx, eBone, pchan, arm, boneflag, constflag); | ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | ||||
| const float *wire_color = get_bone_wire_color( | |||||
| ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | |||||
| copy_v4_v4(col_wire_tail, wire_color); | copy_v4_v4(col_wire_tail, wire_color); | ||||
| copy_v4_v4(col_wire_root, wire_color); | copy_v4_v4(col_wire_root, wire_color); | ||||
| copy_v4_v4(col_solid_tail, solid_color); | copy_v4_v4(col_solid_tail, solid_color); | ||||
| copy_v4_v4(col_solid_root, solid_color); | copy_v4_v4(col_solid_root, solid_color); | ||||
| } | } | ||||
| bone_hint_color_shade(col_hint_root, (ctx->const_color) ? col_solid_root : col_wire_root); | bone_hint_color_shade(col_hint_root, (ctx->const_color) ? col_solid_root : col_wire_root); | ||||
| bone_hint_color_shade(col_hint_tail, (ctx->const_color) ? col_solid_tail : col_wire_tail); | bone_hint_color_shade(col_hint_tail, (ctx->const_color) ? col_solid_tail : col_wire_tail); | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
| * \{ */ | * \{ */ | ||||
| static void draw_bone_custom_shape(ArmatureDrawContext *ctx, | static void draw_bone_custom_shape(ArmatureDrawContext *ctx, | ||||
| EditBone *eBone, | EditBone *eBone, | ||||
| bPoseChannel *pchan, | bPoseChannel *pchan, | ||||
| bArmature *arm, | bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag, | const short constflag, | ||||
| const int drawflag, | |||||
| const int select_id) | const int select_id) | ||||
| { | { | ||||
| const float *col_solid = get_bone_solid_color(ctx, eBone, pchan, arm, boneflag, constflag); | const float *col_solid = get_bone_solid_color( | ||||
| const float *col_wire = get_bone_wire_color(ctx, eBone, pchan, arm, boneflag, constflag); | ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | ||||
| const float *col_hint = get_bone_hint_color(ctx, eBone, pchan, arm, boneflag, constflag); | const float *col_wire = get_bone_wire_color( | ||||
| ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | |||||
| const float *col_hint = get_bone_hint_color( | |||||
| ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | |||||
| const float(*disp_mat)[4] = pchan->disp_mat; | const float(*disp_mat)[4] = pchan->disp_mat; | ||||
| if (select_id != -1) { | if (select_id != -1) { | ||||
| DRW_select_load_id(select_id | BONESEL_BONE); | DRW_select_load_id(select_id | BONESEL_BONE); | ||||
| } | } | ||||
| if (pchan->custom->type == OB_EMPTY) { | if (pchan->custom->type == OB_EMPTY) { | ||||
| Object *ob = pchan->custom; | Object *ob = pchan->custom; | ||||
| if (ob->empty_drawtype != OB_EMPTY_IMAGE) { | if (ob->empty_drawtype != OB_EMPTY_IMAGE) { | ||||
| drw_shgroup_bone_custom_empty(ctx, disp_mat, col_wire, pchan->custom); | drw_shgroup_bone_custom_empty(ctx, disp_mat, col_wire, pchan->custom); | ||||
| } | } | ||||
| } | } | ||||
| if ((boneflag & BONE_DRAWWIRE) == 0) { | if ((boneflag & BONE_DRAWWIRE) == 0 && (drawflag & DRAW_FLAG_LOCKED) == 0) { | ||||
| drw_shgroup_bone_custom_solid(ctx, disp_mat, col_solid, col_hint, col_wire, pchan->custom); | drw_shgroup_bone_custom_solid(ctx, disp_mat, col_solid, col_hint, col_wire, pchan->custom); | ||||
| } | } | ||||
| else { | else { | ||||
| drw_shgroup_bone_custom_wire(ctx, disp_mat, col_wire, pchan->custom); | drw_shgroup_bone_custom_wire(ctx, disp_mat, col_wire, pchan->custom); | ||||
| } | } | ||||
| if (select_id != -1) { | if (select_id != -1) { | ||||
| DRW_select_load_id(-1); | DRW_select_load_id(-1); | ||||
| } | } | ||||
| } | } | ||||
| static void draw_bone_envelope(ArmatureDrawContext *ctx, | static void draw_bone_envelope(ArmatureDrawContext *ctx, | ||||
| EditBone *eBone, | EditBone *eBone, | ||||
| bPoseChannel *pchan, | bPoseChannel *pchan, | ||||
| bArmature *arm, | bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag, | const short constflag, | ||||
| const int drawflag, | |||||
| const int select_id) | const int select_id) | ||||
| { | { | ||||
| const float *col_solid = get_bone_solid_with_consts_color( | const float *col_solid = get_bone_solid_with_consts_color( | ||||
| ctx, eBone, pchan, arm, boneflag, constflag); | ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | ||||
| const float *col_wire = get_bone_wire_color(ctx, eBone, pchan, arm, boneflag, constflag); | const float *col_wire = get_bone_wire_color( | ||||
| const float *col_hint = get_bone_hint_color(ctx, eBone, pchan, arm, boneflag, constflag); | ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | ||||
| const float *col_hint = get_bone_hint_color( | |||||
| ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | |||||
| float *rad_head, *rad_tail, *distance; | float *rad_head, *rad_tail, *distance; | ||||
| if (eBone) { | if (eBone) { | ||||
| rad_tail = &eBone->rad_tail; | rad_tail = &eBone->rad_tail; | ||||
| distance = &eBone->dist; | distance = &eBone->dist; | ||||
| rad_head = (eBone->parent && (boneflag & BONE_CONNECTED)) ? &eBone->parent->rad_tail : | rad_head = (eBone->parent && (boneflag & BONE_CONNECTED)) ? &eBone->parent->rad_tail : | ||||
| &eBone->rad_head; | &eBone->rad_head; | ||||
| } | } | ||||
| Show All 16 Lines | static void draw_bone_envelope(ArmatureDrawContext *ctx, | ||||
| drw_shgroup_bone_envelope( | drw_shgroup_bone_envelope( | ||||
| ctx, BONE_VAR(eBone, pchan, disp_mat), col_solid, col_hint, col_wire, rad_head, rad_tail); | ctx, BONE_VAR(eBone, pchan, disp_mat), col_solid, col_hint, col_wire, rad_head, rad_tail); | ||||
| if (select_id != -1) { | if (select_id != -1) { | ||||
| DRW_select_load_id(-1); | DRW_select_load_id(-1); | ||||
| } | } | ||||
| draw_points(ctx, eBone, pchan, arm, boneflag, constflag, select_id); | draw_points(ctx, eBone, pchan, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| static void draw_bone_line(ArmatureDrawContext *ctx, | static void draw_bone_line(ArmatureDrawContext *ctx, | ||||
| EditBone *eBone, | EditBone *eBone, | ||||
| bPoseChannel *pchan, | bPoseChannel *pchan, | ||||
| bArmature *arm, | bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag, | const short constflag, | ||||
| const int drawflag, | |||||
| const int select_id) | const int select_id) | ||||
| { | { | ||||
| const float *col_bone = get_bone_solid_with_consts_color( | const float *col_bone = get_bone_solid_with_consts_color( | ||||
| ctx, eBone, pchan, arm, boneflag, constflag); | ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | ||||
| const float *col_wire = get_bone_wire_color(ctx, eBone, pchan, arm, boneflag, constflag); | const float *col_wire = get_bone_wire_color( | ||||
| ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | |||||
| const float no_display[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | const float no_display[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | ||||
| const float *col_head = no_display; | const float *col_head = no_display; | ||||
| const float *col_tail = col_bone; | const float *col_tail = col_bone; | ||||
| if (ctx->const_color != NULL) { | if (ctx->const_color != NULL) { | ||||
| col_wire = no_display; /* actually shrink the display. */ | col_wire = no_display; /* actually shrink the display. */ | ||||
| col_bone = col_head = col_tail = ctx->const_color; | col_bone = col_head = col_tail = ctx->const_color; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void draw_bone_wire(ArmatureDrawContext *ctx, | static void draw_bone_wire(ArmatureDrawContext *ctx, | ||||
| EditBone *eBone, | EditBone *eBone, | ||||
| bPoseChannel *pchan, | bPoseChannel *pchan, | ||||
| bArmature *arm, | bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag, | const short constflag, | ||||
| const int drawflag, | |||||
| const int select_id) | const int select_id) | ||||
| { | { | ||||
| const float *col_wire = get_bone_wire_color(ctx, eBone, pchan, arm, boneflag, constflag); | const float *col_wire = get_bone_wire_color( | ||||
| ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | |||||
| if (select_id != -1) { | if (select_id != -1) { | ||||
| DRW_select_load_id(select_id | BONESEL_BONE); | DRW_select_load_id(select_id | BONESEL_BONE); | ||||
| } | } | ||||
| if (pchan) { | if (pchan) { | ||||
| Mat4 *bbones_mat = (Mat4 *)pchan->draw_data->bbone_matrix; | Mat4 *bbones_mat = (Mat4 *)pchan->draw_data->bbone_matrix; | ||||
| BLI_assert(bbones_mat != NULL); | BLI_assert(bbones_mat != NULL); | ||||
| for (int i = pchan->bone->segments; i--; bbones_mat++) { | for (int i = pchan->bone->segments; i--; bbones_mat++) { | ||||
| drw_shgroup_bone_wire(ctx, bbones_mat->mat, col_wire); | drw_shgroup_bone_wire(ctx, bbones_mat->mat, col_wire); | ||||
| } | } | ||||
| } | } | ||||
| else if (eBone) { | else if (eBone) { | ||||
| for (int i = 0; i < eBone->segments; i++) { | for (int i = 0; i < eBone->segments; i++) { | ||||
| drw_shgroup_bone_wire(ctx, eBone->disp_bbone_mat[i], col_wire); | drw_shgroup_bone_wire(ctx, eBone->disp_bbone_mat[i], col_wire); | ||||
| } | } | ||||
| } | } | ||||
| if (select_id != -1) { | if (select_id != -1) { | ||||
| DRW_select_load_id(-1); | DRW_select_load_id(-1); | ||||
| } | } | ||||
| if (eBone) { | if (eBone) { | ||||
| draw_points(ctx, eBone, pchan, arm, boneflag, constflag, select_id); | draw_points(ctx, eBone, pchan, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| } | } | ||||
| static void draw_bone_box(ArmatureDrawContext *ctx, | static void draw_bone_box(ArmatureDrawContext *ctx, | ||||
| EditBone *eBone, | EditBone *eBone, | ||||
| bPoseChannel *pchan, | bPoseChannel *pchan, | ||||
| bArmature *arm, | bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag, | const short constflag, | ||||
| const int drawflag, | |||||
| const int select_id) | const int select_id) | ||||
| { | { | ||||
| const float *col_solid = get_bone_solid_with_consts_color( | const float *col_solid = get_bone_solid_with_consts_color( | ||||
| ctx, eBone, pchan, arm, boneflag, constflag); | ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | ||||
| const float *col_wire = get_bone_wire_color(ctx, eBone, pchan, arm, boneflag, constflag); | const float *col_wire = get_bone_wire_color( | ||||
| const float *col_hint = get_bone_hint_color(ctx, eBone, pchan, arm, boneflag, constflag); | ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | ||||
| const float *col_hint = get_bone_hint_color( | |||||
| ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | |||||
| if (select_id != -1) { | if (select_id != -1) { | ||||
| DRW_select_load_id(select_id | BONESEL_BONE); | DRW_select_load_id(select_id | BONESEL_BONE); | ||||
| } | } | ||||
| if (pchan) { | if (pchan) { | ||||
| Mat4 *bbones_mat = (Mat4 *)pchan->draw_data->bbone_matrix; | Mat4 *bbones_mat = (Mat4 *)pchan->draw_data->bbone_matrix; | ||||
| BLI_assert(bbones_mat != NULL); | BLI_assert(bbones_mat != NULL); | ||||
| for (int i = pchan->bone->segments; i--; bbones_mat++) { | for (int i = pchan->bone->segments; i--; bbones_mat++) { | ||||
| drw_shgroup_bone_box(ctx, bbones_mat->mat, col_solid, col_hint, col_wire); | drw_shgroup_bone_box(ctx, bbones_mat->mat, col_solid, col_hint, col_wire); | ||||
| } | } | ||||
| } | } | ||||
| else if (eBone) { | else if (eBone) { | ||||
| for (int i = 0; i < eBone->segments; i++) { | for (int i = 0; i < eBone->segments; i++) { | ||||
| drw_shgroup_bone_box(ctx, eBone->disp_bbone_mat[i], col_solid, col_hint, col_wire); | drw_shgroup_bone_box(ctx, eBone->disp_bbone_mat[i], col_solid, col_hint, col_wire); | ||||
| } | } | ||||
| } | } | ||||
| if (select_id != -1) { | if (select_id != -1) { | ||||
| DRW_select_load_id(-1); | DRW_select_load_id(-1); | ||||
| } | } | ||||
| if (eBone) { | if (eBone) { | ||||
| draw_points(ctx, eBone, pchan, arm, boneflag, constflag, select_id); | draw_points(ctx, eBone, pchan, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| } | } | ||||
| static void draw_bone_octahedral(ArmatureDrawContext *ctx, | static void draw_bone_octahedral(ArmatureDrawContext *ctx, | ||||
| EditBone *eBone, | EditBone *eBone, | ||||
| bPoseChannel *pchan, | bPoseChannel *pchan, | ||||
| bArmature *arm, | bArmature *arm, | ||||
| const int boneflag, | const int boneflag, | ||||
| const short constflag, | const short constflag, | ||||
| const int drawflag, | |||||
| const int select_id) | const int select_id) | ||||
| { | { | ||||
| const float *col_solid = get_bone_solid_with_consts_color( | const float *col_solid = get_bone_solid_with_consts_color( | ||||
| ctx, eBone, pchan, arm, boneflag, constflag); | ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | ||||
| const float *col_wire = get_bone_wire_color(ctx, eBone, pchan, arm, boneflag, constflag); | const float *col_wire = get_bone_wire_color( | ||||
| const float *col_hint = get_bone_hint_color(ctx, eBone, pchan, arm, boneflag, constflag); | ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | ||||
| const float *col_hint = get_bone_hint_color( | |||||
| ctx, eBone, pchan, arm, boneflag, constflag, drawflag); | |||||
| if (select_id != -1) { | if (select_id != -1) { | ||||
| DRW_select_load_id(select_id | BONESEL_BONE); | DRW_select_load_id(select_id | BONESEL_BONE); | ||||
| } | } | ||||
| drw_shgroup_bone_octahedral( | drw_shgroup_bone_octahedral( | ||||
| ctx, BONE_VAR(eBone, pchan, disp_mat), col_solid, col_hint, col_wire); | ctx, BONE_VAR(eBone, pchan, disp_mat), col_solid, col_hint, col_wire); | ||||
| if (select_id != -1) { | if (select_id != -1) { | ||||
| DRW_select_load_id(-1); | DRW_select_load_id(-1); | ||||
| } | } | ||||
| draw_points(ctx, eBone, pchan, arm, boneflag, constflag, select_id); | draw_points(ctx, eBone, pchan, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Draw Degrees of Freedom | /** \name Draw Degrees of Freedom | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Lines | static void draw_armature_edit(ArmatureDrawContext *ctx) | ||||
| edbo_compute_bbone_child(arm); | edbo_compute_bbone_child(arm); | ||||
| for (eBone = arm->edbo->first, index = ob_orig->runtime.select_id; eBone; | for (eBone = arm->edbo->first, index = ob_orig->runtime.select_id; eBone; | ||||
| eBone = eBone->next, index += 0x10000) { | eBone = eBone->next, index += 0x10000) { | ||||
| if (eBone->layer & arm->layer) { | if (eBone->layer & arm->layer) { | ||||
| if ((eBone->flag & BONE_HIDDEN_A) == 0) { | if ((eBone->flag & BONE_HIDDEN_A) == 0) { | ||||
| const int select_id = is_select ? index : (uint)-1; | const int select_id = is_select ? index : (uint)-1; | ||||
| const short constflag = 0; | const short constflag = 0; | ||||
| const int drawflag = 0; | |||||
| /* catch exception for bone with hidden parent */ | /* catch exception for bone with hidden parent */ | ||||
| int boneflag = eBone->flag; | int boneflag = eBone->flag; | ||||
| if ((eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) { | if ((eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) { | ||||
| boneflag &= ~BONE_CONNECTED; | boneflag &= ~BONE_CONNECTED; | ||||
| } | } | ||||
| /* set temporary flag for drawing bone as active, but only if selected */ | /* set temporary flag for drawing bone as active, but only if selected */ | ||||
| if (eBone == arm->act_edbone) { | if (eBone == arm->act_edbone) { | ||||
| boneflag |= BONE_DRAW_ACTIVE; | boneflag |= BONE_DRAW_ACTIVE; | ||||
| } | } | ||||
| draw_bone_relations(ctx, eBone, NULL, arm, boneflag, constflag); | draw_bone_relations(ctx, eBone, NULL, arm, boneflag, constflag); | ||||
| if (arm->drawtype == ARM_ENVELOPE) { | if (arm->drawtype == ARM_ENVELOPE) { | ||||
| draw_bone_update_disp_matrix_default(eBone, NULL); | draw_bone_update_disp_matrix_default(eBone, NULL); | ||||
| draw_bone_envelope(ctx, eBone, NULL, arm, boneflag, constflag, select_id); | draw_bone_envelope(ctx, eBone, NULL, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| else if (arm->drawtype == ARM_LINE) { | else if (arm->drawtype == ARM_LINE) { | ||||
| draw_bone_update_disp_matrix_default(eBone, NULL); | draw_bone_update_disp_matrix_default(eBone, NULL); | ||||
| draw_bone_line(ctx, eBone, NULL, arm, boneflag, constflag, select_id); | draw_bone_line(ctx, eBone, NULL, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| else if (arm->drawtype == ARM_WIRE) { | else if (arm->drawtype == ARM_WIRE) { | ||||
| draw_bone_update_disp_matrix_bbone(eBone, NULL); | draw_bone_update_disp_matrix_bbone(eBone, NULL); | ||||
| draw_bone_wire(ctx, eBone, NULL, arm, boneflag, constflag, select_id); | draw_bone_wire(ctx, eBone, NULL, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| else if (arm->drawtype == ARM_B_BONE) { | else if (arm->drawtype == ARM_B_BONE) { | ||||
| draw_bone_update_disp_matrix_bbone(eBone, NULL); | draw_bone_update_disp_matrix_bbone(eBone, NULL); | ||||
| draw_bone_box(ctx, eBone, NULL, arm, boneflag, constflag, select_id); | draw_bone_box(ctx, eBone, NULL, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| else { | else { | ||||
| draw_bone_update_disp_matrix_default(eBone, NULL); | draw_bone_update_disp_matrix_default(eBone, NULL); | ||||
| draw_bone_octahedral(ctx, eBone, NULL, arm, boneflag, constflag, select_id); | draw_bone_octahedral(ctx, eBone, NULL, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| if (show_text && (arm->flag & ARM_DRAWNAMES)) { | if (show_text && (arm->flag & ARM_DRAWNAMES)) { | ||||
| draw_bone_name(ctx, eBone, NULL, arm, boneflag); | draw_bone_name(ctx, eBone, NULL, arm, boneflag); | ||||
| } | } | ||||
| if (arm->flag & ARM_DRAWAXES) { | if (arm->flag & ARM_DRAWAXES) { | ||||
| draw_axes(ctx, eBone, NULL); | draw_axes(ctx, eBone, NULL); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void draw_armature_pose(ArmatureDrawContext *ctx) | static void draw_armature_pose(ArmatureDrawContext *ctx) | ||||
| { | { | ||||
| Object *ob = ctx->ob; | Object *ob = ctx->ob; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| const Scene *scene = draw_ctx->scene; | const Scene *scene = draw_ctx->scene; | ||||
| bArmature *arm = ob->data; | bArmature *arm = ob->data; | ||||
| bPoseChannel *pchan; | bPoseChannel *pchan; | ||||
| int index = -1; | int index = -1; | ||||
| const bool show_text = DRW_state_show_text(); | const bool show_text = DRW_state_show_text(); | ||||
| GSet *locked_bones = NULL; | |||||
| /* We can't safely draw non-updated pose, might contain NULL bone pointers... */ | /* We can't safely draw non-updated pose, might contain NULL bone pointers... */ | ||||
| if (ob->pose->flag & POSE_RECALC) { | if (ob->pose->flag & POSE_RECALC) { | ||||
| return; | return; | ||||
| } | } | ||||
| bool is_pose_select = false; | bool is_pose_select = false; | ||||
| /* Object can be edited in the scene. */ | /* Object can be edited in the scene. */ | ||||
| Show All 19 Lines | is_pose_select = | ||||
| DRW_state_is_select(); | DRW_state_is_select(); | ||||
| if (is_pose_select) { | if (is_pose_select) { | ||||
| const Object *ob_orig = DEG_get_original_object(ob); | const Object *ob_orig = DEG_get_original_object(ob); | ||||
| index = ob_orig->runtime.select_id; | index = ob_orig->runtime.select_id; | ||||
| } | } | ||||
| } | } | ||||
| /* In weight paint mode retrieve lock status. */ | |||||
| if ((draw_ctx->object_mode == OB_MODE_WEIGHT_PAINT) && (draw_ctx->object_pose == ob) && | |||||
| (draw_ctx->obact != NULL)) { | |||||
| const Object *obact_orig = DEG_get_original_object(draw_ctx->obact); | |||||
| LISTBASE_FOREACH (bDeformGroup *, dg, &obact_orig->defbase) { | |||||
| if (dg->flag & DG_LOCK_WEIGHT) { | |||||
| if (locked_bones == NULL) { | |||||
| locked_bones = BLI_gset_str_new(__func__); | |||||
| } | |||||
| BLI_gset_add(locked_bones, dg->name); | |||||
| } | |||||
| } | |||||
| } | |||||
| for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next, index += 0x10000) { | for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next, index += 0x10000) { | ||||
| Bone *bone = pchan->bone; | Bone *bone = pchan->bone; | ||||
| const bool bone_visible = (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0; | const bool bone_visible = (bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0; | ||||
| if (bone_visible) { | if (bone_visible) { | ||||
| if (bone->layer & arm->layer) { | if (bone->layer & arm->layer) { | ||||
| const bool draw_dofs = !is_pose_select && ctx->show_relations && | const bool draw_dofs = !is_pose_select && ctx->show_relations && | ||||
| (arm->flag & ARM_POSEMODE) && (bone->flag & BONE_SELECTED) && | (arm->flag & ARM_POSEMODE) && (bone->flag & BONE_SELECTED) && | ||||
| ((ob->base_flag & BASE_FROM_DUPLI) == 0) && | ((ob->base_flag & BASE_FROM_DUPLI) == 0) && | ||||
| (pchan->ikflag & (BONE_IK_XLIMIT | BONE_IK_ZLIMIT)); | (pchan->ikflag & (BONE_IK_XLIMIT | BONE_IK_ZLIMIT)); | ||||
| const int select_id = is_pose_select ? index : (uint)-1; | const int select_id = is_pose_select ? index : (uint)-1; | ||||
| const short constflag = pchan->constflag; | const short constflag = pchan->constflag; | ||||
| int drawflag = 0; | |||||
| pchan_draw_data_init(pchan); | pchan_draw_data_init(pchan); | ||||
| if (!ctx->const_color) { | if (!ctx->const_color) { | ||||
| set_pchan_colorset(ctx, ob, pchan); | set_pchan_colorset(ctx, ob, pchan); | ||||
| } | } | ||||
| if (locked_bones && BLI_gset_haskey(locked_bones, pchan->name)) { | |||||
| drawflag |= DRAW_FLAG_LOCKED; | |||||
| } | |||||
| int boneflag = bone->flag; | int boneflag = bone->flag; | ||||
| /* catch exception for bone with hidden parent */ | /* catch exception for bone with hidden parent */ | ||||
| boneflag = bone->flag; | boneflag = bone->flag; | ||||
| if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) { | if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) { | ||||
| boneflag &= ~BONE_CONNECTED; | boneflag &= ~BONE_CONNECTED; | ||||
| } | } | ||||
| /* set temporary flag for drawing bone as active, but only if selected */ | /* set temporary flag for drawing bone as active, but only if selected */ | ||||
| if (bone == arm->act_bone) { | if (bone == arm->act_bone) { | ||||
| boneflag |= BONE_DRAW_ACTIVE; | boneflag |= BONE_DRAW_ACTIVE; | ||||
| } | } | ||||
| draw_bone_relations(ctx, NULL, pchan, arm, boneflag, constflag); | draw_bone_relations(ctx, NULL, pchan, arm, boneflag, constflag); | ||||
| if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) { | if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) { | ||||
| draw_bone_update_disp_matrix_custom(pchan); | draw_bone_update_disp_matrix_custom(pchan); | ||||
| draw_bone_custom_shape(ctx, NULL, pchan, arm, boneflag, constflag, select_id); | draw_bone_custom_shape(ctx, NULL, pchan, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| else if (arm->drawtype == ARM_ENVELOPE) { | else if (arm->drawtype == ARM_ENVELOPE) { | ||||
| draw_bone_update_disp_matrix_default(NULL, pchan); | draw_bone_update_disp_matrix_default(NULL, pchan); | ||||
| draw_bone_envelope(ctx, NULL, pchan, arm, boneflag, constflag, select_id); | draw_bone_envelope(ctx, NULL, pchan, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| else if (arm->drawtype == ARM_LINE) { | else if (arm->drawtype == ARM_LINE) { | ||||
| draw_bone_update_disp_matrix_default(NULL, pchan); | draw_bone_update_disp_matrix_default(NULL, pchan); | ||||
| draw_bone_line(ctx, NULL, pchan, arm, boneflag, constflag, select_id); | draw_bone_line(ctx, NULL, pchan, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| else if (arm->drawtype == ARM_WIRE) { | else if (arm->drawtype == ARM_WIRE) { | ||||
| draw_bone_update_disp_matrix_bbone(NULL, pchan); | draw_bone_update_disp_matrix_bbone(NULL, pchan); | ||||
| draw_bone_wire(ctx, NULL, pchan, arm, boneflag, constflag, select_id); | draw_bone_wire(ctx, NULL, pchan, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| else if (arm->drawtype == ARM_B_BONE) { | else if (arm->drawtype == ARM_B_BONE) { | ||||
| draw_bone_update_disp_matrix_bbone(NULL, pchan); | draw_bone_update_disp_matrix_bbone(NULL, pchan); | ||||
| draw_bone_box(ctx, NULL, pchan, arm, boneflag, constflag, select_id); | draw_bone_box(ctx, NULL, pchan, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| else { | else { | ||||
| draw_bone_update_disp_matrix_default(NULL, pchan); | draw_bone_update_disp_matrix_default(NULL, pchan); | ||||
| draw_bone_octahedral(ctx, NULL, pchan, arm, boneflag, constflag, select_id); | draw_bone_octahedral(ctx, NULL, pchan, arm, boneflag, constflag, drawflag, select_id); | ||||
| } | } | ||||
| if (draw_dofs) { | if (draw_dofs) { | ||||
| draw_bone_degrees_of_freedom(ctx, pchan); | draw_bone_degrees_of_freedom(ctx, pchan); | ||||
| } | } | ||||
| if (show_text && (arm->flag & ARM_DRAWNAMES)) { | if (show_text && (arm->flag & ARM_DRAWNAMES)) { | ||||
| draw_bone_name(ctx, NULL, pchan, arm, boneflag); | draw_bone_name(ctx, NULL, pchan, arm, boneflag); | ||||
| } | } | ||||
| if (arm->flag & ARM_DRAWAXES) { | if (arm->flag & ARM_DRAWAXES) { | ||||
| draw_axes(ctx, NULL, pchan); | draw_axes(ctx, NULL, pchan); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (locked_bones) { | |||||
| BLI_gset_free(locked_bones, NULL); | |||||
| } | |||||
| arm->flag &= ~ARM_POSEMODE; | arm->flag &= ~ARM_POSEMODE; | ||||
| } | } | ||||
| static void armature_context_setup(ArmatureDrawContext *ctx, | static void armature_context_setup(ArmatureDrawContext *ctx, | ||||
| OVERLAY_PrivateData *pd, | OVERLAY_PrivateData *pd, | ||||
| Object *ob, | Object *ob, | ||||
| const bool do_envelope_dist, | const bool do_envelope_dist, | ||||
| const bool is_edit_mode, | const bool is_edit_mode, | ||||
| ▲ Show 20 Lines • Show All 185 Lines • Show Last 20 Lines | |||||