Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/overlay_armature.c
| Show First 20 Lines • Show All 1,025 Lines • ▼ Show 20 Lines | 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_bone_update_disp_matrix_default(EditBone *eBone, bPoseChannel *pchan) | ||||
| { | { | ||||
| float ebmat[4][4]; | float ebmat[4][4]; | ||||
| float length; | float bone_scale[3]; | ||||
sybren: There is no such thing as a 3D bone length, as "length" is inherently 1D. `bone_scale` is… | |||||
| float(*bone_mat)[4]; | float(*bone_mat)[4]; | ||||
| float(*disp_mat)[4]; | float(*disp_mat)[4]; | ||||
| float(*disp_tail_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) { | if (pchan) { | ||||
| length = pchan->bone->length; | |||||
| bone_mat = pchan->pose_mat; | bone_mat = pchan->pose_mat; | ||||
| disp_mat = pchan->disp_mat; | disp_mat = pchan->disp_mat; | ||||
| disp_tail_mat = pchan->disp_tail_mat; | disp_tail_mat = pchan->disp_tail_mat; | ||||
| mul_v3_v3fl(bone_scale, pchan->custom_scale_xyz, pchan->bone->length); | |||||
Done Inline Actionslength can be const sybren: `length` can be `const` | |||||
| } | } | ||||
| else { | else { | ||||
Done Inline ActionsThis is just mul_v3_fl(bone_length, length). sybren: This is just `mul_v3_fl(bone_length, length)`. | |||||
| eBone->length = len_v3v3(eBone->tail, eBone->head); | eBone->length = len_v3v3(eBone->tail, eBone->head); | ||||
| ED_armature_ebone_to_mat4(eBone, ebmat); | ED_armature_ebone_to_mat4(eBone, ebmat); | ||||
| length = eBone->length; | copy_v3_fl(bone_scale, eBone->length); | ||||
| bone_mat = ebmat; | bone_mat = ebmat; | ||||
| disp_mat = eBone->disp_mat; | disp_mat = eBone->disp_mat; | ||||
Done Inline ActionsUse the copy_v3_fl function. sybren: Use the `copy_v3_fl` function. | |||||
| disp_tail_mat = eBone->disp_tail_mat; | disp_tail_mat = eBone->disp_tail_mat; | ||||
| } | } | ||||
| copy_m4_m4(disp_mat, bone_mat); | copy_m4_m4(disp_mat, bone_mat); | ||||
| rescale_m4(disp_mat, (float[3]){length, length, length}); | rescale_m4(disp_mat, bone_scale); | ||||
| copy_m4_m4(disp_tail_mat, disp_mat); | copy_m4_m4(disp_tail_mat, disp_mat); | ||||
| translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f); | translate_m4(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; | ||||
| ▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | static void draw_bone_update_disp_matrix_bbone(EditBone *eBone, bPoseChannel *pchan) | ||||
| } | } | ||||
| /* 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_bone_update_disp_matrix_default(eBone, pchan); | ||||
| } | } | ||||
| static void draw_bone_update_disp_matrix_custom(bPoseChannel *pchan) | static void draw_bone_update_disp_matrix_custom(bPoseChannel *pchan) | ||||
| { | { | ||||
| float length; | float bone_scale[3]; | ||||
| float(*bone_mat)[4]; | float(*bone_mat)[4]; | ||||
| float(*disp_mat)[4]; | float(*disp_mat)[4]; | ||||
| float(*disp_tail_mat)[4]; | float(*disp_tail_mat)[4]; | ||||
| float rot_mat[3][3]; | |||||
| /* See TODO above */ | /* See TODO above */ | ||||
| length = PCHAN_CUSTOM_DRAW_SIZE(pchan); | mul_v3_v3fl(bone_scale, pchan->custom_scale_xyz, PCHAN_CUSTOM_BONE_LENGTH(pchan)); | ||||
| bone_mat = pchan->custom_tx ? pchan->custom_tx->pose_mat : pchan->pose_mat; | bone_mat = pchan->custom_tx ? pchan->custom_tx->pose_mat : pchan->pose_mat; | ||||
Done Inline ActionsI think you should invert this check. So you write instead: if ((pchan->drawflag & PCHAN_DRAW_NO_CUSTOM_SHAPE) ) {
return;
}
float length;At the start of the function. This way you know that if the flag is set, this function does nothing. zeddb: I think you should invert this check.
So you write instead:
```
if ((pchan->drawflag &… | |||||
| disp_mat = pchan->disp_mat; | disp_mat = pchan->disp_mat; | ||||
| disp_tail_mat = pchan->disp_tail_mat; | disp_tail_mat = pchan->disp_tail_mat; | ||||
| eulO_to_mat3(rot_mat, pchan->custom_rotation_euler, ROT_MODE_XYZ); | |||||
| copy_m4_m4(disp_mat, bone_mat); | copy_m4_m4(disp_mat, bone_mat); | ||||
| rescale_m4(disp_mat, (float[3]){length, length, length}); | translate_m4(disp_mat, | ||||
| pchan->custom_translation[0], | |||||
| pchan->custom_translation[1], | |||||
| pchan->custom_translation[2]); | |||||
| mul_m4_m4m3(disp_mat, disp_mat, rot_mat); | |||||
| rescale_m4(disp_mat, bone_scale); | |||||
| copy_m4_m4(disp_tail_mat, disp_mat); | copy_m4_m4(disp_tail_mat, disp_mat); | ||||
| translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f); | 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, | ||||
Done Inline ActionsIt's faster to first multiply pchan->custom_scale_xyz with length, and then apply the result to the matrix. sybren: It's faster to first multiply `pchan->custom_scale_xyz` with `length`, and then apply the… | |||||
| const bArmature *arm) | const bArmature *arm) | ||||
| { | { | ||||
| float final_col[4]; | float final_col[4]; | ||||
| const float *col = (ctx->const_color) ? | const float *col = (ctx->const_color) ? | ||||
| ctx->const_color : | ctx->const_color : | ||||
| (BONE_FLAG(eBone, pchan) & BONE_SELECTED) ? G_draw.block.colorTextHi : | (BONE_FLAG(eBone, pchan) & BONE_SELECTED) ? G_draw.block.colorTextHi : | ||||
| G_draw.block.colorText; | G_draw.block.colorText; | ||||
| copy_v4_v4(final_col, col); | copy_v4_v4(final_col, col); | ||||
| ▲ Show 20 Lines • Show All 1,016 Lines • Show Last 20 Lines | |||||
There is no such thing as a 3D bone length, as "length" is inherently 1D. bone_scale is better.