Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_snap.c
| Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | |||||
| bool validSnap(const TransInfo *t) | bool validSnap(const TransInfo *t) | ||||
| { | { | ||||
| return (t->tsnap.status & (POINT_INIT | TARGET_INIT)) == (POINT_INIT | TARGET_INIT) || | return (t->tsnap.status & (POINT_INIT | TARGET_INIT)) == (POINT_INIT | TARGET_INIT) || | ||||
| (t->tsnap.status & (MULTI_POINTS | TARGET_INIT)) == (MULTI_POINTS | TARGET_INIT); | (t->tsnap.status & (MULTI_POINTS | TARGET_INIT)) == (MULTI_POINTS | TARGET_INIT); | ||||
| } | } | ||||
| bool activeSnap(const TransInfo *t) | bool activeSnap(const TransInfo *t) | ||||
| { | { | ||||
| if (t->modifiers & MOD_EDIT_SNAPWITH) { | |||||
| return true; | |||||
| } | |||||
| return ((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP) || | return ((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP) || | ||||
| ((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP_INVERT); | ((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP_INVERT); | ||||
| } | } | ||||
| bool transformModeUseSnap(const TransInfo *t) | bool transformModeUseSnap(const TransInfo *t) | ||||
| { | { | ||||
| ToolSettings *ts = t->settings; | ToolSettings *ts = t->settings; | ||||
| if (t->mode == TFM_TRANSLATION) { | if (t->mode == TFM_TRANSLATION) { | ||||
| Show All 33 Lines | void drawSnapping(const struct bContext *C, TransInfo *t) | ||||
| UI_GetThemeColor3ubv(TH_SELECT, selectedCol); | UI_GetThemeColor3ubv(TH_SELECT, selectedCol); | ||||
| selectedCol[3] = 128; | selectedCol[3] = 128; | ||||
| UI_GetThemeColor3ubv(TH_ACTIVE, activeCol); | UI_GetThemeColor3ubv(TH_ACTIVE, activeCol); | ||||
| activeCol[3] = 192; | activeCol[3] = 192; | ||||
| if (t->spacetype == SPACE_VIEW3D) { | if (t->spacetype == SPACE_VIEW3D) { | ||||
| bool draw_target = (t->tsnap.status & TARGET_INIT) && | bool draw_target = (t->modifiers & MOD_EDIT_SNAPWITH) || | ||||
| (t->tsnap.status & TARGET_INIT) && | |||||
| (t->scene->toolsettings->snap_mode & SCE_SNAP_MODE_EDGE_PERPENDICULAR); | (t->scene->toolsettings->snap_mode & SCE_SNAP_MODE_EDGE_PERPENDICULAR); | ||||
| if (draw_target || validSnap(t)) { | if (draw_target || validSnap(t)) { | ||||
| const float *loc_cur = NULL; | const float *loc_cur = NULL; | ||||
| const float *loc_prev = NULL; | const float *loc_prev = NULL; | ||||
| const float *normal = NULL; | const float *normal = NULL; | ||||
| GPU_depth_test(GPU_DEPTH_NONE); | GPU_depth_test(GPU_DEPTH_NONE); | ||||
| ▲ Show 20 Lines • Show All 920 Lines • ▼ Show 20 Lines | if (t->tsnap.status & POINT_INIT) { | ||||
| } | } | ||||
| TargetSnapOffset(t, closest); | TargetSnapOffset(t, closest); | ||||
| t->tsnap.status |= TARGET_INIT; | t->tsnap.status |= TARGET_INIT; | ||||
| } | } | ||||
| } | } | ||||
| static void TargetSnapCustom(TransInfo *t) | |||||
| { | |||||
| t->tsnap.status |= TARGET_INIT; | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Snap Objects | /** \name Snap Objects | ||||
| * \{ */ | * \{ */ | ||||
| short snapObjectsTransform( | short snapObjectsTransform( | ||||
| TransInfo *t, const float mval[2], float *dist_px, float r_loc[3], float r_no[3]) | TransInfo *t, const float mval[2], float *dist_px, float r_loc[3], float r_no[3]) | ||||
| { | { | ||||
| float *target = (t->tsnap.status & TARGET_INIT) ? t->tsnap.snapTarget : t->center_global; | float *target = (t->tsnap.status & TARGET_INIT) ? t->tsnap.snapTarget : t->center_global; | ||||
| return ED_transform_snap_object_project_view3d_ex( | return ED_transform_snap_object_project_view3d_ex( | ||||
| t->tsnap.object_context, | t->tsnap.object_context, | ||||
| t->depsgraph, | t->depsgraph, | ||||
| t->settings->snap_mode, | t->settings->snap_mode, | ||||
| &(const struct SnapObjectParams){ | &(const struct SnapObjectParams){ | ||||
| .snap_select = t->tsnap.modeSelect, | .snap_select = t->modifiers & MOD_EDIT_SNAPWITH ? SNAP_ALL : t->tsnap.modeSelect, | ||||
| .use_object_edit_cage = (t->flag & T_EDIT) != 0, | .use_object_edit_cage = (t->flag & T_EDIT) != 0, | ||||
| .use_occlusion_test = t->settings->snap_mode != SCE_SNAP_MODE_FACE, | .use_occlusion_test = t->settings->snap_mode != SCE_SNAP_MODE_FACE, | ||||
| .use_backface_culling = t->tsnap.use_backface_culling, | .use_backface_culling = t->tsnap.use_backface_culling, | ||||
| }, | }, | ||||
| mval, | mval, | ||||
| target, | target, | ||||
| dist_px, | dist_px, | ||||
| r_loc, | r_loc, | ||||
| ▲ Show 20 Lines • Show All 399 Lines • ▼ Show 20 Lines | bool transform_snap_increment(TransInfo *t, float *val) | ||||
| } | } | ||||
| float increment_dist = (t->modifiers & MOD_PRECISION) ? t->snap[1] : t->snap[0]; | float increment_dist = (t->modifiers & MOD_PRECISION) ? t->snap[1] : t->snap[0]; | ||||
| snap_increment_apply(t, t->idx_max, increment_dist, val); | snap_increment_apply(t, t->idx_max, increment_dist, val); | ||||
| return true; | return true; | ||||
| } | } | ||||
| void tranform_snap_snapwith_init(TransInfo *t) | |||||
| { | |||||
| t->modifiers |= MOD_EDIT_SNAPWITH; | |||||
| t->tsnap.targetSnap = TargetSnapCustom; | |||||
| t->tsnap.targetSnap(t); | |||||
| restoreTransObjects(t); | |||||
| } | |||||
| void tranform_snap_snapwith_update(TransInfo *t) | |||||
| { | |||||
| BLI_assert(t->modifiers & MOD_EDIT_SNAPWITH); | |||||
| double current = PIL_check_seconds_timer(); | |||||
| /* Time base quirky code to go around findnearest slowness */ | |||||
| /* TODO: add exception for object mode, no need to slow it down then. */ | |||||
| if (current - t->tsnap.last >= 0.01) { | |||||
| t->tsnap.calcSnap(t, NULL); | |||||
| t->tsnap.last = current; | |||||
| } | |||||
| if (validSnap(t)) { | |||||
| copy_v3_v3(t->tsnap.snapTarget, t->tsnap.snapPoint); | |||||
| t->redraw |= TREDRAW_SOFT; | |||||
| } | |||||
| } | |||||
| void tranform_snap_snapwith_end(TransInfo *t) | |||||
| { | |||||
| BLI_assert(t->modifiers & MOD_EDIT_SNAPWITH); | |||||
| t->modifiers &= ~MOD_EDIT_SNAPWITH; | |||||
| /* Force a reinit with a current #t->mval. */ | |||||
| initMouseInput(t, &t->mouse, t->center2d, t->mval, false); | |||||
| applyMouseInput(t, &t->mouse, t->mval, t->values); | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Generic callbacks | /** \name Generic callbacks | ||||
| * \{ */ | * \{ */ | ||||
| float transform_snap_distance_len_squared_fn(TransInfo *UNUSED(t), | float transform_snap_distance_len_squared_fn(TransInfo *UNUSED(t), | ||||
| const float p1[3], | const float p1[3], | ||||
| const float p2[3]) | const float p2[3]) | ||||
| { | { | ||||
| return len_squared_v3v3(p1, p2); | return len_squared_v3v3(p1, p2); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||