Blender V4.3
view3d_snap.cc File Reference
#include "MEM_guardedalloc.h"
#include "DNA_armature_types.h"
#include "DNA_object_types.h"
#include "BLI_bounds.hh"
#include "BLI_math_matrix.h"
#include "BLI_math_matrix.hh"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_utildefines.h"
#include "BLI_vector.hh"
#include "BKE_action.hh"
#include "BKE_armature.hh"
#include "BKE_context.hh"
#include "BKE_crazyspace.hh"
#include "BKE_editmesh.hh"
#include "BKE_layer.hh"
#include "BKE_main.hh"
#include "BKE_mball.hh"
#include "BKE_object.hh"
#include "BKE_report.hh"
#include "BKE_scene.hh"
#include "BKE_tracking.h"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"
#include "WM_api.hh"
#include "WM_types.hh"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "ED_anim_api.hh"
#include "ED_curves.hh"
#include "ED_grease_pencil.hh"
#include "ED_keyframing.hh"
#include "ED_object.hh"
#include "ED_screen.hh"
#include "ED_transverts.hh"
#include "ANIM_action.hh"
#include "ANIM_bone_collections.hh"
#include "ANIM_keyframing.hh"
#include "view3d_intern.hh"

Go to the source code of this file.

Functions

Snap Cursor to Selection Operator
static bool snap_curs_to_sel_ex (bContext *C, const int pivot_point, float r_cursor[3])
 
static void bundle_midpoint (Scene *scene, Object *ob, float r_vec[3])
 
static int snap_curs_to_sel_exec (bContext *C, wmOperator *)
 
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 *)
 
void VIEW3D_OT_snap_cursor_to_active (wmOperatorType *ot)
 
Snap Selection to Grid Operator
static int snap_sel_to_grid_exec (bContext *C, wmOperator *op)
 
void VIEW3D_OT_snap_selected_to_grid (wmOperatorType *ot)
 
Snap Selection to Location (Utility)
static bool snap_selected_to_location (bContext *C, wmOperator *op, const float snap_target_global[3], const bool use_offset, const int pivot_point, const bool use_toolsettings)
 
bool ED_view3d_snap_selected_to_location (bContext *C, wmOperator *op, const float snap_target_global[3], const int pivot_point)
 
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 *)
 
void VIEW3D_OT_snap_cursor_to_grid (wmOperatorType *ot)
 
Snap Cursor to Center Operator
static int snap_curs_to_center_exec (bContext *C, wmOperator *)
 
void VIEW3D_OT_snap_cursor_to_center (wmOperatorType *ot)
 
Min/Max Object Vertices Utility
static std::optional< blender::Bounds< blender::float3 > > bounds_min_max_with_transform (const blender::float4x4 &transform, const blender::Span< blender::float3 > positions, const blender::IndexMask &mask)
 
bool ED_view3d_minmax_verts (const Scene *scene, Object *obedit, float r_min[3], float r_max[3])
 

Function Documentation

◆ bounds_min_max_with_transform()

static std::optional< blender::Bounds< blender::float3 > > bounds_min_max_with_transform ( const blender::float4x4 & transform,
const blender::Span< blender::float3 > positions,
const blender::IndexMask & mask )
static

Definition at line 999 of file view3d_snap.cc.

References init(), and blender::math::transform_point().

Referenced by ED_view3d_minmax_verts().

◆ bundle_midpoint()

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

◆ ED_view3d_minmax_verts()

◆ ED_view3d_snap_selected_to_location()

bool ED_view3d_snap_selected_to_location ( bContext * C,
wmOperator * op,
const float snap_target_global[3],
const int pivot_point )

◆ 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 922 of file view3d_snap.cc.

References blender::ed::object::calc_active_center(), and CTX_data_active_object().

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

◆ snap_curs_to_active_exec()

◆ snap_curs_to_center_exec()

static int snap_curs_to_center_exec ( bContext * C,
wmOperator *  )
static

Snaps the 3D cursor location to the origin and clears cursor rotation.

Definition at line 966 of file view3d_snap.cc.

References CTX_data_scene(), DEG_id_tag_update(), ID_RECALC_SYNC_TO_EVAL, blender::MatBase< float, 4, 4 >::identity(), NC_SPACE, ND_SPACE_VIEW3D, OPERATOR_FINISHED, and WM_event_add_notifier().

Referenced by VIEW3D_OT_snap_cursor_to_center().

◆ snap_curs_to_grid_exec()

static int snap_curs_to_grid_exec ( bContext * C,
wmOperator *  )
static

◆ snap_curs_to_sel_ex()

◆ snap_curs_to_sel_exec()

◆ snap_sel_to_grid_exec()

static int snap_sel_to_grid_exec ( bContext * C,
wmOperator * op )
static

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

Definition at line 68 of file view3d_snap.cc.

