Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_snap.c
| Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | |||||
| static void ApplySnapTranslation(TransInfo *t, float vec[3]); | static void ApplySnapTranslation(TransInfo *t, float vec[3]); | ||||
| static void ApplySnapRotation(TransInfo *t, float *vec); | static void ApplySnapRotation(TransInfo *t, float *vec); | ||||
| static void ApplySnapResize(TransInfo *t, float vec[2]); | static void ApplySnapResize(TransInfo *t, float vec[2]); | ||||
| /* static void CalcSnapGrid(TransInfo *t, float *vec); */ | /* static void CalcSnapGrid(TransInfo *t, float *vec); */ | ||||
| static void CalcSnapGeometry(TransInfo *t, float *vec); | static void CalcSnapGeometry(TransInfo *t, float *vec); | ||||
| static void TargetSnapMedian(TransInfo *t); | |||||
| static void TargetSnapCenter(TransInfo *t); | |||||
| static void TargetSnapClosest(TransInfo *t); | static void TargetSnapClosest(TransInfo *t); | ||||
| static void TargetSnapCenter(TransInfo *t); | |||||
| static void TargetSnapBBoxCenter(TransInfo *t); | |||||
| static void TargetSnapCursor(TransInfo *t); | |||||
| static void TargetSnapMedian(TransInfo *t); | |||||
| static void TargetSnapActive(TransInfo *t); | static void TargetSnapActive(TransInfo *t); | ||||
| static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3]); | static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3]); | ||||
| static float TranslationBetween(TransInfo *t, const float p1[3], const float p2[3]); | static float TranslationBetween(TransInfo *t, const float p1[3], const float p2[3]); | ||||
| static float ResizeBetween(TransInfo *t, const float p1[3], const float p2[3]); | static float ResizeBetween(TransInfo *t, const float p1[3], const float p2[3]); | ||||
| /****************** IMPLEMENTATIONS *********************/ | /****************** IMPLEMENTATIONS *********************/ | ||||
| ▲ Show 20 Lines • Show All 587 Lines • ▼ Show 20 Lines | static void setSnappingCallback(TransInfo *t) | ||||
| switch (t->tsnap.target) { | switch (t->tsnap.target) { | ||||
| case SCE_SNAP_TARGET_CLOSEST: | case SCE_SNAP_TARGET_CLOSEST: | ||||
| t->tsnap.targetSnap = TargetSnapClosest; | t->tsnap.targetSnap = TargetSnapClosest; | ||||
| break; | break; | ||||
| case SCE_SNAP_TARGET_CENTER: | case SCE_SNAP_TARGET_CENTER: | ||||
| t->tsnap.targetSnap = TargetSnapCenter; | t->tsnap.targetSnap = TargetSnapCenter; | ||||
| break; | break; | ||||
| case SCE_SNAP_TARGET_BBOXCENTER: | |||||
| t->tsnap.targetSnap = TargetSnapBBoxCenter; | |||||
| break; | |||||
| case SCE_SNAP_TARGET_CURSOR: | |||||
| t->tsnap.targetSnap = TargetSnapCursor; | |||||
| break; | |||||
| case SCE_SNAP_TARGET_MEDIAN: | case SCE_SNAP_TARGET_MEDIAN: | ||||
| t->tsnap.targetSnap = TargetSnapMedian; | t->tsnap.targetSnap = TargetSnapMedian; | ||||
| break; | break; | ||||
| case SCE_SNAP_TARGET_ACTIVE: | case SCE_SNAP_TARGET_ACTIVE: | ||||
| t->tsnap.targetSnap = TargetSnapActive; | t->tsnap.targetSnap = TargetSnapActive; | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 376 Lines • ▼ Show 20 Lines | static void TargetSnapCenter(TransInfo *t) | ||||
| if ((t->tsnap.status & TARGET_INIT) == 0) { | if ((t->tsnap.status & TARGET_INIT) == 0) { | ||||
| copy_v3_v3(t->tsnap.snapTarget, t->center_global); | copy_v3_v3(t->tsnap.snapTarget, t->center_global); | ||||
| TargetSnapOffset(t, NULL); | TargetSnapOffset(t, NULL); | ||||
| t->tsnap.status |= TARGET_INIT; | t->tsnap.status |= TARGET_INIT; | ||||
| } | } | ||||
| } | } | ||||
| static void TargetSnapCursor(TransInfo *t) | |||||
| { | |||||
| /* Only need to calculate once */ | |||||
| if ((t->tsnap.status & TARGET_INIT) == 0) { | |||||
| copy_v3_v3(t->tsnap.snapTarget, t->scene->cursor.location); | |||||
| TargetSnapOffset(t, NULL); | |||||
| t->tsnap.status |= TARGET_INIT; | |||||
| } | |||||
| } | |||||
| static void TargetSnapBBoxCenter(TransInfo *t) | |||||
| { | |||||
| /* Only need to calculate once */ | |||||
| if ((t->tsnap.status & TARGET_INIT) == 0) { | |||||
| float dist_closest = 0.0f; | |||||
| TransData *closest = NULL; | |||||
| float target[3]; | |||||
| zero_v3(target); | |||||
| int i_accum = 0; | |||||
| /* Object mode */ | |||||
| if (t->flag & T_OBJECT) { | |||||
| FOREACH_TRANS_DATA_CONTAINER(t, tc) { | |||||
| TransData *td; | |||||
| int i; | |||||
| for (td = tc->data, i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) { | |||||
| float v[3]; | |||||
| struct BoundBox *bb = BKE_object_boundbox_get(td->ob); | |||||
| if (bb) { | |||||
| mid_v3_v3v3(v, bb->vec[0], bb->vec[6]); | |||||
| mul_m4_v3(td->ext->obmat, v); | |||||
| } | |||||
| /* use element center otherwise */ | |||||
| else { | |||||
| copy_v3_v3(v, td->center); | |||||
| } | |||||
| if (tc->use_local_mat) { | |||||
| mul_m4_v3(tc->mat, v); | |||||
| } | |||||
| add_v3_v3(target, v); | |||||
| } | |||||
| i_accum += i; | |||||
| } | |||||
| mul_v3_v3fl(t->tsnap.snapTarget, target, 1.0f / i_accum); | |||||
| } | |||||
| else { | |||||
| float bmin[3], bmax[3]; | |||||
| INIT_MINMAX(bmin, bmax); | |||||
| FOREACH_TRANS_DATA_CONTAINER(t, tc) { | |||||
| float tc_min[3], tc_max[3]; | |||||
| INIT_MINMAX(tc_min, tc_max); | |||||
| TransData *td = tc->data; | |||||
| int i; | |||||
| for (i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) { | |||||
| minmax_v3v3_v3(tc_min, tc_max, td->center); | |||||
| } | |||||
| if (tc->use_local_mat) { | |||||
| mul_m4_v3(tc->mat, tc_min); | |||||
| mul_m4_v3(tc->mat, tc_max); | |||||
| } | |||||
| if (bmin[0] > tc_min[0]) bmin[0] = tc_min[0]; | |||||
| if (bmin[1] > tc_min[1]) bmin[1] = tc_min[1]; | |||||
| if (bmin[2] > tc_min[2]) bmin[2] = tc_min[2]; | |||||
| if (bmax[0] < tc_max[0]) bmax[0] = tc_max[0]; | |||||
| if (bmax[1] < tc_max[1]) bmax[1] = tc_max[1]; | |||||
| if (bmax[2] < tc_max[2]) bmax[2] = tc_max[2]; | |||||
| } | |||||
| mid_v3_v3v3(t->tsnap.snapTarget, bmin, bmax); | |||||
| } | |||||
| TargetSnapOffset(t, NULL); | |||||
| t->tsnap.status |= TARGET_INIT; | |||||
| } | |||||
| } | |||||
| static void TargetSnapActive(TransInfo *t) | static void TargetSnapActive(TransInfo *t) | ||||
| { | { | ||||
| /* Only need to calculate once */ | /* Only need to calculate once */ | ||||
| if ((t->tsnap.status & TARGET_INIT) == 0) { | if ((t->tsnap.status & TARGET_INIT) == 0) { | ||||
| if (calculateCenterActive(t, true, t->tsnap.snapTarget)) { | if (calculateCenterActive(t, true, t->tsnap.snapTarget)) { | ||||
| TargetSnapOffset(t, NULL); | TargetSnapOffset(t, NULL); | ||||
| t->tsnap.status |= TARGET_INIT; | t->tsnap.status |= TARGET_INIT; | ||||
| ▲ Show 20 Lines • Show All 470 Lines • Show Last 20 Lines | |||||