Blender V4.3
view3d_cursor_snap.cc File Reference

Snap cursor. More...

#include "DNA_object_types.h"
#include "BLI_listbase.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector_types.hh"
#include "BLI_rect.h"
#include "MEM_guardedalloc.h"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_layer.hh"
#include "BKE_main.hh"
#include "BKE_object.hh"
#include "BKE_scene.hh"
#include "BKE_screen.hh"
#include "GPU_immediate.hh"
#include "GPU_matrix.hh"
#include "ED_screen.hh"
#include "ED_transform.hh"
#include "ED_transform_snap_object_context.hh"
#include "ED_view3d.hh"
#include "UI_resources.hh"
#include "RNA_access.hh"
#include "DEG_depsgraph_query.hh"
#include "WM_api.hh"

Go to the source code of this file.

Classes

struct  SnapStateIntern
 
struct  SnapCursorDataIntern
 

Macros

#define STATE_INTERN_GET(state)
 
#define FADE(v)
 

Functions

static void v3d_cursor_poject_surface_normal (const float normal[3], const float obmat[4][4], float r_mat[3][3])
 
static bool mat3_align_axis_to_v3 (float mat[3][3], const int axis_align, const float v[3])
 
V3DSnapCursorStateED_view3d_cursor_snap_state_active_get ()
 
void ED_view3d_cursor_snap_state_active_set (V3DSnapCursorState *state)
 
static void v3d_cursor_snap_activate ()
 
static void v3d_cursor_snap_free ()
 
void ED_view3d_cursor_snap_state_default_set (V3DSnapCursorState *state)
 
V3DSnapCursorStateED_view3d_cursor_snap_state_create ()
 
void ED_view3d_cursor_snap_state_free (V3DSnapCursorState *state)
 
void ED_view3d_cursor_snap_state_prevpoint_set (V3DSnapCursorState *state, const float prev_point[3])
 
void ED_view3d_cursor_snap_data_update (V3DSnapCursorState *state, const bContext *C, const ARegion *region, const int x, const int y)
 
V3DSnapCursorDataED_view3d_cursor_snap_data_get ()
 
SnapObjectContextED_view3d_cursor_snap_context_ensure (Scene *scene)
 
Drawings
static void v3d_cursor_plane_draw_grid (const int resolution, const float scale, const float scale_fade, const float matrix[4][4], const int plane_axis, const float color[4])
 
static void v3d_cursor_plane_draw (const RegionView3D *rv3d, const int plane_axis, const float matrix[4][4])
 
static void cursor_box_draw (const float dimensions[3], uchar color[4])
 
static void cursor_point_draw (uint attr_pos, const float loc[3], const float size, eSnapMode snap_type, const uchar color[4])
 
void ED_view3d_cursor_snap_draw_util (RegionView3D *rv3d, const float source_loc[3], const float target_loc[3], const eSnapMode source_type, const eSnapMode target_type, const uchar source_color[4], const uchar target_color[4])
 
Event State
static bool v3d_cursor_eventstate_has_changed (SnapCursorDataIntern *data_intern, V3DSnapCursorState *state, const int x, const int y, uint8_t event_modifier)
 
static void v3d_cursor_eventstate_save_xy (SnapCursorDataIntern *cursor_snap, const int x, const int y)
 
static void v3d_cursor_eventstate_save_modifier (SnapCursorDataIntern *data_intern, uint8_t event_modifier)
 
static bool v3d_cursor_is_snap_invert (SnapCursorDataIntern *data_intern, uint8_t event_modifier)
 
Update
static eSnapMode v3d_cursor_snap_elements (ToolSettings *tool_settings)
 
static void v3d_cursor_snap_context_ensure (Scene *scene)
 
static bool v3d_cursor_snap_calc_plane ()
 
static void v3d_cursor_snap_update (V3DSnapCursorState *state, const bContext *C, Depsgraph *depsgraph, Scene *scene, const ARegion *region, View3D *v3d, int x, int y, uint8_t event_modifier)
 
Callbacks
static bool v3d_cursor_snap_poll_fn (bContext *C)
 
static void v3d_cursor_snap_draw_fn (bContext *C, int x, int y, void *)
 

Variables

static SnapCursorDataIntern g_data_intern
 
static const float eps_view_align = 1e-2f
 

Detailed Description

Snap cursor.

Definition in file view3d_cursor_snap.cc.

Macro Definition Documentation

◆ FADE

#define FADE ( v)
Value:
\
max_ff(0.0f, (1.0f - square_f(((len_v3v3(v, center) / scale_fade) + resolution_div) * 2.0f)))
MINLINE float square_f(float a)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ATTR_WARN_UNUSED_RESULT const BMVert * v

Referenced by v3d_cursor_plane_draw_grid().

