Blender  V2.93
view3d_snap.c File Reference
#include "MEM_guardedalloc.h"
#include "DNA_armature_types.h"
#include "DNA_object_types.h"
#include "BLI_array.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_context.h"
#include "BKE_editmesh.h"
#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_mball.h"
#include "BKE_object.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_tracking.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#include "WM_api.h"
#include "WM_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "ED_keyframing.h"
#include "ED_object.h"
#include "ED_screen.h"
#include "ED_transverts.h"
#include "view3d_intern.h"

Go to the source code of this file.

Functions

Snap Cursor to Selection Operator
static bool snap_curs_to_sel_ex (bContext *C, float cursor[3])
 
static void bundle_midpoint (Scene *scene, Object *ob, float r_vec[3])
 
static int snap_curs_to_sel_exec (bContext *C, wmOperator *UNUSED(op))
 
void VIEW3D_OT_snap_cursor_to_selected (wmOperatorType *ot)
 
Snap Cursor to Active Operator
static bool snap_calc_active_center (bContext *C, const bool select_only, float r_center[3])
 
static int snap_curs_to_active_exec (bContext *C, wmOperator *UNUSED(op))
 
void VIEW3D_OT_snap_cursor_to_active (wmOperatorType *ot)
 
Snap Selection to Grid Operator
static int snap_sel_to_grid_exec (bContext *C, wmOperator *UNUSED(op))
 
void VIEW3D_OT_snap_selected_to_grid (wmOperatorType *ot)
 
Snap Selection to Location (Utility)
static int snap_selected_to_location (bContext *C, const float snap_target_global[3], const bool use_offset)
 
Snap Selection to Cursor Operator
static int snap_selected_to_cursor_exec (bContext *C, wmOperator *op)
 
void VIEW3D_OT_snap_selected_to_cursor (wmOperatorType *ot)
 
Snap Selection to Active Operator
static int snap_selected_to_active_exec (bContext *C, wmOperator *op)
 
void VIEW3D_OT_snap_selected_to_active (wmOperatorType *ot)
 
Snap Cursor to Grid Operator
static int snap_curs_to_grid_exec (bContext *C, wmOperator *UNUSED(op))
 
void VIEW3D_OT_snap_cursor_to_grid (wmOperatorType *ot)
 
Snap Cursor to Center Operator
static int snap_curs_to_center_exec (bContext *C, wmOperator *UNUSED(op))
 
void VIEW3D_OT_snap_cursor_to_center (wmOperatorType *ot)
 
Min/Max Object Vertices Utility
bool ED_view3d_minmax_verts (Object *obedit, float r_min[3], float r_max[3])
 

Function Documentation

◆ bundle_midpoint()

static void bundle_midpoint ( Scene scene,
Object ob,
float  r_vec[3] 
)
static

◆ ED_view3d_minmax_verts()

bool ED_view3d_minmax_verts ( Object obedit,
float  r_min[3],
float  r_max[3] 
)

◆ snap_calc_active_center()

static bool snap_calc_active_center ( bContext C,
const bool  select_only,
float  r_center[3] 
)
static

Calculates the center position of the active object in global space.

Note: this could be exported to be a generic function. see: calculateCenterActive

Definition at line 901 of file view3d_snap.c.

References C, CTX_data_active_object(), ED_object_calc_active_center(), and NULL.

Referenced by snap_curs_to_active_exec(), snap_selected_to_active_exec(), and snap_selected_to_location().

◆ snap_curs_to_active_exec()

static int snap_curs_to_active_exec ( bContext C,
wmOperator UNUSEDop 
)
static

◆ snap_curs_to_center_exec()

static int snap_curs_to_center_exec ( bContext C,
wmOperator UNUSEDop 
)
static

◆ snap_curs_to_grid_exec()

static int snap_curs_to_grid_exec ( bContext C,
wmOperator UNUSEDop 
)
static

◆ snap_curs_to_sel_ex()

static bool snap_curs_to_sel_ex ( bContext C,
float  cursor[3] 
)
static

◆ snap_curs_to_sel_exec()

static int snap_curs_to_sel_exec ( bContext C,
wmOperator UNUSEDop 
)
static

◆ snap_sel_to_grid_exec()

static int snap_sel_to_grid_exec ( bContext C,
wmOperator UNUSEDop 
)
static

