Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/overlay_armature.c
| Show First 20 Lines • Show All 1,019 Lines • ▼ Show 20 Lines | static void pchan_draw_data_init(bPoseChannel *pchan) | ||||
| if (pchan->draw_data == NULL) { | if (pchan->draw_data == NULL) { | ||||
| pchan->draw_data = MEM_mallocN( | pchan->draw_data = MEM_mallocN( | ||||
| sizeof(*pchan->draw_data) + sizeof(Mat4) * pchan->bone->segments, __func__); | sizeof(*pchan->draw_data) + sizeof(Mat4) * pchan->bone->segments, __func__); | ||||
| pchan->draw_data->bbone_matrix_len = pchan->bone->segments; | pchan->draw_data->bbone_matrix_len = pchan->bone->segments; | ||||
| } | } | ||||
| } | } | ||||
| static void draw_bone_update_disp_matrix_default(EditBone *eBone, bPoseChannel *pchan) | static void draw_edbo_update_disp_matrix_default(EditBone *eBone) | ||||
| { | { | ||||
| float ebmat[4][4]; | |||||
| float length; | |||||
| float(*bone_mat)[4]; | |||||
| float(*disp_mat)[4]; | |||||
| float(*disp_tail_mat)[4]; | |||||
| /* TODO : This should be moved to depsgraph or armature refresh | /* TODO : This should be moved to depsgraph or armature refresh | ||||
| * and not be tight to the draw pass creation. | * and not be tight to the draw pass creation. | ||||
| * This would refresh armature without invalidating the draw cache */ | * This would refresh armature without invalidating the draw cache */ | ||||
| if (pchan) { | float s[4][4], ebmat[4][4], length; | ||||
| length = pchan->bone->length; | |||||
| bone_mat = pchan->pose_mat; | |||||
| disp_mat = pchan->disp_mat; | |||||
| disp_tail_mat = pchan->disp_tail_mat; | |||||
| } | |||||
| else { | |||||
| eBone->length = len_v3v3(eBone->tail, eBone->head); | |||||
| ED_armature_ebone_to_mat4(eBone, ebmat); | |||||
| length = eBone->length; | eBone->length = length = len_v3v3(eBone->tail, eBone->head); | ||||
| bone_mat = ebmat; | ED_armature_ebone_to_mat4(eBone, ebmat); | ||||
| disp_mat = eBone->disp_mat; | |||||
| disp_tail_mat = eBone->disp_tail_mat; | |||||
| } | |||||
| copy_m4_m4(disp_mat, bone_mat); | copy_m4_m4(eBone->disp_mat, ebmat); | ||||
| rescale_m4(disp_mat, (float[3]){length, length, length}); | rescale_m4(eBone->disp_mat, (float[3]){length, length, length}); | ||||
| copy_m4_m4(disp_tail_mat, disp_mat); | copy_m4_m4(eBone->disp_tail_mat, eBone->disp_mat); | ||||
| translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f); | translate_m4(eBone->disp_tail_mat, 0.0f, 1.0f, 0.0f); | ||||
| } | } | ||||
| /* compute connected child pointer for B-Bone drawing */ | /* compute connected child pointer for B-Bone drawing */ | ||||
| static void edbo_compute_bbone_child(bArmature *arm) | static void edbo_compute_bbone_child(bArmature *arm) | ||||
| { | { | ||||
| EditBone *eBone; | EditBone *eBone; | ||||
| for (eBone = arm->edbo->first; eBone; eBone = eBone->next) { | for (eBone = arm->edbo->first; eBone; eBone = eBone->next) { | ||||
| ▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | if (bbone_segments > 1) { | ||||
| for (int i = bbone_segments; i--; bbones_mat++) { | for (int i = bbone_segments; i--; bbones_mat++) { | ||||
| mul_m4_m4m4(*bbones_mat, *bbones_mat, s); | mul_m4_m4m4(*bbones_mat, *bbones_mat, s); | ||||
| mul_m4_m4m4(*bbones_mat, bone_mat, *bbones_mat); | mul_m4_m4m4(*bbones_mat, bone_mat, *bbones_mat); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| mul_m4_m4m4(*bbones_mat, bone_mat, s); | mul_m4_m4m4(*bbones_mat, bone_mat, s); | ||||
| } | } | ||||
| } | |||||
| /* Grrr... We need default display matrix to draw end points, axes, etc. :( */ | /* Grrr... We need default display matrix to draw end points, axes, etc. :( */ | ||||
| draw_bone_update_disp_matrix_default(eBone, pchan); | draw_edbo_update_disp_matrix_default(eBone, pchan); | ||||
| } | } | ||||
| static void draw_bone_update_disp_matrix_custom(bPoseChannel *pchan) | |||||
| { | |||||
| 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->custom_tx ? pchan->custom_tx->pose_mat : pchan->pose_mat; | |||||
| disp_mat = pchan->disp_mat; | |||||
| disp_tail_mat = pchan->disp_tail_mat; | |||||
| copy_m4_m4(disp_mat, bone_mat); | |||||
| rescale_m4(disp_mat, (float[3]){length, length, length}); | |||||
| copy_m4_m4(disp_tail_mat, disp_mat); | |||||
| translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f); | |||||
| } | } | ||||
| static void draw_axes(ArmatureDrawContext *ctx, | static void draw_axes(ArmatureDrawContext *ctx, | ||||
| const EditBone *eBone, | const EditBone *eBone, | ||||
| const bPoseChannel *pchan, | const bPoseChannel *pchan, | ||||
| const bArmature *arm) | const bArmature *arm) | ||||
| { | { | ||||
| float final_col[4]; | float final_col[4]; | ||||
| ▲ Show 20 Lines • Show All 647 Lines • ▼ Show 20 Lines | if (eBone->layer & arm->layer) { | ||||
| boneflag |= BONE_DRAW_ACTIVE; | boneflag |= BONE_DRAW_ACTIVE; | ||||
| } | } | ||||
| boneflag &= ~BONE_DRAW_LOCKED_WEIGHT; | boneflag &= ~BONE_DRAW_LOCKED_WEIGHT; | ||||
| 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_edbo_update_disp_matrix_default(eBone); | ||||
| draw_bone_envelope(ctx, eBone, NULL, arm, boneflag, constflag, select_id); | draw_bone_envelope(ctx, eBone, NULL, arm, boneflag, constflag, select_id); | ||||
| } | } | ||||
| else if (arm->drawtype == ARM_LINE) { | else if (arm->drawtype == ARM_LINE) { | ||||
| draw_bone_update_disp_matrix_default(eBone, NULL); | draw_edbo_update_disp_matrix_default(eBone); | ||||
| draw_bone_line(ctx, eBone, NULL, arm, boneflag, constflag, select_id); | draw_bone_line(ctx, eBone, NULL, arm, boneflag, constflag, 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, 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, select_id); | ||||
| } | } | ||||
| else { | else { | ||||
| draw_bone_update_disp_matrix_default(eBone, NULL); | draw_edbo_update_disp_matrix_default(eBone); | ||||
| draw_bone_octahedral(ctx, eBone, NULL, arm, boneflag, constflag, select_id); | draw_bone_octahedral(ctx, eBone, NULL, arm, boneflag, constflag, 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) { | ||||
| ▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | if (bone_visible) { | ||||
| if (!draw_locked_weights) { | if (!draw_locked_weights) { | ||||
| boneflag &= ~BONE_DRAW_LOCKED_WEIGHT; | boneflag &= ~BONE_DRAW_LOCKED_WEIGHT; | ||||
| } | } | ||||
| 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_custom_shape(ctx, NULL, pchan, arm, boneflag, constflag, select_id); | draw_bone_custom_shape(ctx, NULL, pchan, arm, boneflag, constflag, select_id); | ||||
| } | } | ||||
| else if (arm->drawtype == ARM_ENVELOPE) { | else if (arm->drawtype == ARM_ENVELOPE) { | ||||
| 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, select_id); | ||||
| } | } | ||||
| else if (arm->drawtype == ARM_LINE) { | else if (arm->drawtype == ARM_LINE) { | ||||
| 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, 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, 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, select_id); | ||||
| } | } | ||||
| else { | else { | ||||
| 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, 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)) { | ||||
| ▲ Show 20 Lines • Show All 192 Lines • Show Last 20 Lines | |||||