Blender V5.0
view3d_snap.cc File Reference
#include "DNA_armature_types.h"
#include "DNA_object_types.h"
#include "DNA_pointcloud_types.h"
#include "BLI_bounds.hh"
#include "BLI_listbase.h"
#include "BLI_math_matrix.h"
#include "BLI_math_matrix.hh"
#include "BLI_math_rotation.h"
#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_pointcloud.hh"
#include "ED_screen.hh"
#include "ED_transverts.hh"
#include "ANIM_action.hh"
#include "ANIM_armature.hh"
#include "ANIM_bone_collections.hh"
#include "ANIM_keyframing.hh"
#include "ANIM_keyingsets.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 wmOperatorStatus 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 wmOperatorStatus snap_curs_to_active_exec (bContext *C, wmOperator *)
void VIEW3D_OT_snap_cursor_to_active (wmOperatorType *ot)
Snap Selection to Grid Operator
static wmOperatorStatus 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 pose_bone_runtime_flag_test_recursive (const bPoseChannel *pose_bone, int flag)
static bool snap_selected_to_location_rotation (bContext *C, wmOperator *op, const blender::float3 &target_loc_global, const View3DCursor *target_orientation_global, 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 target_loc_global[3], const int pivot_point)
Snap Selection to Cursor Operator
static wmOperatorStatus snap_selected_to_cursor_exec (bContext *C, wmOperator *op)
void VIEW3D_OT_snap_selected_to_cursor (wmOperatorType *ot)
Snap Selection to Active Operator
static wmOperatorStatus snap_selected_to_active_exec (bContext *C, wmOperator *op)
void VIEW3D_OT_snap_selected_to_active (wmOperatorType *ot)
Snap Cursor to Grid Operator
static wmOperatorStatus snap_curs_to_grid_exec (bContext *C, wmOperator *)
void VIEW3D_OT_snap_cursor_to_grid (wmOperatorType *ot)
Snap Cursor to Center Operator
static wmOperatorStatus 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()

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

◆ bundle_midpoint()

◆ ED_view3d_minmax_verts()

◆ ED_view3d_snap_selected_to_location()

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

◆ pose_bone_runtime_flag_test_recursive()

bool pose_bone_runtime_flag_test_recursive ( const bPoseChannel * pose_bone,
int flag )
static

◆ snap_calc_active_center()

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

References C, 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_rotation().

◆ snap_curs_to_active_exec()

◆ snap_curs_to_center_exec()

wmOperatorStatus snap_curs_to_center_exec ( bContext * C,
wmOperator *  )
static

◆ snap_curs_to_grid_exec()

◆ snap_curs_to_sel_ex()

◆ snap_curs_to_sel_exec()

◆ snap_sel_to_grid_exec()

wmOperatorStatus 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 72 of file view3d_snap.cc.

References add_v3_v3(), ANIM_bonecoll_is_visible_pchan(), ANIM_deselect_keys_in_animation_editors(), ANIM_KS_LOCATION_ID, blender::Vector< T, InlineBufferCapacity, Allocator >::append(), blender::Vector< T, InlineBufferCapacity, Allocator >::append_unchecked(), 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_protected_location_set(), BKE_object_where_is_calc_ex(), BKE_pchan_protected_location_set(), 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, C, 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(), blender::Vector< T, InlineBufferCapacity, Allocator >::data(), blender::ed::object::data_xform_container_create(), blender::ed::object::data_xform_container_destroy(), blender::ed::object::data_xform_container_item_ensure(), blender::ed::object::data_xform_container_update_all(), DEG_get_evaluated_view_layer(), DEG_get_original(), 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, blender::animrig::get_keyingset_for_autokeying(), Object::id, ID_RECALC_GEOMETRY, ID_RECALC_TRANSFORM, invert_m3_m3(), invert_m4_m4(), blender::animrig::is_autokey_on(), LISTBASE_FOREACH, TransVert::loc, mul_m3_v3(), mul_m4_v3(), NC_OBJECT, ND_TRANSFORM, OB_MESH, OBEDIT_FROM_OBACT, blender::ed::object::object_xform_skip_child_container_destroy(), blender::ed::object::object_xform_skip_child_container_update_all(), OBPOSE_FROM_OBACT, OPERATOR_FINISHED, Object::parent, Object::pose, POSE_DO_UNLOCK, POSE_LOCKED, POSE_SELECTED, 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(), Scene::toolsettings, BMesh::totvertsel, ToolSettings::transform_flag, TransVertStore::transverts, TransVertStore::transverts_tot, WM_event_add_notifier(), blender::ed::object::xform_skip_child_container_create(), and blender::ed::object::xform_skip_child_container_item_ensure_from_array().