◆ STATE_INTERN_GET

#define STATE_INTERN_GET ( state)
Value:
\
(SnapStateIntern *)((char *)state - offsetof(SnapStateIntern, snap_state))
#define offsetof(t, d)
static ulong state[N]

Definition at line 44 of file view3d_cursor_snap.cc.

Referenced by ED_view3d_cursor_snap_state_active_set(), and ED_view3d_cursor_snap_state_free().

Function Documentation

◆ cursor_box_draw()

◆ cursor_point_draw()

◆ ED_view3d_cursor_snap_context_ensure()

SnapObjectContext * ED_view3d_cursor_snap_context_ensure ( Scene * scene)

◆ ED_view3d_cursor_snap_data_get()

◆ ED_view3d_cursor_snap_data_update()

◆ ED_view3d_cursor_snap_draw_util()

◆ ED_view3d_cursor_snap_state_active_get()

◆ ED_view3d_cursor_snap_state_active_set()

◆ ED_view3d_cursor_snap_state_create()

◆ ED_view3d_cursor_snap_state_default_set()

◆ ED_view3d_cursor_snap_state_free()

◆ ED_view3d_cursor_snap_state_prevpoint_set()

◆ mat3_align_axis_to_v3()

static bool mat3_align_axis_to_v3 ( float mat[3][3],
const int axis_align,
const float v[3] )
static

Re-order mat so axis_align uses its own axis which is closest to v.

Definition at line 134 of file view3d_cursor_snap.cc.

References copy_m3_m3(), copy_v3_v3(), dot_v3v3(), fabsf, mod_i(), and v.

Referenced by v3d_cursor_snap_update().

◆ v3d_cursor_eventstate_has_changed()

static bool v3d_cursor_eventstate_has_changed ( SnapCursorDataIntern * data_intern,
V3DSnapCursorState * state,
const int x,
const int y,
uint8_t event_modifier )
static

◆ v3d_cursor_eventstate_save_modifier()

static void v3d_cursor_eventstate_save_modifier ( SnapCursorDataIntern * data_intern,
uint8_t event_modifier )
static

◆ v3d_cursor_eventstate_save_xy()

static void v3d_cursor_eventstate_save_xy ( SnapCursorDataIntern * cursor_snap,
const int x,
const int y )
static

Definition at line 510 of file view3d_cursor_snap.cc.

References cursor_snap, x, and y.

Referenced by v3d_cursor_snap_update().

◆ v3d_cursor_is_snap_invert()

◆ v3d_cursor_plane_draw()

static void v3d_cursor_plane_draw ( const RegionView3D * rv3d,
const int plane_axis,
const float matrix[4][4] )
static

◆ v3d_cursor_plane_draw_grid()

static void v3d_cursor_plane_draw_grid ( const int resolution,
const float scale,
const float scale_fade,
const float matrix[4][4],
const int plane_axis,
const float color[4] )
static

◆ v3d_cursor_poject_surface_normal()

static void v3d_cursor_poject_surface_normal ( const float normal[3],
const float obmat[4][4],
float r_mat[3][3] )
static

Calculate a 3x3 orientation matrix from the surface under the cursor.

Definition at line 101 of file view3d_cursor_snap.cc.

References copy_m3_m4(), copy_v3_v3(), dot_v3v3(), fabsf, negate_v3(), normalize_m3(), and orthogonalize_m3().

Referenced by v3d_cursor_snap_update().

◆ v3d_cursor_snap_activate()

◆ v3d_cursor_snap_calc_plane()

static bool v3d_cursor_snap_calc_plane ( )
static

◆ v3d_cursor_snap_context_ensure()

◆ v3d_cursor_snap_draw_fn()

◆ v3d_cursor_snap_elements()

◆ v3d_cursor_snap_free()

◆ v3d_cursor_snap_poll_fn()

◆ v3d_cursor_snap_update()

static void v3d_cursor_snap_update ( V3DSnapCursorState * state,
const bContext * C,
Depsgraph * depsgraph,
Scene * scene,
const ARegion * region,
View3D * v3d,
int x,
int y,
uint8_t event_modifier )
static

Definition at line 602 of file view3d_cursor_snap.cc.

