Blender  V3.3
Classes | Macros | Typedefs | Functions | Variables
view3d_cursor_snap.c File Reference

Snap cursor. More...

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

Go to the source code of this file.

Classes

struct  SnapStateIntern
 
struct  SnapCursorDataIntern
 

Macros

#define STATE_INTERN_GET(state)    (SnapStateIntern *)((char *)state - offsetof(SnapStateIntern, snap_state))
 
#define FADE(v)    max_ff(0.0f, (1.0f - square_f(((len_v3v3(v, center) / scale_fade) + resolution_div) * 2.0f)))
 

Typedefs

typedef struct SnapStateIntern SnapStateIntern
 
typedef struct SnapCursorDataIntern SnapCursorDataIntern
 

Functions

static void v3d_cursor_poject_surface_normal (const float normal[3], const float obmat[4][4], float r_mat[3][3])
 
static bool v3d_cursor_snap_calc_incremental (Scene *scene, View3D *v3d, ARegion *region, const float co_relative[3], float co[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_get (void)
 
static void v3d_cursor_snap_activate (void)
 
static void v3d_cursor_snap_free (void)
 
void ED_view3d_cursor_snap_state_default_set (V3DSnapCursorState *state)
 
V3DSnapCursorStateED_view3d_cursor_snap_active (void)
 
void ED_view3d_cursor_snap_deactive (V3DSnapCursorState *state)
 
void ED_view3d_cursor_snap_prevpoint_set (V3DSnapCursorState *state, const float prev_point[3])
 
void ED_view3d_cursor_snap_data_update (V3DSnapCursorState *state, const bContext *C, const int x, const int y)
 
V3DSnapCursorDataED_view3d_cursor_snap_data_get ()
 
struct 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])
 
void ED_view3d_cursor_snap_draw_util (RegionView3D *rv3d, const float loc_prev[3], const float loc_curr[3], const float normal[3], const uchar color_line[4], const uchar color_point[4], const eSnapMode snap_elem_type)
 
Event State
static bool v3d_cursor_eventstate_has_changed (SnapCursorDataIntern *data_intern, V3DSnapCursorState *state, const wmWindowManager *wm, const int x, const int y)
 
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, const wmWindowManager *wm)
 
static bool v3d_cursor_is_snap_invert (SnapCursorDataIntern *data_intern, const wmWindowManager *wm)
 
Update
static eSnapMode v3d_cursor_snap_elements (V3DSnapCursorState *snap_state, Scene *scene)
 
static void v3d_cursor_snap_context_ensure (Scene *scene)
 
static bool v3d_cursor_snap_calc_plane (void)
 
static void v3d_cursor_snap_update (V3DSnapCursorState *state, const bContext *C, wmWindowManager *wm, Depsgraph *depsgraph, Scene *scene, ARegion *region, View3D *v3d, int x, int y)
 
Callbacks
static bool v3d_cursor_snap_poll_fn (bContext *C)
 
static void v3d_cursor_snap_draw_fn (bContext *C, int x, int y, void *UNUSED(customdata))
 

Variables

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

Detailed Description

Snap cursor.

Definition in file view3d_cursor_snap.c.

Macro Definition Documentation

◆ FADE

#define FADE (   v)     max_ff(0.0f, (1.0f - square_f(((len_v3v3(v, center) / scale_fade) + resolution_div) * 2.0f)))

◆ STATE_INTERN_GET

#define STATE_INTERN_GET (   state)     (SnapStateIntern *)((char *)state - offsetof(SnapStateIntern, snap_state))

Definition at line 40 of file view3d_cursor_snap.c.

Typedef Documentation

◆ SnapCursorDataIntern

◆ SnapStateIntern

Function Documentation

◆ cursor_box_draw()

static void cursor_box_draw ( const float  dimensions[3],
uchar  color[4] 
)
static

◆ ED_view3d_cursor_snap_active()

V3DSnapCursorState* ED_view3d_cursor_snap_active ( void  )

◆ ED_view3d_cursor_snap_context_ensure()

struct SnapObjectContext* ED_view3d_cursor_snap_context_ensure ( Scene scene)

◆ ED_view3d_cursor_snap_data_get()

V3DSnapCursorData* ED_view3d_cursor_snap_data_get ( void  )

◆ ED_view3d_cursor_snap_data_update()

void ED_view3d_cursor_snap_data_update ( V3DSnapCursorState state,
const bContext C,
const int  x,
const int  y 
)

◆ ED_view3d_cursor_snap_deactive()

void ED_view3d_cursor_snap_deactive ( V3DSnapCursorState state)

◆ ED_view3d_cursor_snap_draw_util()

void ED_view3d_cursor_snap_draw_util ( RegionView3D rv3d,
const float  loc_prev[3],
const float  loc_curr[3],
const float  normal[3],
const uchar  color_line[4],
const uchar  color_point[4],
const eSnapMode  snap_elem_type 
)

◆ ED_view3d_cursor_snap_prevpoint_set()

void ED_view3d_cursor_snap_prevpoint_set ( V3DSnapCursorState state,
const float  prev_point[3] 
)

◆ ED_view3d_cursor_snap_state_default_set()

void ED_view3d_cursor_snap_state_default_set ( V3DSnapCursorState state)

◆ ED_view3d_cursor_snap_state_get()

V3DSnapCursorState* ED_view3d_cursor_snap_state_get ( void  )

◆ 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 162 of file view3d_cursor_snap.c.

References copy_m3_m3(), copy_v3_v3(), dot_v3v3(), fabsf, mod_i(), offset, 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 wmWindowManager wm,
const int  x,
const int  y 
)
static

