Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_snap.c
| Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
| #include "view3d_intern.h" | #include "view3d_intern.h" | ||||
| static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]); | static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]); | ||||
| static bool snap_calc_active_center(bContext *C, const bool select_only, float r_center[3]); | static bool snap_calc_active_center(bContext *C, const bool select_only, float r_center[3]); | ||||
| /* *********************** operators ******************** */ | /* *********************** operators ******************** */ | ||||
| /** Snaps every individual object center to its nearest point on the grid. **/ | /** Snaps every individual object center to its nearest point on the grid. */ | ||||
| static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op)) | static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); | ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| RegionView3D *rv3d = CTX_wm_region_data(C); | RegionView3D *rv3d = CTX_wm_region_data(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| ▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | |||||
| /* *************************************************** */ | /* *************************************************** */ | ||||
| /** Snaps the selection as a whole (use_offset=true) or each selected object to the given location. | /** Snaps the selection as a whole (use_offset=true) or each selected object to the given location. | ||||
| * | * | ||||
| * \param snap_target_global: a location in global space to snap to (eg. 3D cursor or active object). | * \param snap_target_global: a location in global space to snap to (eg. 3D cursor or active object). | ||||
| * \param use_offset: if the selected objects should maintain their relative offsets and be snapped by the selection | * \param use_offset: if the selected objects should maintain their relative offsets and be snapped by the selection | ||||
| * pivot point (median, active), or if every object origin should be snapped to the given location. | * pivot point (median, active), or if every object origin should be snapped to the given location. | ||||
| **/ | */ | ||||
| static int snap_selected_to_location(bContext *C, const float snap_target_global[3], const bool use_offset) | static int snap_selected_to_location(bContext *C, const float snap_target_global[3], const bool use_offset) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| Object *obact = CTX_data_active_object(C); | Object *obact = CTX_data_active_object(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| TransVertStore tvs = {NULL}; | TransVertStore tvs = {NULL}; | ||||
| ▲ Show 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | void VIEW3D_OT_snap_selected_to_cursor(wmOperatorType *ot) | ||||
| /* rna */ | /* rna */ | ||||
| RNA_def_boolean( | RNA_def_boolean( | ||||
| ot->srna, "use_offset", 1, "Offset", | ot->srna, "use_offset", 1, "Offset", | ||||
| "If the selection should be snapped as a whole or by each object center"); | "If the selection should be snapped as a whole or by each object center"); | ||||
| } | } | ||||
| /* *************************************************** */ | /* *************************************************** */ | ||||
| /** Snaps each selected object to the location of the active selected object. **/ | /** Snaps each selected object to the location of the active selected object. */ | ||||
| static int snap_selected_to_active_exec(bContext *C, wmOperator *op) | static int snap_selected_to_active_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| float snap_target_global[3]; | float snap_target_global[3]; | ||||
| if (snap_calc_active_center(C, false, snap_target_global) == false) { | if (snap_calc_active_center(C, false, snap_target_global) == false) { | ||||
| BKE_report(op->reports, RPT_ERROR, "No active element found!"); | BKE_report(op->reports, RPT_ERROR, "No active element found!"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| Show All 14 Lines | void VIEW3D_OT_snap_selected_to_active(wmOperatorType *ot) | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; | ||||
| } | } | ||||
| /* *************************************************** */ | /* *************************************************** */ | ||||
| /** Snaps the 3D cursor location to its nearest point on the grid. **/ | /** Snaps the 3D cursor location to its nearest point on the grid. */ | ||||
| static int snap_curs_to_grid_exec(bContext *C, wmOperator *UNUSED(op)) | static int snap_curs_to_grid_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| RegionView3D *rv3d = CTX_wm_region_data(C); | RegionView3D *rv3d = CTX_wm_region_data(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| float gridf, *curs; | float gridf, *curs; | ||||
| gridf = ED_view3d_grid_view_scale(scene, v3d, rv3d, NULL); | gridf = ED_view3d_grid_view_scale(scene, v3d, rv3d, NULL); | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | for (object = tracking->objects.first; object; object = object->next) { | ||||
| } | } | ||||
| } | } | ||||
| if (ok) { | if (ok) { | ||||
| mid_v3_v3v3(r_vec, min, max); | mid_v3_v3v3(r_vec, min, max); | ||||
| } | } | ||||
| } | } | ||||
| /** Snaps the 3D cursor location to the median point of the selection. **/ | /** Snaps the 3D cursor location to the median point of the selection. */ | ||||
| static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) | static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); | ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| TransVertStore tvs = {NULL}; | TransVertStore tvs = {NULL}; | ||||
| ▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | void VIEW3D_OT_snap_cursor_to_active(wmOperatorType *ot) | ||||
| ot->poll = ED_operator_view3d_active; | ot->poll = ED_operator_view3d_active; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; | ||||
| } | } | ||||
| /* **************************************************** */ | /* **************************************************** */ | ||||
| /** Snaps the 3D cursor location to the origin. **/ | /** Snaps the 3D cursor location to the origin. */ | ||||
| static int snap_curs_to_center_exec(bContext *C, wmOperator *UNUSED(op)) | static int snap_curs_to_center_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| zero_v3(scene->cursor.location); | zero_v3(scene->cursor.location); | ||||
| DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); | DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); | ||||
| ▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines | |||||