Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_orientations.c
| Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_workspace.h" | |||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "ED_armature.h" | #include "ED_armature.h" | ||||
| #include "transform.h" | #include "transform.h" | ||||
| /* *********************** TransSpace ************************** */ | /* *********************** TransSpace ************************** */ | ||||
| void BIF_clearTransformOrientation(bContext *C) | void BIF_clearTransformOrientation(bContext *C) | ||||
| { | { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | ||||
| BLI_freelistN(transform_spaces); | BLI_freelistN(transform_spaces); | ||||
| // Need to loop over all view3d | // Need to loop over all view3d | ||||
| if (v3d && v3d->twmode >= V3D_MANIP_CUSTOM) { | if (v3d && v3d->twmode >= V3D_MANIP_CUSTOM) { | ||||
| v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */ | v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */ | ||||
| v3d->custom_orientation = NULL; | |||||
| } | } | ||||
| } | } | ||||
| static TransformOrientation *findOrientationName(ListBase *lb, const char *name) | static TransformOrientation *findOrientationName(ListBase *lb, const char *name) | ||||
| { | { | ||||
| return BLI_findstring(lb, name, offsetof(TransformOrientation, name)); | return BLI_findstring(lb, name, offsetof(TransformOrientation, name)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 259 Lines • ▼ Show 20 Lines | TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3], | ||||
| /* copy matrix into transform space */ | /* copy matrix into transform space */ | ||||
| copy_m3_m3(ts->mat, mat); | copy_m3_m3(ts->mat, mat); | ||||
| return ts; | return ts; | ||||
| } | } | ||||
| void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target) | void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | |||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ListBase *transform_spaces = &scene->transform_spaces; | ListBase *transform_spaces = &scene->transform_spaces; | ||||
| const int i = BLI_findindex(transform_spaces, target); | |||||
| if (i != -1) { | BLI_assert(BLI_findindex(transform_spaces, target) != -1); | ||||
| Main *bmain = CTX_data_main(C); | BKE_workspaces_transform_orientation_remove(&bmain->workspaces, target); | ||||
| BKE_screen_view3d_main_twmode_remove(&bmain->screen, scene, i); | |||||
| BLI_freelinkN(transform_spaces, target); | BLI_freelinkN(transform_spaces, target); | ||||
| } | } | ||||
| } | |||||
| void BIF_removeTransformOrientationIndex(bContext *C, int index) | |||||
| { | |||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | |||||
| TransformOrientation *ts = BLI_findlink(transform_spaces, index); | |||||
| if (ts) { | |||||
| BIF_removeTransformOrientation(C, ts); | |||||
| } | |||||
| } | |||||
| void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) | void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target) | ||||
| { | { | ||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | ||||
| const int i = BLI_findindex(transform_spaces, target); | const int i = BLI_findindex(transform_spaces, target); | ||||
| if (i != -1) { | if (i != -1) { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| v3d->twmode = V3D_MANIP_CUSTOM + i; | v3d->twmode = V3D_MANIP_CUSTOM + i; | ||||
| v3d->custom_orientation = target; | |||||
| } | } | ||||
| } | } | ||||
| void BIF_selectTransformOrientationValue(bContext *C, int orientation) | void BIF_selectTransformOrientationValue(bContext *C, int orientation) | ||||
| { | { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| if (v3d) /* currently using generic poll */ | |||||
| if (v3d) { /* currently using generic poll */ | |||||
| Scene *scene = CTX_data_scene(C); | |||||
| TransformOrientation *target = BLI_findlink(&scene->transform_spaces, orientation - V3D_MANIP_CUSTOM); | |||||
| v3d->twmode = orientation; | v3d->twmode = orientation; | ||||
| v3d->custom_orientation = target; | |||||
| } | |||||
| } | } | ||||
| int BIF_countTransformOrientation(const bContext *C) | int BIF_countTransformOrientation(const bContext *C) | ||||
| { | { | ||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | ||||
| return BLI_listbase_count(transform_spaces); | return BLI_listbase_count(transform_spaces); | ||||
| } | } | ||||
| bool applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name, int index) | bool applyTransformOrientation(const TransformOrientation *ts, float r_mat[3][3], char *r_name) | ||||
| { | { | ||||
| ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces; | |||||
| TransformOrientation *ts = BLI_findlink(transform_spaces, index); | |||||
| BLI_assert(index >= 0); | |||||
| if (ts) { | if (ts) { | ||||
| if (r_name) { | if (r_name) { | ||||
| BLI_strncpy(r_name, ts->name, MAX_NAME); | BLI_strncpy(r_name, ts->name, MAX_NAME); | ||||
| } | } | ||||
| copy_m3_m3(mat, ts->mat); | copy_m3_m3(r_mat, ts->mat); | ||||
| return true; | return true; | ||||
| } | } | ||||
| else { | else { | ||||
| /* invalid index, can happen sometimes */ | /* invalid index, can happen sometimes */ | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | case V3D_MANIP_VIEW: | ||||
| normalize_m3(mat); | normalize_m3(mat); | ||||
| copy_m3_m3(t->spacemtx, mat); | copy_m3_m3(t->spacemtx, mat); | ||||
| } | } | ||||
| else { | else { | ||||
| unit_m3(t->spacemtx); | unit_m3(t->spacemtx); | ||||
| } | } | ||||
| break; | break; | ||||
| default: /* V3D_MANIP_CUSTOM */ | default: /* V3D_MANIP_CUSTOM */ | ||||
| if (applyTransformOrientation(C, t->spacemtx, t->spacename, t->current_orientation - V3D_MANIP_CUSTOM)) { | { | ||||
| TransformOrientation *ts = BLI_findlink(&t->scene->transform_spaces, | |||||
| t->current_orientation - V3D_MANIP_CUSTOM); | |||||
| if (applyTransformOrientation(ts, t->spacemtx, t->spacename)) { | |||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else { | else { | ||||
| unit_m3(t->spacemtx); | unit_m3(t->spacemtx); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| /** | /** | ||||
| * utility function - get first n, selected vert/edge/faces | * utility function - get first n, selected vert/edge/faces | ||||
| */ | */ | ||||
| static unsigned int bm_mesh_elems_select_get_n__internal( | static unsigned int bm_mesh_elems_select_get_n__internal( | ||||
| BMesh *bm, BMElem **elems, const unsigned int n, | BMesh *bm, BMElem **elems, const unsigned int n, | ||||
| const BMIterType itype, const char htype) | const BMIterType itype, const char htype) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 576 Lines • Show Last 20 Lines | |||||