Snaps every individual object center to its nearest point on the grid.

Definition at line 69 of file view3d_snap.c.

References Freestyle::a, add_v3_v3(), ANIM_get_keyingset_for_autokeying(), ANIM_KS_LOCATION_ID, BKE_armature_loc_pose_to_bone(), BKE_editmesh_from_object(), BKE_object_pose_array_get(), BKE_object_where_is_calc_ex(), BKE_pose_channel_find_name(), BKE_scene_graph_evaluated_ensure(), BKE_view_layer_array_from_objects_in_edit_mode_unique_data, BLI_array_append, BLI_array_declare, BLI_array_len, BMEditMesh::bm, bPoseChannel::bone, BONE_CONNECTED, BONE_SELECTED, C, bPose::chanbase, copy_m3_m4(), copy_v3_v3(), CTX_data_active_object(), CTX_data_ensure_evaluated_depsgraph(), CTX_data_main(), CTX_data_scene(), CTX_data_view_layer(), CTX_wm_region(), CTX_wm_view3d(), Object::data, DEG_get_evaluated_view_layer(), DEG_get_original_object(), DEG_id_tag_update(), depsgraph, ED_autokeyframe_object(), ED_autokeyframe_pchan(), ED_object_data_xform_container_create(), ED_object_data_xform_container_destroy(), ED_object_data_xform_container_item_ensure(), ED_object_data_xform_container_update_all(), ED_object_xform_skip_child_container_create(), ED_object_xform_skip_child_container_destroy(), ED_object_xform_skip_child_container_item_ensure_from_array(), ED_object_xform_skip_child_container_update_all(), ED_transverts_check_obedit(), ED_transverts_create_from_obedit(), ED_transverts_free(), ED_transverts_update_obedit(), ED_view3d_grid_view_scale(), ListBase::first, bPose::flag, Bone::flag, floorf, FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN, FOREACH_SELECTED_EDITABLE_OBJECT_END, Object::id, ID_RECALC_GEOMETRY, ID_RECALC_TRANSFORM, Object::imat, invert_m3_m3(), invert_m4_m4(), Bone::layer, bArmature::layer, TransVert::loc, bPoseChannel::loc, Object::loc, MEM_freeN, MEM_malloc_arrayN, mul_m3_v3(), mul_m4_v3(), bPoseChannel::name, NC_OBJECT, ND_TRANSFORM, bPoseChannel::next, NULL, OB_LOCK_LOCX, OB_LOCK_LOCY, OB_LOCK_LOCZ, OB_MESH, OBEDIT_FROM_OBACT, Object::obmat, OBPOSE_FROM_OBACT, OPERATOR_FINISHED, Object::parent, Object::pose, POSE_DO_UNLOCK, POSE_LOCKED, bPoseChannel::pose_mat, bPoseChannel::protectflag, Object::protectflag, SCE_XFORM_DATA_ORIGIN, SCE_XFORM_SKIP_CHILDREN, scene, sub_v3_v3(), Scene::toolsettings, BMesh::totvertsel, ToolSettings::transform_flag, TransVertStore::transverts, TransVertStore::transverts_tot, Object::type, and WM_event_add_notifier().

Referenced by VIEW3D_OT_snap_selected_to_grid().

◆ snap_selected_to_active_exec()

static int snap_selected_to_active_exec ( bContext C,
wmOperator op 
)
static

Snaps each selected object to the location of the active selected object.

Definition at line 622 of file view3d_snap.c.

References BKE_report(), C, OPERATOR_CANCELLED, wmOperator::reports, RPT_ERROR, snap_calc_active_center(), and snap_selected_to_location().

Referenced by VIEW3D_OT_snap_selected_to_active().

◆ snap_selected_to_cursor_exec()

static int snap_selected_to_cursor_exec ( bContext C,
wmOperator op 
)
static

◆ snap_selected_to_location()

static int snap_selected_to_location ( bContext C,
const float  snap_target_global[3],
const bool  use_offset 
)
static

Snaps the selection as a whole (use_offset=true) or each selected object to the given location.

Parameters
snap_target_globala location in global space to snap to (eg. 3D cursor or active object).
use_offsetif 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.

Definition at line 313 of file view3d_snap.c.