◆ v3d_cursor_eventstate_save_modifier()

static void v3d_cursor_eventstate_save_modifier ( SnapCursorDataIntern data_intern,
const wmWindowManager wm 
)
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 489 of file view3d_cursor_snap.c.

References cursor_snap, x, and y.

Referenced by v3d_cursor_snap_update().

◆ v3d_cursor_is_snap_invert()

static bool v3d_cursor_is_snap_invert ( SnapCursorDataIntern data_intern,
const wmWindowManager wm 
)
static

◆ 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 97 of file view3d_cursor_snap.c.

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

Referenced by v3d_cursor_snap_update().

◆ v3d_cursor_snap_activate()

static void v3d_cursor_snap_activate ( void  )
static

◆ v3d_cursor_snap_calc_incremental()

static bool v3d_cursor_snap_calc_incremental ( Scene scene,
View3D v3d,
ARegion region,
const float  co_relative[3],
float  co[3] 
)
static

Calculate 3D view incremental (grid) snapping.

Note
This could be moved to a public function.

Definition at line 132 of file view3d_cursor_snap.c.

References add_v3_v3(), ED_view3d_grid_view_scale(), mul_v3_fl(), NULL, SCE_SNAP_ABS_GRID, scene, ToolSettings::snap_flag, sub_v3_v3(), Scene::toolsettings, and UNLIKELY.

Referenced by v3d_cursor_snap_update().

◆ v3d_cursor_snap_calc_plane()

static bool v3d_cursor_snap_calc_plane ( void  )
static

◆ v3d_cursor_snap_context_ensure()

static void v3d_cursor_snap_context_ensure ( Scene scene)
static

◆ v3d_cursor_snap_draw_fn()

static void v3d_cursor_snap_draw_fn ( bContext C,
int  x,
int  y,
void UNUSEDcustomdata 
)
static

◆ v3d_cursor_snap_elements()

static eSnapMode v3d_cursor_snap_elements ( V3DSnapCursorState snap_state,
Scene scene 
)
static

◆ v3d_cursor_snap_free()

static void v3d_cursor_snap_free ( void  )
static

◆ v3d_cursor_snap_poll_fn()

static bool v3d_cursor_snap_poll_fn ( bContext C)
static

◆ v3d_cursor_snap_update()

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

Definition at line 583 of file view3d_cursor_snap.c.

References BKE_scene_orientation_get_index(), BLI_assert_msg, C, copy_m3_m3(), copy_m3_m4(), copy_m4_m4(), copy_v3_v3(), copy_v3_v3_int(), CTX_data_view_layer(), Scene::cursor, depsgraph, dot_v3v3(), ED_transform_calc_orientation_from_type_ex(), 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, g_data_intern, if(), V3DSnapCursorData::is_enabled, RegionView3D::is_persp, V3DSnapCursorData::is_snap_invert, is_zero_v3(), V3DSnapCursorData::loc, View3DCursor::location, mat3_align_axis_to_v3(), negate_v3(), negate_v3_v3(), V3DSnapCursorData::nor, NULL, OBACT, V3DSnapCursorData::obmat, orthogonalize_m3(), plane_from_point_normal_v3(), V3DSnapCursorData::plane_omat, ARegion::regiondata, SCE_ORIENT_DEFAULT, SCE_SNAP, SCE_SNAP_MODE_EDGE, SCE_SNAP_MODE_EDGE_MIDPOINT, SCE_SNAP_MODE_EDGE_PERPENDICULAR, SCE_SNAP_MODE_FACE_RAYCAST, SCE_SNAP_MODE_GEOM, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_NONE, SCE_SNAP_MODE_VERTEX, scene, SnapCursorDataIntern::snap_context_v3d, SnapCursorDataIntern::snap_data, V3DSnapCursorData::snap_elem, SnapCursorDataIntern::snap_elem_hidden, ToolSettings::snap_flag, SNAP_GEOM_CAGE, SNAP_GEOM_EDIT, SNAP_GEOM_FINAL, state, sub_v3_v3v3(), Scene::toolsettings, ToolSettings::transform_pivot_point, unit_m3(), v3d_cursor_eventstate_save_modifier(), v3d_cursor_eventstate_save_xy(), v3d_cursor_is_snap_invert(), v3d_cursor_poject_surface_normal(), v3d_cursor_snap_calc_incremental(), 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, x, y, 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 92 of file view3d_cursor_snap.c.

Referenced by v3d_cursor_snap_update().

◆ g_data_intern

SnapCursorDataIntern g_data_intern
static
Initial value:
= {
.state_default = {.flag = V3D_SNAPCURSOR_SNAP_EDIT_GEOM_FINAL,
.snap_elem_force = SCE_SNAP_MODE_GEOM,
.plane_axis = 2,
.color_point = {255, 255, 255, 255},
.color_line = {255, 255, 255, 128},
.color_box = {255, 255, 255, 128},
.box_dimensions = {1.0f, 1.0f, 1.0f},
.draw_point = true}}
@ SCE_SNAP_MODE_GEOM
@ V3D_SNAPCURSOR_SNAP_EDIT_GEOM_FINAL
Definition: ED_view3d.h:287

Definition at line 78 of file view3d_cursor_snap.c.

Referenced by ED_view3d_cursor_snap_active(), ED_view3d_cursor_snap_context_ensure(), ED_view3d_cursor_snap_data_get(), ED_view3d_cursor_snap_data_update(), ED_view3d_cursor_snap_deactive(), ED_view3d_cursor_snap_prevpoint_set(), ED_view3d_cursor_snap_state_default_set(), ED_view3d_cursor_snap_state_get(), 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().