diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-08-31 09:29:59 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-08-31 10:02:47 +0300 |
commit | fa4f9292e16ce6a9253164ea731870c6d0161848 (patch) | |
tree | 988f3d289f45b2f4454a9632f2df563601800417 | |
parent | d718d6b4493429a1e688e874fd76963f98e3d034 (diff) |
Transform: avoid passing the context to extended orientation functions
This makes it possible to calculate orientation from functions
that don't have the context.
7 files changed, 57 insertions, 39 deletions
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h index 69ac48d842f..bedd0e2fa35 100644 --- a/source/blender/editors/include/ED_transform.h +++ b/source/blender/editors/include/ED_transform.h @@ -109,7 +109,8 @@ bool BIF_createTransformOrientation(struct bContext *C, const bool overwrite); void BIF_selectTransformOrientation(struct bContext *C, struct TransformOrientation *target); -void ED_getTransformOrientationMatrix(const struct bContext *C, +void ED_getTransformOrientationMatrix(struct ViewLayer *view_layer, + const struct View3D *v3d, struct Object *ob, struct Object *obedit, const short around, @@ -145,15 +146,15 @@ void Transform_Properties(struct wmOperatorType *ot, int flags); /* *** transform_orientations.c *** */ void ED_transform_calc_orientation_from_type(const struct bContext *C, float r_mat[3][3]); -short ED_transform_calc_orientation_from_type_ex(const struct bContext *C, - float r_mat[3][3], - /* extra args */ - struct Scene *scene, - struct RegionView3D *rv3d, +short ED_transform_calc_orientation_from_type_ex(const struct Scene *scene, + struct ViewLayer *view_layer, + const struct View3D *v3d, + const struct RegionView3D *rv3d, struct Object *ob, struct Object *obedit, const short orientation_index, - const int pivot_point); + const int pivot_point, + float r_mat[3][3]); /* transform gizmos */ diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 8e38d41f971..2fcf8fa6f8f 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -4871,8 +4871,15 @@ static int edbm_select_axis_exec(bContext *C, wmOperator *op) float axis_mat[3][3]; /* 3D view variables may be NULL, (no need to check in poll function). */ - ED_transform_calc_orientation_from_type_ex( - C, axis_mat, scene, CTX_wm_region_view3d(C), obedit, obedit, orientation, V3D_AROUND_ACTIVE); + ED_transform_calc_orientation_from_type_ex(scene, + view_layer, + CTX_wm_view3d(C), + CTX_wm_region_view3d(C), + obedit, + obedit, + orientation, + V3D_AROUND_ACTIVE, + axis_mat); const float *axis_vector = axis_mat[axis]; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 466820353b9..8ed134c7fd1 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -3961,9 +3961,10 @@ static int view_axis_exec(bContext *C, wmOperator *op) Object *obact = CTX_data_active_object(C); if (obact != NULL) { float twmat[3][3]; + ViewLayer *view_layer = CTX_data_view_layer(C); Object *obedit = CTX_data_edit_object(C); /* same as transform gizmo when normal is set */ - ED_getTransformOrientationMatrix(C, obact, obedit, V3D_AROUND_ACTIVE, twmat); + ED_getTransformOrientationMatrix(view_layer, v3d, obact, obedit, V3D_AROUND_ACTIVE, twmat); align_quat = align_quat_buf; mat3_to_quat(align_quat, twmat); invert_qt_normalized(align_quat); diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 279dca9731d..8dc4f107837 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -674,7 +674,7 @@ int ED_transform_calc_gizmo_stats(const bContext *C, if (ob) { float mat[3][3]; ED_transform_calc_orientation_from_type_ex( - C, mat, scene, rv3d, ob, obedit, orient_index, pivot_point); + scene, view_layer, v3d, rv3d, ob, obedit, orient_index, pivot_point, mat); copy_m4_m3(rv3d->twmat, mat); } diff --git a/source/blender/editors/transform/transform_mode.c b/source/blender/editors/transform/transform_mode.c index 8df95222fa1..b9fb8a86752 100644 --- a/source/blender/editors/transform/transform_mode.c +++ b/source/blender/editors/transform/transform_mode.c @@ -1232,14 +1232,24 @@ void transform_mode_default_modal_orientation_set(TransInfo *t, int type) return; } + View3D *v3d = NULL; RegionView3D *rv3d = NULL; if ((type == V3D_ORIENT_VIEW) && (t->spacetype == SPACE_VIEW3D) && t->region && (t->region->regiontype == RGN_TYPE_WINDOW)) { + v3d = t->view; rv3d = t->region->regiondata; } t->orient[O_DEFAULT].type = ED_transform_calc_orientation_from_type_ex( - NULL, t->orient[O_DEFAULT].matrix, NULL, rv3d, NULL, NULL, type, 0); + t->scene, + t->view_layer, + v3d, + rv3d, + NULL, + NULL, + type, + V3D_AROUND_CENTER_BOUNDS, + t->orient[O_DEFAULT].matrix); if (t->orient_curr == O_DEFAULT) { /* Update Orientation. */ diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index 33f4b06eb0e..1e3acdf1071 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -490,13 +490,14 @@ void ED_transform_calc_orientation_from_type(const bContext *C, float r_mat[3][3 Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Object *obedit = CTX_data_edit_object(C); + View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = region->regiondata; Object *ob = OBACT(view_layer); const short orient_index = BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT); const int pivot_point = scene->toolsettings->transform_pivot_point; ED_transform_calc_orientation_from_type_ex( - C, r_mat, scene, rv3d, ob, obedit, orient_index, pivot_point); + scene, view_layer, v3d, rv3d, ob, obedit, orient_index, pivot_point, r_mat); } /** @@ -508,15 +509,15 @@ void ED_transform_calc_orientation_from_type(const bContext *C, float r_mat[3][3 * - #V3D_ORIENT_LOCAL may contain shear from non-uniform scale in parent/child relationships. * - #V3D_ORIENT_CUSTOM may have been created from #V3D_ORIENT_LOCAL. */ -short ED_transform_calc_orientation_from_type_ex(const bContext *C, - float r_mat[3][3], - /* extra args (can be accessed from context) */ - Scene *scene, - RegionView3D *rv3d, +short ED_transform_calc_orientation_from_type_ex(const Scene *scene, + ViewLayer *view_layer, + const View3D *v3d, + const RegionView3D *rv3d, Object *ob, Object *obedit, const short orientation_index, - const int pivot_point) + const int pivot_point, + float r_mat[3][3]) { switch (orientation_index) { case V3D_ORIENT_GIMBAL: { @@ -528,7 +529,7 @@ short ED_transform_calc_orientation_from_type_ex(const bContext *C, } case V3D_ORIENT_NORMAL: { if (obedit || (ob && ob->mode & OB_MODE_POSE)) { - ED_getTransformOrientationMatrix(C, ob, obedit, pivot_point, r_mat); + ED_getTransformOrientationMatrix(view_layer, v3d, ob, obedit, pivot_point, r_mat); break; } /* No break we define 'normal' as 'local' in Object mode. */ @@ -541,7 +542,7 @@ short ED_transform_calc_orientation_from_type_ex(const bContext *C, * use the active pones axis for display T33575, this works as expected on a single * bone and users who select many bones will understand what's going on and what local * means when they start transforming. */ - ED_getTransformOrientationMatrix(C, ob, obedit, pivot_point, r_mat); + ED_getTransformOrientationMatrix(view_layer, v3d, ob, obedit, pivot_point, r_mat); } else { transform_orientations_create_from_axis(r_mat, UNPACK3(ob->obmat)); @@ -604,9 +605,11 @@ short transform_orientation_matrix_get(bContext *C, Object *ob = CTX_data_active_object(C); Object *obedit = CTX_data_edit_object(C); Scene *scene = t->scene; + View3D *v3d = NULL; RegionView3D *rv3d = NULL; if ((t->spacetype == SPACE_VIEW3D) && t->region && (t->region->regiontype == RGN_TYPE_WINDOW)) { + v3d = t->view; rv3d = t->region->regiondata; if (ob && (ob->mode & OB_MODE_ALL_WEIGHT_PAINT) && !(t->options & CTX_PAINT_CURVE)) { @@ -619,15 +622,7 @@ short transform_orientation_matrix_get(bContext *C, } short r_orient_index = ED_transform_calc_orientation_from_type_ex( - C, - r_spacemtx, - /* extra args (can be accessed from context) */ - scene, - rv3d, - ob, - obedit, - orient_index, - t->around); + scene, t->view_layer, v3d, rv3d, ob, obedit, orient_index, t->around, r_spacemtx); if (rv3d && (t->options & CTX_PAINT_CURVE)) { /* Screen space in the 3d region. */ @@ -757,15 +752,14 @@ static uint bm_mesh_faces_select_get_n(BMesh *bm, BMVert **elems, const uint n) } #endif -int getTransformOrientation_ex(const bContext *C, +int getTransformOrientation_ex(ViewLayer *view_layer, + const View3D *v3d, struct Object *ob, struct Object *obedit, float normal[3], float plane[3], const short around) { - ViewLayer *view_layer = CTX_data_view_layer(C); - View3D *v3d = CTX_wm_view3d(C); int result = ORIENTATION_NONE; const bool activeOnly = (around == V3D_AROUND_ACTIVE); @@ -1296,12 +1290,16 @@ int getTransformOrientation(const bContext *C, float normal[3], float plane[3]) /* dummy value, not V3D_AROUND_ACTIVE and not V3D_AROUND_LOCAL_ORIGINS */ short around = V3D_AROUND_CENTER_BOUNDS; - return getTransformOrientation_ex(C, obact, obedit, normal, plane, around); + ViewLayer *view_layer = CTX_data_view_layer(C); + View3D *v3d = CTX_wm_view3d(C); + + return getTransformOrientation_ex(view_layer, v3d, obact, obedit, normal, plane, around); } -void ED_getTransformOrientationMatrix(const bContext *C, - struct Object *ob, - struct Object *obedit, +void ED_getTransformOrientationMatrix(ViewLayer *view_layer, + const View3D *v3d, + Object *ob, + Object *obedit, const short around, float r_orientation_mat[3][3]) { @@ -1310,7 +1308,7 @@ void ED_getTransformOrientationMatrix(const bContext *C, int type; - type = getTransformOrientation_ex(C, ob, obedit, normal, plane, around); + type = getTransformOrientation_ex(view_layer, v3d, ob, obedit, normal, plane, around); /* Fallback, when the plane can't be calculated. */ if (ORIENTATION_USE_PLANE(type) && is_zero_v3(plane)) { diff --git a/source/blender/editors/transform/transform_orientations.h b/source/blender/editors/transform/transform_orientations.h index de8c9b165c1..1da369c8307 100644 --- a/source/blender/editors/transform/transform_orientations.h +++ b/source/blender/editors/transform/transform_orientations.h @@ -58,7 +58,8 @@ enum { }; #define ORIENTATION_USE_PLANE(ty) ELEM(ty, ORIENTATION_NORMAL, ORIENTATION_EDGE, ORIENTATION_FACE) -int getTransformOrientation_ex(const struct bContext *C, +int getTransformOrientation_ex(ViewLayer *view_layer, + const View3D *v3d, struct Object *ob, struct Object *obedit, float normal[3], |