Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_gizmo_3d.c
| Show First 20 Lines • Show All 640 Lines • ▼ Show 20 Lines | int ED_transform_calc_gizmo_stats(const bContext *C, | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| /* TODO(sergey): This function is used from operator's modal() and from gizmo's refresh(). | /* TODO(sergey): This function is used from operator's modal() and from gizmo's refresh(). | ||||
| * Is it fine to possibly evaluate dependency graph here? */ | * Is it fine to possibly evaluate dependency graph here? */ | ||||
| Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); | Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| View3D *v3d = area->spacedata.first; | View3D *v3d = area->spacedata.first; | ||||
| Object *obedit = CTX_data_edit_object(C); | |||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = region->regiondata; | ||||
| Base *base; | Base *base; | ||||
| Object *ob = OBACT(view_layer); | |||||
| bGPdata *gpd = CTX_data_gpencil_data(C); | bGPdata *gpd = CTX_data_gpencil_data(C); | ||||
| const bool is_gp_edit = GPENCIL_ANY_MODE(gpd); | const bool is_gp_edit = GPENCIL_ANY_MODE(gpd); | ||||
| const bool is_curve_edit = GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd); | const bool is_curve_edit = GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd); | ||||
| int a, totsel = 0; | int a, totsel = 0; | ||||
| const int pivot_point = scene->toolsettings->transform_pivot_point; | const int pivot_point = scene->toolsettings->transform_pivot_point; | ||||
| const short orient_index = params->orientation_index ? | const short orient_index = params->orientation_index ? | ||||
| (params->orientation_index - 1) : | (params->orientation_index - 1) : | ||||
| BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT); | BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT); | ||||
| Object *ob = OBACT(view_layer); | |||||
| Object *obedit = OBEDIT_FROM_OBACT(ob); | |||||
| if (ob && ob->mode & OB_MODE_WEIGHT_PAINT) { | |||||
| Object *obpose = BKE_object_pose_armature_get(ob); | |||||
| if (obpose != NULL) { | |||||
| ob = obpose; | |||||
| } | |||||
| } | |||||
| tbounds->use_matrix_space = false; | |||||
| /* transform widget matrix */ | /* transform widget matrix */ | ||||
| unit_m4(rv3d->twmat); | unit_m4(rv3d->twmat); | ||||
| unit_m3(rv3d->tw_axis_matrix); | unit_m3(rv3d->tw_axis_matrix); | ||||
| zero_v3(rv3d->tw_axis_min); | zero_v3(rv3d->tw_axis_min); | ||||
| zero_v3(rv3d->tw_axis_max); | zero_v3(rv3d->tw_axis_max); | ||||
| rv3d->twdrawflag = 0xFFFF; | rv3d->twdrawflag = 0xFFFF; | ||||
| /* global, local or normal orientation? | /* global, local or normal orientation? | ||||
| * if we could check 'totsel' now, this should be skipped with no selection. */ | * if we could check 'totsel' now, this should be skipped with no selection. */ | ||||
| if (ob) { | if (ob) { | ||||
| float mat[3][3]; | float mat[3][3]; | ||||
| ED_transform_calc_orientation_from_type_ex( | ED_transform_calc_orientation_from_type_ex( | ||||
| scene, view_layer, v3d, rv3d, ob, obedit, orient_index, pivot_point, mat); | scene, view_layer, v3d, rv3d, ob, obedit, orient_index, pivot_point, mat); | ||||
| copy_m4_m3(rv3d->twmat, mat); | copy_m4_m3(rv3d->twmat, mat); | ||||
| } | } | ||||
| /* transform widget centroid/center */ | /* transform widget centroid/center */ | ||||
| reset_tw_center(tbounds); | reset_tw_center(tbounds); | ||||
| copy_m3_m4(tbounds->axis, rv3d->twmat); | copy_m3_m4(tbounds->axis, rv3d->twmat); | ||||
| if (params->use_local_axis && (ob && ob->mode & OB_MODE_EDIT)) { | if (params->use_local_axis && (ob && ob->mode & (OB_MODE_EDIT | OB_MODE_POSE))) { | ||||
| float diff_mat[3][3]; | float diff_mat[3][3]; | ||||
| copy_m3_m4(diff_mat, ob->obmat); | copy_m3_m4(diff_mat, ob->obmat); | ||||
| normalize_m3(diff_mat); | normalize_m3(diff_mat); | ||||
| invert_m3(diff_mat); | invert_m3(diff_mat); | ||||
| mul_m3_m3m3(tbounds->axis, tbounds->axis, diff_mat); | mul_m3_m3m3(tbounds->axis, tbounds->axis, diff_mat); | ||||
| normalize_m3(tbounds->axis); | normalize_m3(tbounds->axis); | ||||
| tbounds->use_matrix_space = true; | |||||
| copy_m4_m4(tbounds->matrix_space, ob->obmat); | |||||
| } | } | ||||
| if (is_gp_edit) { | if (is_gp_edit) { | ||||
| float diff_mat[4][4]; | float diff_mat[4][4]; | ||||
| const bool use_mat_local = true; | const bool use_mat_local = true; | ||||
| LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { | LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { | ||||
| /* only editable and visible layers are considered */ | /* only editable and visible layers are considered */ | ||||
| ▲ Show 20 Lines • Show All 258 Lines • ▼ Show 20 Lines | for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | ||||
| /* mislead counting bones... bah. We don't know the gizmo mode, could be mixed */ | /* mislead counting bones... bah. We don't know the gizmo mode, could be mixed */ | ||||
| const int mode = TFM_ROTATION; | const int mode = TFM_ROTATION; | ||||
| const int totsel_iter = transform_convert_pose_transflags_update( | const int totsel_iter = transform_convert_pose_transflags_update( | ||||
| ob_iter, mode, V3D_AROUND_CENTER_BOUNDS, NULL); | ob_iter, mode, V3D_AROUND_CENTER_BOUNDS, NULL); | ||||
| if (totsel_iter) { | if (totsel_iter) { | ||||
| float mat_local[4][4]; | float mat_local[4][4]; | ||||
| if (params->use_local_axis) { | |||||
| if (use_mat_local) { | if (use_mat_local) { | ||||
| mul_m4_m4m4(mat_local, ob->imat, ob_iter->obmat); | mul_m4_m4m4(mat_local, ob->imat, ob_iter->obmat); | ||||
| } | } | ||||
| } | |||||
| /* use channels to get stats */ | /* use channels to get stats */ | ||||
| for (pchan = ob_iter->pose->chanbase.first; pchan; pchan = pchan->next) { | for (pchan = ob_iter->pose->chanbase.first; pchan; pchan = pchan->next) { | ||||
| Bone *bone = pchan->bone; | Bone *bone = pchan->bone; | ||||
| if (bone && (bone->flag & BONE_TRANSFORM)) { | if (bone && (bone->flag & BONE_TRANSFORM)) { | ||||
| calc_tw_center_with_matrix(tbounds, pchan->pose_head, use_mat_local, mat_local); | calc_tw_center_with_matrix(tbounds, pchan->pose_head, use_mat_local, mat_local); | ||||
| protectflag_to_drawflags_pchan(rv3d, pchan, orient_index); | protectflag_to_drawflags_pchan(rv3d, pchan, orient_index); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,128 Lines • ▼ Show 20 Lines | if ((ED_transform_calc_gizmo_stats(C, | ||||
| .use_local_axis = true, | .use_local_axis = true, | ||||
| .orientation_index = orient_index + 1, | .orientation_index = orient_index + 1, | ||||
| }, | }, | ||||
| &tbounds) == 0) || | &tbounds) == 0) || | ||||
| equals_v3v3(rv3d->tw_axis_min, rv3d->tw_axis_max)) { | equals_v3v3(rv3d->tw_axis_min, rv3d->tw_axis_max)) { | ||||
| WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); | WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); | ||||
| } | } | ||||
| else { | else { | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | if (tbounds.use_matrix_space) { | ||||
| Object *ob = OBACT(view_layer); | copy_m4_m4(gz->matrix_space, tbounds.matrix_space); | ||||
| if (ob && ob->mode & OB_MODE_EDIT) { | |||||
| copy_m4_m4(gz->matrix_space, ob->obmat); | |||||
| } | } | ||||
| else { | else { | ||||
| unit_m4(gz->matrix_space); | unit_m4(gz->matrix_space); | ||||
| } | } | ||||
| gizmo_prepare_mat(C, rv3d, &tbounds); | gizmo_prepare_mat(C, rv3d, &tbounds); | ||||
| WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, false); | WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, false); | ||||
| ▲ Show 20 Lines • Show All 331 Lines • Show Last 20 Lines | |||||