Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_manipulator.c
| Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | |||||
| #include "transform.h" | #include "transform.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "GPU_select.h" | #include "GPU_select.h" | ||||
| #include "GPU_immediate.h" | #include "GPU_immediate.h" | ||||
| #include "GPU_matrix.h" | #include "GPU_matrix.h" | ||||
| #include "DEG_depsgraph_query.h" | |||||
| #define USE_AXIS_BOUNDS | #define USE_AXIS_BOUNDS | ||||
| /* return codes for select, and drawing flags */ | /* return codes for select, and drawing flags */ | ||||
| #define MAN_TRANS_X (1 << 0) | #define MAN_TRANS_X (1 << 0) | ||||
| #define MAN_TRANS_Y (1 << 1) | #define MAN_TRANS_Y (1 << 1) | ||||
| #define MAN_TRANS_Z (1 << 2) | #define MAN_TRANS_Z (1 << 2) | ||||
| #define MAN_TRANS_C (MAN_TRANS_X | MAN_TRANS_Y | MAN_TRANS_Z) | #define MAN_TRANS_C (MAN_TRANS_X | MAN_TRANS_Y | MAN_TRANS_Z) | ||||
| ▲ Show 20 Lines • Show All 495 Lines • ▼ Show 20 Lines | |||||
| /* centroid, boundbox, of selection */ | /* centroid, boundbox, of selection */ | ||||
| /* returns total items selected */ | /* returns total items selected */ | ||||
| static int calc_manipulator_stats( | static int calc_manipulator_stats( | ||||
| const bContext *C, bool use_only_center, | const bContext *C, bool use_only_center, | ||||
| struct TransformBounds *tbounds) | struct TransformBounds *tbounds) | ||||
| { | { | ||||
| const Depsgraph *depsgraph = CTX_data_depsgraph(C); | |||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| View3D *v3d = sa->spacedata.first; | View3D *v3d = sa->spacedata.first; | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| Base *base; | Base *base; | ||||
| Object *ob = OBACT(view_layer); | Object *ob = OBACT(view_layer); | ||||
| const Object *ob_eval = NULL; | |||||
| const Object *obedit_eval = NULL; | |||||
| bGPdata *gpd = CTX_data_gpencil_data(C); | bGPdata *gpd = CTX_data_gpencil_data(C); | ||||
| const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE)); | const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE)); | ||||
| int a, totsel = 0; | int a, totsel = 0; | ||||
| /* transform widget matrix */ | /* transform widget matrix */ | ||||
| unit_m4(rv3d->twmat); | unit_m4(rv3d->twmat); | ||||
| #ifdef USE_AXIS_BOUNDS | #ifdef USE_AXIS_BOUNDS | ||||
| 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); | ||||
| #endif | #endif | ||||
| rv3d->twdrawflag = 0xFFFF; | rv3d->twdrawflag = 0xFFFF; | ||||
| ob_eval = DEG_get_evaluated_object(depsgraph, ob); | |||||
| obedit_eval = DEG_get_evaluated_object(depsgraph, obedit); | |||||
| /* 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 && !is_gp_edit) { | if (ob && !is_gp_edit) { | ||||
| switch (scene->orientation_type) { | switch (scene->orientation_type) { | ||||
| case V3D_MANIP_GLOBAL: | case V3D_MANIP_GLOBAL: | ||||
| { | { | ||||
| Show All 27 Lines | switch (scene->orientation_type) { | ||||
| * use the active pones axis for display [#33575], this works as expected on a single bone | * use the active pones axis for display [#33575], this works as expected on a single bone | ||||
| * and users who select many bones will understand whats going on and what local means | * and users who select many bones will understand whats going on and what local means | ||||
| * when they start transforming */ | * when they start transforming */ | ||||
| float mat[3][3]; | float mat[3][3]; | ||||
| ED_getTransformOrientationMatrix(C, mat, v3d->around); | ED_getTransformOrientationMatrix(C, mat, v3d->around); | ||||
| copy_m4_m3(rv3d->twmat, mat); | copy_m4_m3(rv3d->twmat, mat); | ||||
| break; | break; | ||||
| } | } | ||||
| copy_m4_m4(rv3d->twmat, ob->obmat); | copy_m4_m4(rv3d->twmat, ob_eval->obmat); | ||||
| normalize_m4(rv3d->twmat); | normalize_m4(rv3d->twmat); | ||||
| break; | break; | ||||
| } | } | ||||
| case V3D_MANIP_VIEW: | case V3D_MANIP_VIEW: | ||||
| { | { | ||||
| float mat[3][3]; | float mat[3][3]; | ||||
| copy_m3_m4(mat, rv3d->viewinv); | copy_m3_m4(mat, rv3d->viewinv); | ||||
| normalize_m3(mat); | normalize_m3(mat); | ||||
| Show All 17 Lines | #endif | ||||
| /* transform widget centroid/center */ | /* transform widget centroid/center */ | ||||
| INIT_MINMAX(tbounds->min, tbounds->max); | INIT_MINMAX(tbounds->min, tbounds->max); | ||||
| zero_v3(tbounds->center); | zero_v3(tbounds->center); | ||||
| #ifdef USE_AXIS_BOUNDS | #ifdef USE_AXIS_BOUNDS | ||||
| copy_m3_m4(tbounds->axis, rv3d->twmat); | copy_m3_m4(tbounds->axis, rv3d->twmat); | ||||
| if (ob && ob->mode & OB_MODE_EDIT) { | if (ob && ob->mode & OB_MODE_EDIT) { | ||||
| float diff_mat[3][3]; | float diff_mat[3][3]; | ||||
| copy_m3_m4(diff_mat, ob->obmat); | copy_m3_m4(diff_mat, ob_eval->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); | ||||
| } | } | ||||
| for (int i = 0; i < 3; i++) { | for (int i = 0; i < 3; i++) { | ||||
| tbounds->axis_min[i] = +FLT_MAX; | tbounds->axis_min[i] = +FLT_MAX; | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if (is_gp_edit) { | ||||
| /* selection center */ | /* selection center */ | ||||
| if (totsel) { | if (totsel) { | ||||
| mul_v3_fl(tbounds->center, 1.0f / (float)totsel); /* centroid! */ | mul_v3_fl(tbounds->center, 1.0f / (float)totsel); /* centroid! */ | ||||
| } | } | ||||
| } | } | ||||
| else if (obedit) { | else if (obedit) { | ||||
| ob = obedit; | ob = obedit; | ||||
| ob_eval = obedit_eval; | |||||
| if (obedit->type == OB_MESH) { | if (obedit->type == OB_MESH) { | ||||
| BMEditMesh *em = BKE_editmesh_from_object(obedit); | BMEditMesh *em = BKE_editmesh_from_object(obedit); | ||||
| BMEditSelection ese; | BMEditSelection ese; | ||||
| float vec[3] = {0, 0, 0}; | float vec[3] = {0, 0, 0}; | ||||
| /* USE LAST SELECTE WITH ACTIVE */ | /* USE LAST SELECTE WITH ACTIVE */ | ||||
| if ((v3d->around == V3D_AROUND_ACTIVE) && BM_select_history_active_get(em->bm, &ese)) { | if ((v3d->around == V3D_AROUND_ACTIVE) && BM_select_history_active_get(em->bm, &ese)) { | ||||
| BM_editselection_center(&ese, vec); | BM_editselection_center(&ese, vec); | ||||
| ▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | else if (obedit->type == OB_LATTICE) { | ||||
| bp++; | bp++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* selection center */ | /* selection center */ | ||||
| if (totsel) { | if (totsel) { | ||||
| mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid! | mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid! | ||||
| mul_m4_v3(obedit->obmat, tbounds->center); | mul_m4_v3(obedit_eval->obmat, tbounds->center); | ||||
| mul_m4_v3(obedit->obmat, tbounds->min); | mul_m4_v3(obedit_eval->obmat, tbounds->min); | ||||
| mul_m4_v3(obedit->obmat, tbounds->max); | mul_m4_v3(obedit_eval->obmat, tbounds->max); | ||||
| } | } | ||||
| } | } | ||||
| else if (ob && (ob->mode & OB_MODE_POSE)) { | else if (ob && (ob->mode & OB_MODE_POSE)) { | ||||
| bPoseChannel *pchan; | bPoseChannel *pchan; | ||||
| int mode = TFM_ROTATION; // mislead counting bones... bah. We don't know the manipulator mode, could be mixed | int mode = TFM_ROTATION; // mislead counting bones... bah. We don't know the manipulator mode, could be mixed | ||||
| bool ok = false; | bool ok = false; | ||||
| if ((v3d->around == V3D_AROUND_ACTIVE) && (pchan = BKE_pose_channel_active(ob))) { | if ((v3d->around == V3D_AROUND_ACTIVE) && (pchan = BKE_pose_channel_active(ob))) { | ||||
| Show All 19 Lines | else { | ||||
| } | } | ||||
| } | } | ||||
| ok = true; | ok = true; | ||||
| } | } | ||||
| } | } | ||||
| if (ok) { | if (ok) { | ||||
| mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid! | mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid! | ||||
| mul_m4_v3(ob->obmat, tbounds->center); | mul_m4_v3(ob_eval->obmat, tbounds->center); | ||||
| mul_m4_v3(ob->obmat, tbounds->min); | mul_m4_v3(ob_eval->obmat, tbounds->min); | ||||
| mul_m4_v3(ob->obmat, tbounds->max); | mul_m4_v3(ob_eval->obmat, tbounds->max); | ||||
| } | } | ||||
| } | } | ||||
| else if (ob && (ob->mode & OB_MODE_ALL_PAINT)) { | else if (ob && (ob->mode & OB_MODE_ALL_PAINT)) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) { | else if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) { | ||||
| PTCacheEdit *edit = PE_get_current(scene, ob); | PTCacheEdit *edit = PE_get_current(scene, ob); | ||||
| PTCacheEditPoint *point; | PTCacheEditPoint *point; | ||||
| Show All 21 Lines | #endif | ||||
| else { | else { | ||||
| /* we need the one selected object, if its not active */ | /* we need the one selected object, if its not active */ | ||||
| base = BASACT(view_layer); | base = BASACT(view_layer); | ||||
| ob = OBACT(view_layer); | ob = OBACT(view_layer); | ||||
| if (base && ((base->flag & BASE_SELECTED) == 0)) ob = NULL; | if (base && ((base->flag & BASE_SELECTED) == 0)) ob = NULL; | ||||
| for (base = view_layer->object_bases.first; base; base = base->next) { | for (base = view_layer->object_bases.first; base; base = base->next) { | ||||
| if (TESTBASELIB(base)) { | if (!TESTBASELIB(base)) { | ||||
| if (ob == NULL) | continue; | ||||
| } | |||||
| const Object *base_object_eval = DEG_get_evaluated_object(depsgraph, base->object); | |||||
| if (ob == NULL) { | |||||
| ob = base->object; | ob = base->object; | ||||
| if (use_only_center || base->object->bb == NULL) { | ob_eval = base_object_eval; | ||||
| calc_tw_center(tbounds, base->object->obmat[3]); | } | ||||
| if (use_only_center || base_object_eval->bb == NULL) { | |||||
| calc_tw_center(tbounds, base_object_eval->obmat[3]); | |||||
| } | } | ||||
| else { | else { | ||||
| for (uint j = 0; j < 8; j++) { | for (uint j = 0; j < 8; j++) { | ||||
| float co[3]; | float co[3]; | ||||
| mul_v3_m4v3(co, base->object->obmat, base->object->bb->vec[j]); | mul_v3_m4v3(co, base_object_eval->obmat, base_object_eval->bb->vec[j]); | ||||
| calc_tw_center(tbounds, co); | calc_tw_center(tbounds, co); | ||||
| } | } | ||||
| } | } | ||||
| protectflag_to_drawflags(base->object->protectflag, &rv3d->twdrawflag); | protectflag_to_drawflags(base->object->protectflag, &rv3d->twdrawflag); | ||||
| totsel++; | totsel++; | ||||
| } | } | ||||
| } | |||||
| /* selection center */ | /* selection center */ | ||||
| if (totsel) { | if (totsel) { | ||||
| mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid! | mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid! | ||||
| } | } | ||||
| } | } | ||||
| if (totsel == 0) { | if (totsel == 0) { | ||||
| ▲ Show 20 Lines • Show All 681 Lines • Show Last 20 Lines | |||||