Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_mode_translate.c
| Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "transform.h" | #include "transform.h" | ||||
| #include "transform_convert.h" | #include "transform_convert.h" | ||||
| #include "transform_mode.h" | #include "transform_mode.h" | ||||
| #include "transform_snap.h" | #include "transform_snap.h" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Transform (Translate) Custom Data | |||||
| * \{ */ | |||||
| /** | |||||
| * Custom data, stored in #TransInfo.custom.mode.data | |||||
| */ | |||||
| struct TranslateCustomData { | |||||
| /** Settings used in the last call to #applyTranslation. */ | |||||
| struct { | |||||
| bool apply_snap_align_rotation; | |||||
| bool is_valid_snapping_normal; | |||||
| } prev; | |||||
| }; | |||||
| /** \} */ | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Transform (Translation) | /** \name Transform (Translation) | ||||
| * \{ */ | * \{ */ | ||||
| static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_DRAW_STR]) | static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_DRAW_STR]) | ||||
| { | { | ||||
| size_t ofs = 0; | size_t ofs = 0; | ||||
| char tvec[NUM_STR_REP_LEN * 3]; | char tvec[NUM_STR_REP_LEN * 3]; | ||||
| char distvec[NUM_STR_REP_LEN]; | char distvec[NUM_STR_REP_LEN]; | ||||
| ▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | else { | ||||
| } | } | ||||
| sub_v3_v3v3(vec, point, t->tsnap.snapTarget); | sub_v3_v3v3(vec, point, t->tsnap.snapTarget); | ||||
| } | } | ||||
| } | } | ||||
| static void applyTranslationValue(TransInfo *t, const float vec[3]) | static void applyTranslationValue(TransInfo *t, const float vec[3]) | ||||
| { | { | ||||
| const bool apply_snap_align_rotation = usingSnappingNormal( | struct TranslateCustomData *custom_data = t->custom.mode.data; | ||||
| t); // && (t->tsnap.status & POINT_INIT); | |||||
| bool apply_snap_align_rotation = false; | |||||
| bool is_valid_snapping_normal = false; | |||||
| if (activeSnap(t) && usingSnappingNormal(t) && validSnappingNormal(t)) { | |||||
| apply_snap_align_rotation = true; | |||||
| is_valid_snapping_normal = true; | |||||
| } | |||||
| /* Check to see if this needs to be re-enabled. */ | |||||
| if (apply_snap_align_rotation == false) { | |||||
| if (t->flag & T_POINTS) { | |||||
| /* When transforming points, only use rotation when snapping is enabled | |||||
| * since re-applying translation without rotation removes rotation. */ | |||||
| } | |||||
| else { | |||||
| /* When transforming data that it's self stores rotation (objects, bones etc), | |||||
| * apply rotation if it was applied (with the snap normal) previously. | |||||
| * This is needed because failing to rotate will leave the rotation at the last | |||||
| * value used before snapping was disabled. */ | |||||
| if (custom_data->prev.apply_snap_align_rotation && | |||||
| custom_data->prev.is_valid_snapping_normal) { | |||||
| BLI_assert(is_valid_snapping_normal == false); | |||||
| apply_snap_align_rotation = true; | |||||
| } | |||||
| } | |||||
| } | |||||
| float tvec[3]; | float tvec[3]; | ||||
| /* The ideal would be "apply_snap_align_rotation" only when a snap point is found | /* The ideal would be "apply_snap_align_rotation" only when a snap point is found | ||||
| * so, maybe inside this function is not the best place to apply this rotation. | * so, maybe inside this function is not the best place to apply this rotation. | ||||
| * but you need "handle snapping rotation before doing the translation" (really?) */ | * but you need "handle snapping rotation before doing the translation" (really?) */ | ||||
| FOREACH_TRANS_DATA_CONTAINER (t, tc) { | FOREACH_TRANS_DATA_CONTAINER (t, tc) { | ||||
| float pivot[3]; | float pivot[3]; | ||||
| Show All 13 Lines | for (int i = 0; i < tc->data_len; i++, td++) { | ||||
| float rotate_offset[3] = {0}; | float rotate_offset[3] = {0}; | ||||
| bool use_rotate_offset = false; | bool use_rotate_offset = false; | ||||
| /* handle snapping rotation before doing the translation */ | /* handle snapping rotation before doing the translation */ | ||||
| if (apply_snap_align_rotation) { | if (apply_snap_align_rotation) { | ||||
| float mat[3][3]; | float mat[3][3]; | ||||
| if (validSnappingNormal(t)) { | if (is_valid_snapping_normal) { | ||||
| const float *original_normal; | const float *original_normal; | ||||
| /* In pose mode, we want to align normals with Y axis of bones... */ | /* In pose mode, we want to align normals with Y axis of bones... */ | ||||
| if (t->options & CTX_POSE_BONE) { | if (t->options & CTX_POSE_BONE) { | ||||
| original_normal = td->axismtx[1]; | original_normal = td->axismtx[1]; | ||||
| } | } | ||||
| else { | else { | ||||
| original_normal = td->axismtx[2]; | original_normal = td->axismtx[2]; | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | for (int i = 0; i < tc->data_len; i++, td++) { | ||||
| if (td->loc) { | if (td->loc) { | ||||
| add_v3_v3v3(td->loc, td->iloc, tvec); | add_v3_v3v3(td->loc, td->iloc, tvec); | ||||
| } | } | ||||
| constraintTransLim(t, td); | constraintTransLim(t, td); | ||||
| } | } | ||||
| } | } | ||||
| custom_data->prev.apply_snap_align_rotation = apply_snap_align_rotation; | |||||
| custom_data->prev.is_valid_snapping_normal = is_valid_snapping_normal; | |||||
| } | } | ||||
| static void applyTranslation(TransInfo *t, const int UNUSED(mval[2])) | static void applyTranslation(TransInfo *t, const int UNUSED(mval[2])) | ||||
| { | { | ||||
| char str[UI_MAX_DRAW_STR]; | char str[UI_MAX_DRAW_STR]; | ||||
| float global_dir[3] = {0.0f}; | float global_dir[3] = {0.0f}; | ||||
| if (t->flag & T_INPUT_IS_VALUES_FINAL) { | if (t->flag & T_INPUT_IS_VALUES_FINAL) { | ||||
| ▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | else { | ||||
| /* SPACE_GRAPH, SPACE_ACTION, etc. could use some time units, when we have them... */ | /* SPACE_GRAPH, SPACE_ACTION, etc. could use some time units, when we have them... */ | ||||
| t->num.unit_type[0] = B_UNIT_NONE; | t->num.unit_type[0] = B_UNIT_NONE; | ||||
| t->num.unit_type[1] = B_UNIT_NONE; | t->num.unit_type[1] = B_UNIT_NONE; | ||||
| t->num.unit_type[2] = B_UNIT_NONE; | t->num.unit_type[2] = B_UNIT_NONE; | ||||
| } | } | ||||
| transform_mode_default_modal_orientation_set( | transform_mode_default_modal_orientation_set( | ||||
| t, (t->options & CTX_CAMERA) ? V3D_ORIENT_VIEW : V3D_ORIENT_GLOBAL); | t, (t->options & CTX_CAMERA) ? V3D_ORIENT_VIEW : V3D_ORIENT_GLOBAL); | ||||
| struct TranslateCustomData *custom_data = MEM_callocN(sizeof(*custom_data), __func__); | |||||
| custom_data->prev.apply_snap_align_rotation = false; | |||||
| custom_data->prev.is_valid_snapping_normal = false; | |||||
| t->custom.mode.data = custom_data; | |||||
| t->custom.mode.use_free = true; | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||