References BKE_scene_orientation_get_index(), BKE_view_layer_active_object_get(), BKE_view_layer_synced_ensure(), BLI_assert, BLI_assert_msg, copy_m3_m3(), copy_m3_m4(), copy_m4_m4(), copy_v3_v3(), copy_v3_v3_int(), CTX_data_scene(), CTX_data_view_layer(), depsgraph, dot_v3v3(), ED_transform_calc_orientation_from_type_ex(), ED_transform_snap_object_project_view3d(), ED_transform_snap_object_project_view3d_ex(), ED_view3d_win_to_3d(), ED_view3d_win_to_3d_on_plane(), V3DSnapCursorData::elem_index, eps_view_align, fabsf, float, g_data_intern, V3DSnapCursorData::is_enabled, RegionView3D::is_persp, V3DSnapCursorData::is_snap_invert, is_zero_v3(), V3DSnapCursorData::loc, mat3_align_axis_to_v3(), negate_v3(), negate_v3_v3(), V3DSnapCursorData::nor, V3DSnapCursorData::obmat, orthogonalize_m3(), params, ToolSettings::plane_axis, ToolSettings::plane_depth, plane_from_point_normal_v3(), V3DSnapCursorData::plane_omat, ToolSettings::plane_orient, SCE_ORIENT_DEFAULT, SCE_SNAP, SCE_SNAP_TARGET_ALL, SCE_SNAP_TO_EDGE, SCE_SNAP_TO_EDGE_MIDPOINT, SCE_SNAP_TO_EDGE_PERPENDICULAR, SCE_SNAP_TO_FACE, SCE_SNAP_TO_GEOM, SCE_SNAP_TO_GRID, SCE_SNAP_TO_NONE, SCE_SNAP_TO_VERTEX, SnapCursorDataIntern::snap_context_v3d, SnapCursorDataIntern::snap_data, SnapCursorDataIntern::snap_elem_hidden, ToolSettings::snap_flag, SNAP_GEOM_CAGE, SNAP_GEOM_EDIT, SNAP_GEOM_FINAL, SNAP_OCCLUSION_ALWAYS, SNAP_OCCLUSION_AS_SEEM, SNAP_OCCLUSION_NEVER, state, sub_v3_v3v3(), V3DSnapCursorData::type_target, unit_m3(), ToolSettings::use_plane_axis_auto, v3d_cursor_eventstate_save_modifier(), v3d_cursor_eventstate_save_xy(), v3d_cursor_is_snap_invert(), v3d_cursor_poject_surface_normal(), v3d_cursor_snap_calc_plane(), v3d_cursor_snap_context_ensure(), v3d_cursor_snap_elements(), V3D_PLACE_DEPTH_CURSOR_VIEW, V3D_PLACE_DEPTH_SURFACE, V3D_PLACE_ORIENT_SURFACE, V3D_SNAPCURSOR_OCCLUSION_ALWAYS_TRUE, V3D_SNAPCURSOR_SNAP_EDIT_GEOM_CAGE, V3D_SNAPCURSOR_SNAP_EDIT_GEOM_FINAL, V3D_SNAPCURSOR_TOGGLE_ALWAYS_TRUE, RegionView3D::viewinv, and zero_v3().

Referenced by ED_view3d_cursor_snap_data_update(), and v3d_cursor_snap_draw_fn().

Variable Documentation

◆ eps_view_align

const float eps_view_align = 1e-2f
static

Dot products below this will be considered view aligned. In this case we can't usefully project the mouse cursor onto the plane.

Definition at line 96 of file view3d_cursor_snap.cc.

Referenced by v3d_cursor_snap_update().

◆ g_data_intern

SnapCursorDataIntern g_data_intern
static
Initial value:
= []() {
copy_v4_v4_uchar(data.state_default.target_color, blender::uchar4{255, 255, 255, 255});
copy_v4_v4_uchar(data.state_default.source_color, blender::uchar4{255, 255, 255, 128});
copy_v4_v4_uchar(data.state_default.color_box, blender::uchar4{255, 255, 255, 128});
copy_v3_fl(data.state_default.box_dimensions, 1.0f);
data.state_default.draw_point = true;
return data;
}()
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
MINLINE void copy_v3_fl(float r[3], float f)
@ V3D_SNAPCURSOR_SNAP_EDIT_GEOM_FINAL
Definition ED_view3d.hh:320
V3DSnapCursorState state_default
eV3DSnapCursor flag
Definition ED_view3d.hh:341

Definition at line 81 of file view3d_cursor_snap.cc.

Referenced by ED_view3d_cursor_snap_context_ensure(), ED_view3d_cursor_snap_data_get(), ED_view3d_cursor_snap_data_update(), ED_view3d_cursor_snap_state_active_get(), ED_view3d_cursor_snap_state_active_set(), ED_view3d_cursor_snap_state_create(), ED_view3d_cursor_snap_state_default_set(), ED_view3d_cursor_snap_state_free(), ED_view3d_cursor_snap_state_prevpoint_set(), v3d_cursor_snap_activate(), v3d_cursor_snap_calc_plane(), v3d_cursor_snap_context_ensure(), v3d_cursor_snap_draw_fn(), v3d_cursor_snap_free(), and v3d_cursor_snap_update().