References Freestyle::a, add_v3_v3(), add_v3_v3v3(), ANIM_get_keyingset_for_autokeying(), ANIM_KS_LOCATION_ID, BKE_armature_bone_flag_test_recursive(), BKE_armature_loc_pose_to_bone(), BKE_editmesh_from_object(), BKE_object_flag_test_recursive(), BKE_object_get_parent_matrix(), BKE_object_pose_array_get(), BKE_scene_graph_evaluated_ensure(), BKE_view_layer_array_from_objects_in_edit_mode_unique_data, BLI_array_append, BLI_array_declare, BLI_array_len, BMEditMesh::bm, bPoseChannel::bone, BONE_CONNECTED, BONE_SELECTED, BONE_TRANSFORM, C, bPose::chanbase, copy_m3_m4(), copy_v3_v3(), CTX_data_active_object(), CTX_data_depsgraph_pointer(), CTX_data_edit_object(), CTX_data_main(), CTX_data_scene(), CTX_data_view_layer(), CTX_wm_view3d(), Object::data, DEG_get_evaluated_object(), DEG_id_tag_update(), depsgraph, ED_autokeyframe_object(), ED_autokeyframe_pchan(), ED_object_data_xform_container_create(), ED_object_data_xform_container_destroy(), ED_object_data_xform_container_item_ensure(), ED_object_data_xform_container_update_all(), ED_object_xform_skip_child_container_create(), ED_object_xform_skip_child_container_destroy(), ED_object_xform_skip_child_container_item_ensure_from_array(), ED_object_xform_skip_child_container_update_all(), ED_transverts_check_obedit(), ED_transverts_create_from_obedit(), ED_transverts_free(), ED_transverts_update_obedit(), ListBase::first, bPose::flag, Bone::flag, FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN, FOREACH_SELECTED_EDITABLE_OBJECT_END, Object::id, ID_RECALC_GEOMETRY, ID_RECALC_TRANSFORM, Object::imat, invert_m3_m3(), invert_m4_m4(), TransVert::loc, bPoseChannel::loc, Object::loc, MEM_freeN, mul_m3_m4m4(), mul_m3_v3(), mul_m4_v3(), mul_v3_m3v3(), mul_v3_m4v3(), NC_OBJECT, ND_TRANSFORM, bPoseChannel::next, NULL, OB_DONE, OB_LOCK_LOCX, OB_LOCK_LOCY, OB_LOCK_LOCZ, OB_MESH, Main::objects, Object::obmat, OBPOSE_FROM_OBACT, OPERATOR_FINISHED, Bone::parent, Object::parent, Object::parentinv, PBONE_VISIBLE, Object::pose, POSE_DO_UNLOCK, POSE_LOCKED, bPoseChannel::pose_mat, bPoseChannel::protectflag, Object::protectflag, SCE_XFORM_DATA_ORIGIN, SCE_XFORM_SKIP_CHILDREN, scene, snap_calc_active_center(), snap_curs_to_sel_ex(), sub_v3_v3(), sub_v3_v3v3(), Scene::toolsettings, BMesh::totvertsel, ToolSettings::transform_flag, ToolSettings::transform_pivot_point, TransVertStore::transverts, TransVertStore::transverts_tot, Object::type, V3D_AROUND_ACTIVE, and WM_event_add_notifier().

Referenced by snap_selected_to_active_exec(), and snap_selected_to_cursor_exec().

◆ VIEW3D_OT_snap_cursor_to_active()

void VIEW3D_OT_snap_cursor_to_active ( wmOperatorType ot)

◆ VIEW3D_OT_snap_cursor_to_center()

void VIEW3D_OT_snap_cursor_to_center ( wmOperatorType ot)

◆ VIEW3D_OT_snap_cursor_to_grid()

void VIEW3D_OT_snap_cursor_to_grid ( wmOperatorType ot)

◆ VIEW3D_OT_snap_cursor_to_selected()

void VIEW3D_OT_snap_cursor_to_selected ( wmOperatorType ot)

◆ VIEW3D_OT_snap_selected_to_active()

void VIEW3D_OT_snap_selected_to_active ( wmOperatorType ot)

◆ VIEW3D_OT_snap_selected_to_cursor()

void VIEW3D_OT_snap_selected_to_cursor ( wmOperatorType ot)

◆ VIEW3D_OT_snap_selected_to_grid()

void VIEW3D_OT_snap_selected_to_grid ( wmOperatorType ot)