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 activeSnap(const TransInfo *t) | bool activeSnap(const TransInfo *t) | ||||
| { | { | ||||
| 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 activeSnap_SnappingIndividual(const TransInfo *t) | bool activeSnap_SnappingIndividual(const TransInfo *t) | ||||
| { | { | ||||
| if (activeSnap(t) && t->tsnap.mode & SCE_SNAP_MODE_FACE_NEAREST) { | if (activeSnap(t) && (t->tsnap.mode & SCE_SNAP_MODE_FACE_NEAREST)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (!t->tsnap.project) { | if (!t->tsnap.project && (t->tsnap.mode & SCE_SNAP_MODE_FACE_RAYCAST)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (!activeSnap(t) || (t->flag & T_NO_PROJECT)) { | if (!activeSnap(t) || (t->flag & T_NO_PROJECT)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (doForceIncrementSnap(t)) { | if (doForceIncrementSnap(t)) { | ||||
| ▲ Show 20 Lines • Show All 360 Lines • ▼ Show 20 Lines | for (int i = 0; i < tc->data_len; i++, td++) { | ||||
| if (td->flag & TD_SKIP) { | if (td->flag & TD_SKIP) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) { | if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* If both face ray-cast and face nearest methods are enabled, start with face ray-cast and | /* If both face raycast and face nearest methods are enabled, start with face ray-cast and | ||||
| * fallback to face nearest ray-cast does not hit. */ | * fallback to face nearest if raycast does not hit. */ | ||||
| bool hit = applyFaceProject(t, tc, td); | bool hit = false; | ||||
| if (t->tsnap.flag & SCE_SNAP_PROJECT) { | |||||
| /* Only raycast in this function if projecting individual elemenst. */ | |||||
| hit = applyFaceProject(t, tc, td); | |||||
| } | |||||
| if (!hit) { | if (!hit) { | ||||
| applyFaceNearest(t, tc, td); | applyFaceNearest(t, tc, td); | ||||
| } | } | ||||
| #if 0 /* TODO: support this? */ | #if 0 /* TODO: support this? */ | ||||
| constraintTransLim(t, td); | constraintTransLim(t, td); | ||||
| #endif | #endif | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 390 Lines • ▼ Show 20 Lines | if (RNA_property_boolean_get(op->ptr, prop)) { | ||||
| } | } | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "use_snap_selectable")) && | if ((prop = RNA_struct_find_property(op->ptr, "use_snap_selectable")) && | ||||
| RNA_property_is_set(op->ptr, prop)) { | RNA_property_is_set(op->ptr, prop)) { | ||||
| SET_FLAG_FROM_TEST(t->tsnap.target_select, | SET_FLAG_FROM_TEST(t->tsnap.target_select, | ||||
| RNA_property_boolean_get(op->ptr, prop), | RNA_property_boolean_get(op->ptr, prop), | ||||
| SCE_SNAP_TARGET_ONLY_SELECTABLE); | SCE_SNAP_TARGET_ONLY_SELECTABLE); | ||||
| } | } | ||||
| if ((prop = RNA_struct_find_property(op->ptr, "use_snap_retopology_mode")) && | |||||
| RNA_property_is_set(op->ptr, prop)) { | |||||
| SET_FLAG_FROM_TEST(t->tsnap.target_select, | |||||
| RNA_property_boolean_get(op->ptr, prop), | |||||
| SCE_SNAP_TARGET_RETOPOLOGY_MODE); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| /* use scene defaults only when transform is modal */ | /* use scene defaults only when transform is modal */ | ||||
| else if (t->flag & T_MODAL) { | else if (t->flag & T_MODAL) { | ||||
| if (transformModeUseSnap(t) && (t->tsnap.flag & SCE_SNAP)) { | if (transformModeUseSnap(t) && (t->tsnap.flag & SCE_SNAP)) { | ||||
| t->modifiers |= MOD_SNAP; | t->modifiers |= MOD_SNAP; | ||||
| } | } | ||||
| t->tsnap.target_select = SCE_SNAP_TARGET_ALL; | |||||
| t->tsnap.align = ((t->tsnap.flag & SCE_SNAP_ROTATE) != 0); | t->tsnap.align = ((t->tsnap.flag & SCE_SNAP_ROTATE) != 0); | ||||
| t->tsnap.project = ((t->tsnap.flag & SCE_SNAP_PROJECT) != 0); | t->tsnap.project = ((t->tsnap.flag & SCE_SNAP_PROJECT) != 0); | ||||
| t->tsnap.peel = ((t->tsnap.flag & SCE_SNAP_PROJECT) != 0); | t->tsnap.peel = ((t->tsnap.flag & SCE_SNAP_PROJECT) != 0); | ||||
| SET_FLAG_FROM_TEST(t->tsnap.target_select, | SET_FLAG_FROM_TEST(t->tsnap.target_select, | ||||
| (ts->snap_flag & SCE_SNAP_NOT_TO_ACTIVE), | (ts->snap_flag & SCE_SNAP_NOT_TO_ACTIVE), | ||||
| SCE_SNAP_TARGET_NOT_ACTIVE); | SCE_SNAP_TARGET_NOT_ACTIVE); | ||||
| SET_FLAG_FROM_TEST(t->tsnap.target_select, | SET_FLAG_FROM_TEST(t->tsnap.target_select, | ||||
| !(ts->snap_flag & SCE_SNAP_TO_INCLUDE_EDITED), | !(ts->snap_flag & SCE_SNAP_TO_INCLUDE_EDITED), | ||||
| SCE_SNAP_TARGET_NOT_EDITED); | SCE_SNAP_TARGET_NOT_EDITED); | ||||
| SET_FLAG_FROM_TEST(t->tsnap.target_select, | SET_FLAG_FROM_TEST(t->tsnap.target_select, | ||||
| !(ts->snap_flag & SCE_SNAP_TO_INCLUDE_NONEDITED), | !(ts->snap_flag & SCE_SNAP_TO_INCLUDE_NONEDITED), | ||||
| SCE_SNAP_TARGET_NOT_NONEDITED); | SCE_SNAP_TARGET_NOT_NONEDITED); | ||||
| SET_FLAG_FROM_TEST(t->tsnap.target_select, | SET_FLAG_FROM_TEST(t->tsnap.target_select, | ||||
| (ts->snap_flag & SCE_SNAP_TO_ONLY_SELECTABLE), | (ts->snap_flag & SCE_SNAP_TO_ONLY_SELECTABLE), | ||||
| SCE_SNAP_TARGET_ONLY_SELECTABLE); | SCE_SNAP_TARGET_ONLY_SELECTABLE); | ||||
| SET_FLAG_FROM_TEST(t->tsnap.target_select, | |||||
| (t->settings->snap_flag & SCE_SNAP_RETOPOLOGY_MODE), | |||||
| SCE_SNAP_TARGET_RETOPOLOGY_MODE); | |||||
| } | } | ||||
| t->tsnap.source_select = snap_source; | t->tsnap.source_select = snap_source; | ||||
| initSnappingMode(t); | initSnappingMode(t); | ||||
| } | } | ||||
| void freeSnapping(TransInfo *t) | void freeSnapping(TransInfo *t) | ||||
| ▲ Show 20 Lines • Show All 489 Lines • ▼ Show 20 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Snap Objects | /** \name Snap Objects | ||||
| * \{ */ | * \{ */ | ||||
| eSnapMode snapObjectsTransform( | eSnapMode 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; | ||||
| // filter mode to group snapping modes | |||||
| eSnapMode mode = t->tsnap.mode; | |||||
| mode &= ~(SCE_SNAP_MODE_FACE_NEAREST); | |||||
| if (t->tsnap.flag & SCE_SNAP_PROJECT) { | |||||
| mode &= ~(SCE_SNAP_MODE_FACE_RAYCAST); | |||||
| } | |||||
| const bool use_retopo_mode = (t->tsnap.target_select & SCE_SNAP_TARGET_RETOPOLOGY_MODE); | |||||
| const bool face_raycast_only = t->settings->snap_mode == SCE_SNAP_MODE_FACE_RAYCAST; | |||||
| const bool use_occlusion_test = use_retopo_mode || !face_raycast_only; | |||||
| return ED_transform_snap_object_project_view3d( | return ED_transform_snap_object_project_view3d( | ||||
| t->tsnap.object_context, | t->tsnap.object_context, | ||||
| t->depsgraph, | t->depsgraph, | ||||
| t->region, | t->region, | ||||
| t->view, | t->view, | ||||
| t->tsnap.mode, | mode, | ||||
| &(const struct SnapObjectParams){ | &(const struct SnapObjectParams){ | ||||
| .snap_target_select = t->tsnap.target_select, | .snap_target_select = t->tsnap.target_select, | ||||
| .edit_mode_type = (t->flag & T_EDIT) != 0 ? SNAP_GEOM_EDIT : SNAP_GEOM_FINAL, | .edit_mode_type = (t->flag & T_EDIT) != 0 ? SNAP_GEOM_EDIT : SNAP_GEOM_FINAL, | ||||
| .use_occlusion_test = t->settings->snap_mode != SCE_SNAP_MODE_FACE_RAYCAST, | .use_occlusion_test = use_occlusion_test, | ||||
| .use_backface_culling = t->tsnap.use_backface_culling, | .use_backface_culling = t->tsnap.use_backface_culling, | ||||
| }, | }, | ||||
| NULL, | NULL, | ||||
| mval, | mval, | ||||
| target, | target, | ||||
| dist_px, | dist_px, | ||||
| r_loc, | r_loc, | ||||
| r_no); | r_no); | ||||
| ▲ Show 20 Lines • Show All 377 Lines • Show Last 20 Lines | |||||