Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/transform/transform_orientations.c')
-rw-r--r--source/blender/editors/transform/transform_orientations.c203
1 files changed, 115 insertions, 88 deletions
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c
index 32269e1bacc..cd170b144d8 100644
--- a/source/blender/editors/transform/transform_orientations.c
+++ b/source/blender/editors/transform/transform_orientations.c
@@ -397,14 +397,12 @@ int BIF_countTransformOrientation(const bContext *C)
return BLI_listbase_count(transform_orientations);
}
-bool applyTransformOrientation(const TransformOrientation *ts, float r_mat[3][3], char *r_name)
+void applyTransformOrientation(const TransformOrientation *ts, float r_mat[3][3], char *r_name)
{
if (r_name) {
BLI_strncpy(r_name, ts->name, MAX_NAME);
}
copy_m3_m3(r_mat, ts->mat);
-
- return true;
}
/* Updates all `BONE_TRANSFORM` flags.
@@ -438,82 +436,141 @@ static int armature_bone_transflags_update_recursive(bArmature *arm,
return total;
}
-/* Sets the matrix of the specified space orientation.
- * If the matrix cannot be obtained, an orientation different from the one
- * informed is returned */
-short transform_orientation_matrix_get(bContext *C,
- TransInfo *t,
- const short orientation,
- const float custom[3][3],
- float r_spacemtx[3][3])
+void ED_transform_calc_orientation_from_type(const bContext *C, float r_mat[3][3])
{
- Object *ob = CTX_data_active_object(C);
- Object *obedit = CTX_data_active_object(C);
+ ARegion *region = CTX_wm_region(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *obedit = CTX_data_edit_object(C);
+ RegionView3D *rv3d = region->regiondata;
+ Object *ob = OBACT(view_layer);
+ const short orientation_type = scene->orientation_slots[SCE_ORIENT_DEFAULT].type;
+ const short orientation_index_custom = scene->orientation_slots[SCE_ORIENT_DEFAULT].index_custom;
+ const int pivot_point = scene->toolsettings->transform_pivot_point;
- switch (orientation) {
- case V3D_ORIENT_GLOBAL:
- unit_m3(r_spacemtx);
- return V3D_ORIENT_GLOBAL;
+ ED_transform_calc_orientation_from_type_ex(
+ C, r_mat, scene, rv3d, ob, obedit, orientation_type, orientation_index_custom, pivot_point);
+}
- case V3D_ORIENT_GIMBAL:
- unit_m3(r_spacemtx);
- if (ob && gimbal_axis(ob, r_spacemtx)) {
+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,
+ Object *ob,
+ Object *obedit,
+ const short orientation_type,
+ int orientation_index_custom,
+ const int pivot_point)
+{
+ switch (orientation_type) {
+ case V3D_ORIENT_GLOBAL: {
+ unit_m3(r_mat);
+ return V3D_ORIENT_GLOBAL;
+ }
+ case V3D_ORIENT_GIMBAL: {
+ if (gimbal_axis(ob, r_mat)) {
return V3D_ORIENT_GIMBAL;
}
- ATTR_FALLTHROUGH; /* no gimbal fallthrough to normal */
-
- case V3D_ORIENT_NORMAL:
- if (obedit || (ob && ob->mode & OB_MODE_POSE)) {
- ED_getTransformOrientationMatrix(C, r_spacemtx, t->around);
+ /* if not gimbal, fall through to normal */
+ ATTR_FALLTHROUGH;
+ }
+ case V3D_ORIENT_NORMAL: {
+ if (obedit || ob->mode & OB_MODE_POSE) {
+ ED_getTransformOrientationMatrix(C, r_mat, pivot_point);
return V3D_ORIENT_NORMAL;
}
- ATTR_FALLTHROUGH; /* we define 'normal' as 'local' in Object mode */
-
- case V3D_ORIENT_LOCAL:
+ /* no break we define 'normal' as 'local' in Object mode */
+ ATTR_FALLTHROUGH;
+ }
+ case V3D_ORIENT_LOCAL: {
if (ob) {
- copy_m3_m4(r_spacemtx, ob->obmat);
- normalize_m3(r_spacemtx);
+ if (ob->mode & OB_MODE_POSE) {
+ /* each bone moves on its own local axis, but to avoid confusion,
+ * use the active pones axis for display [#33575], 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, r_mat, pivot_point);
+ }
+ else {
+ copy_m3_m4(r_mat, ob->obmat);
+ normalize_m3(r_mat);
+ }
return V3D_ORIENT_LOCAL;
}
- unit_m3(r_spacemtx);
+ unit_m3(r_mat);
return V3D_ORIENT_GLOBAL;
-
+ }
case V3D_ORIENT_VIEW: {
- float mat[3][3];
- if ((t->spacetype == SPACE_VIEW3D) && (t->region->regiontype == RGN_TYPE_WINDOW)) {
- RegionView3D *rv3d = t->region->regiondata;
- copy_m3_m4(mat, rv3d->viewinv);
- normalize_m3(mat);
+ if (rv3d != NULL) {
+ copy_m3_m4(r_mat, rv3d->viewinv);
+ normalize_m3(r_mat);
}
else {
- unit_m3(mat);
+ unit_m3(r_mat);
}
- copy_m3_m3(r_spacemtx, mat);
return V3D_ORIENT_VIEW;
}
- case V3D_ORIENT_CURSOR:
- BKE_scene_cursor_rot_to_mat3(&t->scene->cursor, r_spacemtx);
+ case V3D_ORIENT_CURSOR: {
+ BKE_scene_cursor_rot_to_mat3(&scene->cursor, r_mat);
return V3D_ORIENT_CURSOR;
-
- case V3D_ORIENT_CUSTOM_MATRIX:
- copy_m3_m3(r_spacemtx, custom);
- return V3D_ORIENT_CUSTOM_MATRIX;
-
+ }
+ case V3D_ORIENT_CUSTOM_MATRIX: {
+ /* Do nothing. */;
+ break;
+ }
case V3D_ORIENT_CUSTOM:
- default:
- BLI_assert(orientation >= V3D_ORIENT_CUSTOM);
- TransformOrientation *ts = BKE_scene_transform_orientation_find(
- t->scene, orientation - V3D_ORIENT_CUSTOM);
- if (applyTransformOrientation(ts, r_spacemtx, t->spacename)) {
- /* pass */
- }
- else {
- unit_m3(r_spacemtx);
- }
+ default: {
+ BLI_assert(orientation_type >= V3D_ORIENT_CUSTOM);
+ TransformOrientation *custom_orientation = BKE_scene_transform_orientation_find(
+ scene, orientation_index_custom);
+ applyTransformOrientation(custom_orientation, r_mat, NULL);
break;
+ }
}
- return orientation;
+ return orientation_type;
+}
+
+/* Sets the matrix of the specified space orientation.
+ * If the matrix cannot be obtained, an orientation different from the one
+ * informed is returned */
+short transform_orientation_matrix_get(bContext *C,
+ TransInfo *t,
+ const short orientation,
+ const float custom[3][3],
+ float r_spacemtx[3][3])
+{
+ if (orientation == V3D_ORIENT_CUSTOM_MATRIX) {
+ copy_m3_m3(r_spacemtx, custom);
+ return V3D_ORIENT_CUSTOM_MATRIX;
+ }
+
+ if ((t->spacetype == SPACE_VIEW3D) && (t->region->regiontype == RGN_TYPE_WINDOW)) {
+ Object *ob = CTX_data_active_object(C);
+ Object *obedit = CTX_data_active_object(C);
+ RegionView3D *rv3d = t->region->regiondata;
+ int orientation_index_custom = 0;
+
+ if (orientation >= V3D_ORIENT_CUSTOM) {
+ orientation_index_custom = orientation - V3D_ORIENT_CUSTOM;
+ }
+
+ return ED_transform_calc_orientation_from_type_ex(
+ C,
+ r_spacemtx,
+ /* extra args (can be accessed from context) */
+ t->scene,
+ rv3d,
+ ob,
+ obedit,
+ orientation,
+ orientation_index_custom,
+ t->around);
+ }
+
+ unit_m3(r_spacemtx);
+ return V3D_ORIENT_GLOBAL;
}
const char *transform_orientations_spacename_get(TransInfo *t, const short orient_type)
@@ -545,37 +602,7 @@ const char *transform_orientations_spacename_get(TransInfo *t, const short orien
void transform_orientations_current_set(TransInfo *t, const short orient_index)
{
const short orientation = t->orient[orient_index].type;
- const char *spacename;
- switch (orientation) {
- case V3D_ORIENT_GLOBAL:
- spacename = TIP_("global");
- break;
- case V3D_ORIENT_GIMBAL:
- spacename = TIP_("gimbal");
- break;
- case V3D_ORIENT_NORMAL:
- spacename = TIP_("normal");
- break;
- case V3D_ORIENT_LOCAL:
- spacename = TIP_("local");
- break;
- case V3D_ORIENT_VIEW:
- spacename = TIP_("view");
- break;
- case V3D_ORIENT_CURSOR:
- spacename = TIP_("cursor");
- break;
- case V3D_ORIENT_CUSTOM_MATRIX:
- spacename = TIP_("custom");
- break;
- case V3D_ORIENT_CUSTOM:
- default:
- BLI_assert(orientation >= V3D_ORIENT_CUSTOM);
- TransformOrientation *ts = BKE_scene_transform_orientation_find(
- t->scene, orientation - V3D_ORIENT_CUSTOM);
- spacename = ts->name;
- break;
- }
+ const char *spacename = transform_orientations_spacename_get(t, orientation);
BLI_strncpy(t->spacename, spacename, sizeof(t->spacename));
copy_m3_m3(t->spacemtx, t->orient[orient_index].matrix);