diff options
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_gizmo_armature.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_gizmo_armature.c | 268 |
1 files changed, 133 insertions, 135 deletions
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_armature.c b/source/blender/editors/space_view3d/view3d_gizmo_armature.c index 64617b03c5e..ae186505456 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_armature.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_armature.c @@ -43,8 +43,7 @@ #include "WM_api.h" #include "WM_types.h" -#include "view3d_intern.h" /* own include */ - +#include "view3d_intern.h" /* own include */ /* -------------------------------------------------------------------- */ /** \name Armature Spline Gizmo @@ -63,166 +62,165 @@ #define BBONE_SCALE_Y 3.0f struct BoneSplineHandle { - wmGizmo *gizmo; - bPoseChannel *pchan; - /* We could remove, keep since at the moment for checking the conversion. */ - float co[3]; - int index; + wmGizmo *gizmo; + bPoseChannel *pchan; + /* We could remove, keep since at the moment for checking the conversion. */ + float co[3]; + int index; }; struct BoneSplineWidgetGroup { - struct BoneSplineHandle handles[2]; + struct BoneSplineHandle handles[2]; }; -static void gizmo_bbone_offset_get( - const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, - void *value_p) +static void gizmo_bbone_offset_get(const wmGizmo *UNUSED(gz), + wmGizmoProperty *gz_prop, + void *value_p) { - struct BoneSplineHandle *bh = gz_prop->custom_func.user_data; - bPoseChannel *pchan = bh->pchan; - - float *value = value_p; - BLI_assert(gz_prop->type->array_length == 3); - - if (bh->index == 0) { - bh->co[1] = pchan->bone->ease1 / BBONE_SCALE_Y; - bh->co[0] = pchan->curveInX; - bh->co[2] = pchan->curveInY; - } - else { - bh->co[1] = -pchan->bone->ease2 / BBONE_SCALE_Y; - bh->co[0] = pchan->curveOutX; - bh->co[2] = pchan->curveOutY; - } - copy_v3_v3(value, bh->co); + struct BoneSplineHandle *bh = gz_prop->custom_func.user_data; + bPoseChannel *pchan = bh->pchan; + + float *value = value_p; + BLI_assert(gz_prop->type->array_length == 3); + + if (bh->index == 0) { + bh->co[1] = pchan->bone->ease1 / BBONE_SCALE_Y; + bh->co[0] = pchan->curveInX; + bh->co[2] = pchan->curveInY; + } + else { + bh->co[1] = -pchan->bone->ease2 / BBONE_SCALE_Y; + bh->co[0] = pchan->curveOutX; + bh->co[2] = pchan->curveOutY; + } + copy_v3_v3(value, bh->co); } -static void gizmo_bbone_offset_set( - const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, - const void *value_p) +static void gizmo_bbone_offset_set(const wmGizmo *UNUSED(gz), + wmGizmoProperty *gz_prop, + const void *value_p) { - struct BoneSplineHandle *bh = gz_prop->custom_func.user_data; - bPoseChannel *pchan = bh->pchan; - - const float *value = value_p; - - BLI_assert(gz_prop->type->array_length == 3); - copy_v3_v3(bh->co, value); - - if (bh->index == 0) { - pchan->bone->ease1 = max_ff(0.0f, bh->co[1] * BBONE_SCALE_Y); - pchan->curveInX = bh->co[0]; - pchan->curveInY = bh->co[2]; - } - else { - pchan->bone->ease2 = max_ff(0.0f, -bh->co[1] * BBONE_SCALE_Y); - pchan->curveOutX = bh->co[0]; - pchan->curveOutY = bh->co[2]; - } - + struct BoneSplineHandle *bh = gz_prop->custom_func.user_data; + bPoseChannel *pchan = bh->pchan; + + const float *value = value_p; + + BLI_assert(gz_prop->type->array_length == 3); + copy_v3_v3(bh->co, value); + + if (bh->index == 0) { + pchan->bone->ease1 = max_ff(0.0f, bh->co[1] * BBONE_SCALE_Y); + pchan->curveInX = bh->co[0]; + pchan->curveInY = bh->co[2]; + } + else { + pchan->bone->ease2 = max_ff(0.0f, -bh->co[1] * BBONE_SCALE_Y); + pchan->curveOutX = bh->co[0]; + pchan->curveOutY = bh->co[2]; + } } static bool WIDGETGROUP_armature_spline_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzgt)) { - View3D *v3d = CTX_wm_view3d(C); - if (v3d->gizmo_flag & (V3D_GIZMO_HIDE | V3D_GIZMO_HIDE_CONTEXT)) { - return false; - } - - ViewLayer *view_layer = CTX_data_view_layer(C); - Base *base = BASACT(view_layer); - if (base && BASE_SELECTABLE(v3d, base)) { - Object *ob = BKE_object_pose_armature_get(base->object); - if (ob) { - const bArmature *arm = ob->data; - if (arm->drawtype == ARM_B_BONE) { - bPoseChannel *pchan = BKE_pose_channel_active(ob); - if (pchan && pchan->bone->segments > 1) { - return true; - } - } - } - } - return false; + View3D *v3d = CTX_wm_view3d(C); + if (v3d->gizmo_flag & (V3D_GIZMO_HIDE | V3D_GIZMO_HIDE_CONTEXT)) { + return false; + } + + ViewLayer *view_layer = CTX_data_view_layer(C); + Base *base = BASACT(view_layer); + if (base && BASE_SELECTABLE(v3d, base)) { + Object *ob = BKE_object_pose_armature_get(base->object); + if (ob) { + const bArmature *arm = ob->data; + if (arm->drawtype == ARM_B_BONE) { + bPoseChannel *pchan = BKE_pose_channel_active(ob); + if (pchan && pchan->bone->segments > 1) { + return true; + } + } + } + } + return false; } - static void WIDGETGROUP_armature_spline_setup(const bContext *C, wmGizmoGroup *gzgroup) { - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = BKE_object_pose_armature_get(OBACT(view_layer)); - bPoseChannel *pchan = BKE_pose_channel_active(ob); - - const wmGizmoType *gzt_move = WM_gizmotype_find("GIZMO_GT_move_3d", true); - - struct BoneSplineWidgetGroup *bspline_group = MEM_callocN(sizeof(struct BoneSplineWidgetGroup), __func__); - gzgroup->customdata = bspline_group; - - /* Handles */ - for (int i = 0; i < ARRAY_SIZE(bspline_group->handles); i++) { - wmGizmo *gz; - gz = bspline_group->handles[i].gizmo = WM_gizmo_new_ptr(gzt_move, gzgroup, NULL); - RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_MOVE_STYLE_RING_2D); - RNA_enum_set(gz->ptr, "draw_options", - ED_GIZMO_MOVE_DRAW_FLAG_FILL | ED_GIZMO_MOVE_DRAW_FLAG_ALIGN_VIEW); - WM_gizmo_set_flag(gz, WM_GIZMO_DRAW_VALUE, true); - - UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, gz->color); - UI_GetThemeColor3fv(TH_GIZMO_HI, gz->color_hi); - - gz->scale_basis = 0.06f; - - if (i == 0) { - copy_v3_v3(gz->matrix_basis[3], pchan->loc); - } - } + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = BKE_object_pose_armature_get(OBACT(view_layer)); + bPoseChannel *pchan = BKE_pose_channel_active(ob); + + const wmGizmoType *gzt_move = WM_gizmotype_find("GIZMO_GT_move_3d", true); + + struct BoneSplineWidgetGroup *bspline_group = MEM_callocN(sizeof(struct BoneSplineWidgetGroup), + __func__); + gzgroup->customdata = bspline_group; + + /* Handles */ + for (int i = 0; i < ARRAY_SIZE(bspline_group->handles); i++) { + wmGizmo *gz; + gz = bspline_group->handles[i].gizmo = WM_gizmo_new_ptr(gzt_move, gzgroup, NULL); + RNA_enum_set(gz->ptr, "draw_style", ED_GIZMO_MOVE_STYLE_RING_2D); + RNA_enum_set(gz->ptr, + "draw_options", + ED_GIZMO_MOVE_DRAW_FLAG_FILL | ED_GIZMO_MOVE_DRAW_FLAG_ALIGN_VIEW); + WM_gizmo_set_flag(gz, WM_GIZMO_DRAW_VALUE, true); + + UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, gz->color); + UI_GetThemeColor3fv(TH_GIZMO_HI, gz->color_hi); + + gz->scale_basis = 0.06f; + + if (i == 0) { + copy_v3_v3(gz->matrix_basis[3], pchan->loc); + } + } } static void WIDGETGROUP_armature_spline_refresh(const bContext *C, wmGizmoGroup *gzgroup) { - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = BKE_object_pose_armature_get(OBACT(view_layer)); - - if (!gzgroup->customdata) { - return; - } - - struct BoneSplineWidgetGroup *bspline_group = gzgroup->customdata; - bPoseChannel *pchan = BKE_pose_channel_active(ob); - - /* Handles */ - for (int i = 0; i < ARRAY_SIZE(bspline_group->handles); i++) { - wmGizmo *gz = bspline_group->handles[i].gizmo; - bspline_group->handles[i].pchan = pchan; - bspline_group->handles[i].index = i; - - float mat[4][4]; - mul_m4_m4m4(mat, ob->obmat, (i == 0) ? pchan->disp_mat : pchan->disp_tail_mat); - copy_m4_m4(gz->matrix_space, mat); - - /* need to set property here for undo. TODO would prefer to do this in _init */ - WM_gizmo_target_property_def_func( - gz, "offset", - &(const struct wmGizmoPropertyFnParams) { - .value_get_fn = gizmo_bbone_offset_get, - .value_set_fn = gizmo_bbone_offset_set, - .range_get_fn = NULL, - .user_data = &bspline_group->handles[i], - }); - } + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = BKE_object_pose_armature_get(OBACT(view_layer)); + + if (!gzgroup->customdata) { + return; + } + + struct BoneSplineWidgetGroup *bspline_group = gzgroup->customdata; + bPoseChannel *pchan = BKE_pose_channel_active(ob); + + /* Handles */ + for (int i = 0; i < ARRAY_SIZE(bspline_group->handles); i++) { + wmGizmo *gz = bspline_group->handles[i].gizmo; + bspline_group->handles[i].pchan = pchan; + bspline_group->handles[i].index = i; + + float mat[4][4]; + mul_m4_m4m4(mat, ob->obmat, (i == 0) ? pchan->disp_mat : pchan->disp_tail_mat); + copy_m4_m4(gz->matrix_space, mat); + + /* need to set property here for undo. TODO would prefer to do this in _init */ + WM_gizmo_target_property_def_func(gz, + "offset", + &(const struct wmGizmoPropertyFnParams){ + .value_get_fn = gizmo_bbone_offset_get, + .value_set_fn = gizmo_bbone_offset_set, + .range_get_fn = NULL, + .user_data = &bspline_group->handles[i], + }); + } } void VIEW3D_GGT_armature_spline(wmGizmoGroupType *gzgt) { - gzgt->name = "Armature Spline Widgets"; - gzgt->idname = "VIEW3D_GGT_armature_spline"; + gzgt->name = "Armature Spline Widgets"; + gzgt->idname = "VIEW3D_GGT_armature_spline"; - gzgt->flag = (WM_GIZMOGROUPTYPE_PERSISTENT | - WM_GIZMOGROUPTYPE_3D); + gzgt->flag = (WM_GIZMOGROUPTYPE_PERSISTENT | WM_GIZMOGROUPTYPE_3D); - gzgt->poll = WIDGETGROUP_armature_spline_poll; - gzgt->setup = WIDGETGROUP_armature_spline_setup; - gzgt->refresh = WIDGETGROUP_armature_spline_refresh; + gzgt->poll = WIDGETGROUP_armature_spline_poll; + gzgt->setup = WIDGETGROUP_armature_spline_setup; + gzgt->refresh = WIDGETGROUP_armature_spline_refresh; } /** \} */ |