Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_snap.c
| Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
| 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_ensure_evaluated_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); | ||||
| TransVertStore tvs = {NULL}; | TransVertStore tvs = {NULL}; | ||||
| TransVert *tv; | TransVert *tv; | ||||
| float gridf, imat[3][3], bmat[3][3], vec[3]; | float gridf, imat[3][3], bmat[3][3], vec[3]; | ||||
| ▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot) | ||||
| ot->description = "Snap selected item(s) to their nearest grid division"; | ot->description = "Snap selected item(s) to their nearest grid division"; | ||||
| ot->idname = "VIEW3D_OT_snap_selected_to_grid"; | ot->idname = "VIEW3D_OT_snap_selected_to_grid"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = snap_sel_to_grid_exec; | ot->exec = snap_sel_to_grid_exec; | ||||
| ot->poll = ED_operator_region_view3d_active; | ot->poll = ED_operator_region_view3d_active; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| /* *************************************************** */ | /* *************************************************** */ | ||||
| /** 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 | * \param snap_target_global: a location in global space to snap to | ||||
| * (eg. 3D cursor or active object). | * (eg. 3D cursor or active object). | ||||
| * \param use_offset: if the selected objects should maintain their relative offsets | * \param use_offset: if the selected objects should maintain their relative offsets | ||||
| * and be snapped by the selection pivot point (median, active), | * and be snapped by the selection pivot point (median, active), | ||||
| * or if every object origin should be snapped to the given location. | * or if every object origin should be snapped to the given location. | ||||
| */ | */ | ||||
| static int snap_selected_to_location(bContext *C, | static int snap_selected_to_location(bContext *C, | ||||
| const float snap_target_global[3], | const float snap_target_global[3], | ||||
| const bool use_offset) | const bool use_offset) | ||||
| { | { | ||||
| 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}; | ||||
| TransVert *tv; | TransVert *tv; | ||||
| float imat[3][3], bmat[3][3]; | float imat[3][3], bmat[3][3]; | ||||
| float center_global[3]; | float center_global[3]; | ||||
| ▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | for (ctx_ob = ctx_data_list.first; ctx_ob; ctx_ob = ctx_ob->next) { | ||||
| } | } | ||||
| sub_v3_v3(cursor_parent, ob->obmat[3]); | sub_v3_v3(cursor_parent, ob->obmat[3]); | ||||
| if (ob->parent) { | if (ob->parent) { | ||||
| float originmat[3][3], parentmat[4][4]; | float originmat[3][3], parentmat[4][4]; | ||||
| /* Use the evaluated object here because sometimes | /* Use the evaluated object here because sometimes | ||||
| * `ob->parent->runtime.curve_cache` is required. */ | * `ob->parent->runtime.curve_cache` is required. */ | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | |||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | ||||
| BKE_object_get_parent_matrix(ob_eval, ob_eval->parent, parentmat); | BKE_object_get_parent_matrix(ob_eval, ob_eval->parent, parentmat); | ||||
| mul_m3_m4m4(originmat, parentmat, ob->parentinv); | mul_m3_m4m4(originmat, parentmat, ob->parentinv); | ||||
| invert_m3_m3(imat, originmat); | invert_m3_m3(imat, originmat); | ||||
| mul_m3_v3(imat, cursor_parent); | mul_m3_v3(imat, cursor_parent); | ||||
| } | } | ||||
| if ((ob->protectflag & OB_LOCK_LOCX) == 0) { | if ((ob->protectflag & OB_LOCK_LOCX) == 0) { | ||||
| Show All 39 Lines | void VIEW3D_OT_snap_selected_to_cursor(wmOperatorType *ot) | ||||
| ot->description = "Snap selected item(s) to the 3D cursor"; | ot->description = "Snap selected item(s) to the 3D cursor"; | ||||
| ot->idname = "VIEW3D_OT_snap_selected_to_cursor"; | ot->idname = "VIEW3D_OT_snap_selected_to_cursor"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = snap_selected_to_cursor_exec; | ot->exec = snap_selected_to_cursor_exec; | ||||
| 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; | ||||
| /* rna */ | /* rna */ | ||||
| RNA_def_boolean(ot->srna, | RNA_def_boolean(ot->srna, | ||||
| "use_offset", | "use_offset", | ||||
| 1, | 1, | ||||
| "Offset", | "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"); | ||||
| } | } | ||||
| Show All 20 Lines | void VIEW3D_OT_snap_selected_to_active(wmOperatorType *ot) | ||||
| ot->description = "Snap selected item(s) to the active item"; | ot->description = "Snap selected item(s) to the active item"; | ||||
| ot->idname = "VIEW3D_OT_snap_selected_to_active"; | ot->idname = "VIEW3D_OT_snap_selected_to_active"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = snap_selected_to_active_exec; | ot->exec = snap_selected_to_active_exec; | ||||
| 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; | ||||
| } | } | ||||
| /* *************************************************** */ | /* *************************************************** */ | ||||
| /** 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); | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | static void bundle_midpoint(Scene *scene, Object *ob, float r_vec[3]) | ||||
| 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_ensure_evaluated_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}; | ||||
| TransVert *tv; | TransVert *tv; | ||||
| float bmat[3][3], vec[3], min[3], max[3], centroid[3]; | float bmat[3][3], vec[3], min[3], max[3], centroid[3]; | ||||
| int count = 0; | int count = 0; | ||||
| ▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | void VIEW3D_OT_snap_cursor_to_selected(wmOperatorType *ot) | ||||
| ot->description = "Snap 3D cursor to the middle of the selected item(s)"; | ot->description = "Snap 3D cursor to the middle of the selected item(s)"; | ||||
| ot->idname = "VIEW3D_OT_snap_cursor_to_selected"; | ot->idname = "VIEW3D_OT_snap_cursor_to_selected"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = snap_curs_to_sel_exec; | ot->exec = snap_curs_to_sel_exec; | ||||
| 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; | ||||
| } | } | ||||
| /* ********************************************** */ | /* ********************************************** */ | ||||
| /** Calculates the center position of the active object in global space. | /** Calculates the center position of the active object in global space. | ||||
| * | * | ||||
| * Note: this could be exported to be a generic function. | * Note: this could be exported to be a generic function. | ||||
| * see: calculateCenterActive | * see: calculateCenterActive | ||||
| Show All 30 Lines | void VIEW3D_OT_snap_cursor_to_active(wmOperatorType *ot) | ||||
| ot->description = "Snap 3D cursor to the active item"; | ot->description = "Snap 3D cursor to the active item"; | ||||
| ot->idname = "VIEW3D_OT_snap_cursor_to_active"; | ot->idname = "VIEW3D_OT_snap_cursor_to_active"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = snap_curs_to_active_exec; | ot->exec = snap_curs_to_active_exec; | ||||
| 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; | ||||
| } | } | ||||
| /* **************************************************** */ | /* **************************************************** */ | ||||
| /** Snaps the 3D cursor location to the origin and clears cursor rotation. */ | /** Snaps the 3D cursor location to the origin and clears cursor rotation. */ | ||||
| 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); | ||||
| ▲ Show 20 Lines • Show All 75 Lines • Show Last 20 Lines | |||||