Referenced by VIEW3D_OT_snap_selected_to_grid().

◆ snap_selected_to_active_exec()

wmOperatorStatus 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 773 of file view3d_snap.cc.

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

Referenced by VIEW3D_OT_snap_selected_to_active().

◆ snap_selected_to_cursor_exec()

◆ snap_selected_to_location_rotation()

bool snap_selected_to_location_rotation ( bContext * C,
wmOperator * op,
const blender::float3 & target_loc_global,
const View3DCursor * target_orientation_global,
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
target_loc_globala location in global space to snap to (eg. 3D cursor or active object).
target_orientation_globala 3d cursor which will provides rotation. When non-null objects are rotated to match the rotation of the 3d cursor, otherwise, keep their original rotation. Note that a more generic orientation parameter could be supported in future, but for now, only the 3d cursor is used.
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 314 of file view3d_snap.cc.

References add_v3_v3(), add_v3_v3v3(), ANIM_deselect_keys_in_animation_editors(), 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_flag_test_recursive(), BKE_object_get_parent_matrix(), BKE_object_pose_array_get(), BKE_object_protected_location_set(), BKE_object_protected_rotation_axisangle_set(), BKE_object_protected_rotation_euler_set(), BKE_object_protected_rotation_quaternion_set(), BKE_pchan_mat3_to_rot(), BKE_pchan_protected_location_set(), BKE_pchan_protected_rotation_axisangle_set(), BKE_pchan_protected_rotation_euler_set(), BKE_pchan_protected_rotation_quaternion_set(), BKE_scene_graph_evaluated_ensure(), BKE_view_layer_array_from_objects_in_edit_mode_unique_data(), BMEditMesh::bm, BONE_CONNECTED, blender::animrig::bone_is_visible(), C, copy_m3_m4(), copy_v3_v3(), copy_v4_v4(), 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(), blender::Vector< T, InlineBufferCapacity, Allocator >::data(), blender::ed::object::data_xform_container_create(), blender::ed::object::data_xform_container_destroy(), blender::ed::object::data_xform_container_item_ensure(), blender::ed::object::data_xform_container_update_all(), DEG_get_evaluated(), 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, blender::animrig::get_keyingset_for_autokeying(), ID_RECALC_GEOMETRY, ID_RECALC_TRANSFORM, blender::Vector< T, InlineBufferCapacity, Allocator >::index_range(), invert_m3_m3(), invert_m4_m4(), blender::animrig::is_autokey_on(), LISTBASE_FOREACH, TransVert::loc, mat3_normalized_to_quat(), mat3_to_axis_angle(), mat3_to_eulO(), mul_m3_m3m3(), mul_m3_m4m4(), mul_m3_v3(), mul_m4_v3(), mul_v3_m3v3(), mul_v3_m4v3(), NC_OBJECT, ND_TRANSFORM, OB_DONE, OB_MESH, blender::ed::object::object_xform_skip_child_container_destroy(), blender::ed::object::object_xform_skip_child_container_update_all(), Main::objects, OBPOSE_FROM_OBACT, Object::parent, pose_bone_runtime_flag_test_recursive(), POSE_DO_UNLOCK, POSE_LOCKED, POSE_RUNTIME_TRANSFORM, POSE_SELECTED, blender::MatBase< T, NumCol, NumRow, Alignment >::ptr(), wmOperator::reports, ROT_MODE_AXISANGLE, ROT_MODE_QUAT, View3DCursor::rotation_angle, View3DCursor::rotation_axis, View3DCursor::rotation_euler, View3DCursor::rotation_mode, View3DCursor::rotation_quaternion, SCE_XFORM_DATA_ORIGIN, SCE_XFORM_SKIP_CHILDREN, blender::ed::object::shape_key_report_if_locked(), blender::Vector< T, InlineBufferCapacity, Allocator >::size(), snap_calc_active_center(), snap_curs_to_sel_ex(), sub_v3_v3(), sub_v3_v3v3(), Scene::toolsettings, BMesh::totvertsel, ToolSettings::transform_flag, TransVertStore::transverts, TransVertStore::transverts_tot, Object::type, V3D_AROUND_ACTIVE, WM_event_add_notifier(), blender::ed::object::xform_skip_child_container_create(), blender::ed::object::xform_skip_child_container_item_ensure_from_array(), and blender::MatBase< float, 3, 3 >::zero().

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()

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)