References add_v3_v3(), ANIM_bonecoll_is_visible_pchan(), ANIM_deselect_keys_in_animation_editors(), ANIM_get_keyingset_for_autokeying(), ANIM_KS_LOCATION_ID, blender::Vector< T, InlineBufferCapacity, Allocator >::append(), blender::animrig::autokeyframe_object(), blender::animrig::autokeyframe_pchan(), 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(), BMEditMesh::bm, BONE_CONNECTED, BONE_SELECTED, 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(), DEG_get_evaluated_view_layer(), DEG_get_original_object(), DEG_id_tag_update(), depsgraph, ED_transverts_check_obedit(), ED_transverts_create_from_obedit(), ED_transverts_free(), ED_transverts_update_obedit(), ED_view3d_grid_view_scale(), bPose::flag, floorf, FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN, FOREACH_SELECTED_EDITABLE_OBJECT_END, Object::id, ID_RECALC_GEOMETRY, ID_RECALC_TRANSFORM, invert_m3_m3(), invert_m4_m4(), blender::animrig::is_autokey_on(), LISTBASE_FOREACH, bPoseChannel::loc, Object::loc, TransVert::loc, mul_m3_v3(), mul_m4_v3(), NC_OBJECT, ND_TRANSFORM, OB_LOCK_LOCX, OB_LOCK_LOCY, OB_LOCK_LOCZ, OB_MESH, OBEDIT_FROM_OBACT, OBPOSE_FROM_OBACT, OPERATOR_FINISHED, Object::parent, Object::pose, POSE_DO_UNLOCK, POSE_LOCKED, bPoseChannel::protectflag, Object::protectflag, wmOperator::reports, SCE_XFORM_DATA_ORIGIN, SCE_XFORM_SKIP_CHILDREN, blender::ed::object::shape_key_report_if_locked(), blender::Vector< T, InlineBufferCapacity, Allocator >::size(), sub_v3_v3(), BMesh::totvertsel, TransVertStore::transverts, TransVertStore::transverts_tot, 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 647 of file view3d_snap.cc.

References BKE_report(), OPERATOR_CANCELLED, OPERATOR_FINISHED, 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 bool snap_selected_to_location ( bContext * C,
wmOperator * op,
const float snap_target_global[3],
const bool use_offset,
const int pivot_point,
const bool use_toolsettings )
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 307 of file view3d_snap.cc.

References add_v3_v3(), add_v3_v3v3(), ANIM_deselect_keys_in_animation_editors(), ANIM_get_keyingset_for_autokeying(), ANIM_KS_LOCATION_ID, blender::Vector< T, InlineBufferCapacity, Allocator >::append(), blender::animrig::autokeyframe_object(), blender::animrig::autokeyframe_pchan(), 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(), BMEditMesh::bm, BONE_CONNECTED, BONE_SELECTED, BONE_TRANSFORM, 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(), DEG_get_evaluated_object(), DEG_id_tag_update(), depsgraph, ED_transverts_check_obedit(), ED_transverts_create_from_obedit(), ED_transverts_free(), ED_transverts_update_obedit(), ListBase::first, FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN, FOREACH_SELECTED_EDITABLE_OBJECT_END, ID_RECALC_GEOMETRY, ID_RECALC_TRANSFORM, invert_m3_m3(), invert_m4_m4(), blender::animrig::is_autokey_on(), LISTBASE_FOREACH, TransVert::loc, mul_m3_m4m4(), mul_m3_v3(), mul_m4_v3(), mul_v3_m3v3(), mul_v3_m4v3(), NC_OBJECT, ND_TRANSFORM, OB_DONE, OB_LOCK_LOCX, OB_LOCK_LOCY, OB_LOCK_LOCZ, OB_MESH, Main::objects, OBPOSE_FROM_OBACT, Object::parent, PBONE_VISIBLE, POSE_DO_UNLOCK, POSE_LOCKED, wmOperator::reports, SCE_XFORM_DATA_ORIGIN, SCE_XFORM_SKIP_CHILDREN, blender::ed::object::shape_key_report_if_locked(), snap_calc_active_center(), snap_curs_to_sel_ex(), sub_v3_v3(), sub_v3_v3v3(), BMesh::totvertsel, TransVertStore::transverts, TransVertStore::transverts_tot, Object::type, V3D_AROUND_ACTIVE, and WM_event_add_notifier().

Referenced by ED_view3d_snap_selected_to_location(), snap_selected_to_active_exec(), and snap_selected_to_cursor_exec().

◆ VIEW3D_OT_snap_cursor_to_active()

◆ VIEW3D_OT_snap_cursor_to_center()

◆ VIEW3D_OT_snap_cursor_to_grid()

◆ VIEW3D_OT_snap_cursor_to_selected()

◆ VIEW3D_OT_snap_selected_to_active()

◆ VIEW3D_OT_snap_selected_to_cursor()

◆ VIEW3D_OT_snap_selected_to_grid()