45#define STATE_INTERN_GET(state) \
47 (SnapStateIntern *)((char *)state - offsetof(SnapStateIntern, snap_state))
71#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
88 data.state_default.draw_point =
true;
102 const float obmat[4][4],
111 for (
int i = 1;
i < 3;
i++) {
113 if (dot_test > dot_best) {
118 if (
dot_v3v3(mat[i_best], normal) < 0.0f) {
136 float dot_best = -1.0f;
137 int axis_found = axis_align;
138 for (
int i = 0;
i < 3;
i++) {
140 if (dot_test > dot_best) {
146 if (axis_align != axis_found) {
149 const int offset =
mod_i(axis_found - axis_align, 3);
150 for (
int i = 0;
i < 3;
i++) {
164 const float scale_fade,
165 const float matrix[4][4],
166 const int plane_axis,
167 const float color[4])
170 const int resolution_min = resolution - 1;
171 float color_fade[4] = {
UNPACK4(color)};
172 const float *center = matrix[3];
180 format,
"pos", blender::gpu::VertAttrType::SFLOAT_32_32_32);
182 format,
"color", blender::gpu::VertAttrType::SFLOAT_32_32_32_32);
186 const size_t coords_len = resolution * resolution;
187 float (*coords)[3] =
static_cast<float (*)[3]
>(
188 MEM_mallocN(
sizeof(*coords) * coords_len, __func__));
190 const int axis_x = (plane_axis + 0) % 3;
191 const int axis_y = (plane_axis + 1) % 3;
192 const int axis_z = (plane_axis + 2) % 3;
195 const float resolution_div = 1.0f /
float(resolution);
197 for (
int x = 0;
x < resolution;
x++) {
198 const float x_fl = (
x * resolution_div) - 0.5f;
199 for (
int y = 0;
y < resolution;
y++) {
200 const float y_fl = (
y * resolution_div) - 0.5f;
201 coords[
i][axis_x] = 0.0f;
202 coords[
i][axis_y] = x_fl * scale;
203 coords[
i][axis_z] = y_fl * scale;
211 for (
int x = 0;
x < resolution_min;
x++) {
212 for (
int y = 0;
y < resolution_min;
y++) {
217 max_ff(0.0f, (1.0f - square_f(((len_v3v3(v, center) / scale_fade) + resolution_div) * 2.0f)))
219 const float *v0 = coords[(resolution *
x) +
y];
220 const float *v1 = coords[(resolution * (
x + 1)) +
y];
221 const float *
v2 = coords[(resolution *
x) + (
y + 1)];
223 const float f0 =
FADE(v0);
224 const float f1 =
FADE(v1);
225 const float f2 =
FADE(
v2);
227 if (f0 > 0.0f || f1 > 0.0f) {
228 color_fade[3] = color[3] * f0;
231 color_fade[3] = color[3] * f1;
235 if (f0 > 0.0f || f2 > 0.0f) {
236 color_fade[3] = color[3] * f0;
240 color_fade[3] = color[3] * f2;
262 const int plane_axis,
263 const float matrix[4][4])
277 if (pixel_size > FLT_EPSILON) {
280 float color_alpha = 0.75f;
285 if (relative_pixel_scale < 1.0f) {
292 float view_vector[3];
294 float view_dot =
fabsf(
dot_v3v3(matrix[plane_axis], view_vector));
298 const float scale_mod =
U.gizmo_size * 2 *
UI_SCALE_FAC /
U.pixelsize;
300 float final_scale = (scale_mod * pixel_size);
302 const int lines_subdiv = 10;
303 int lines = lines_subdiv;
305 float final_scale_fade = final_scale;
308 float fac = final_scale_fade / final_scale;
310 float color[4] = {1, 1, 1, color_alpha};
312 if (color[3] > 0.0f) {
314 lines * lines_subdiv, final_scale, final_scale_fade, matrix, plane_axis, color);
317 color[3] = color_alpha;
321 final_scale = final_scale_fade;
331 format,
"pos", blender::gpu::VertAttrType::SFLOAT_32_32_32);
358 float model_view_new[4][4];
389 immVertex3f(attr_pos, 0.0f, 0.866f * size_b, 0.0f);
424 const float source_loc[3],
425 const float target_loc[3],
428 const uchar source_color[4],
429 const uchar target_color[4])
431 if (!source_loc && !target_loc) {
439 immVertexFormat(),
"pos", blender::gpu::VertAttrType::SFLOAT_32_32_32);
466 float viewport_size[4];
468 immUniform2f(
"viewport_size", viewport_size[2], viewport_size[3]);
495 uint8_t event_modifier)
501#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
519#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
521 uint8_t event_modifier)
536 const int snap_on = data_intern->
snap_on;
545 if (kmi->propvalue == snap_on) {
588 data_intern->
scene = scene;
596 if (
state->snap_state.draw_plane ||
state->snap_state.draw_box) {
610 uint8_t event_modifier)
621#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
627 if (!calc_plane_omat) {
636 const bool use_surface_co = snap_data->
is_enabled ||
639 float co[3], no[3], face_nor[3], obmat[4][4], omat[3][3];
641 int snap_elem_index[3] = {-1, -1, -1};
649 if (use_surface_nor || use_surface_co) {
659 float prev_co[3] = {0.0f};
660 if (
state->prevpoint) {
674 float dist_px = 12.0f *
U.pixelsize;
678 params.edit_mode_type = edit_mode_type;
718#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
724 if (calc_plane_omat) {
727 if (orient_surface) {
737 scene, view_layer, v3d, rv3d, ob,
nullptr, orient_index, pivot_point, omat);
750 if (orient_surface) {
756 "Use of variable `co` without it being computed");
764 if (
dot_v3v3(ray_dir, face_nor) >= 0.0f) {
778 if (!use_surface_co) {
783 snap_elem &= ~data_intern->snap_elem_hidden;
786 const float *plane_normal = omat[tool_settings->
plane_axis];
791 if (do_plane_isect) {
797 if (!do_plane_isect) {
802 snap_elem_index[0] = index;
807 snap_elem_index[1] = index;
810 snap_elem_index[2] = index;
883 if (region ==
nullptr) {
903 const bool draw_plane =
state->draw_plane ||
state->draw_box;
933 state->target_color);
936 if (
state->draw_box) {
980 if (!data_intern->
handle) {
985#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
1006 if (data_intern->
handle) {
1010 data_intern->
handle =
nullptr;
1035 if (!data_intern->
handle) {
1063 const float prev_point[3])
1074 state->prevpoint =
nullptr;
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
General operations, lookup, etc. for blender objects.
int BKE_scene_orientation_get_index(Scene *scene, int slot_index)
ARegion * BKE_area_find_region_xy(const ScrArea *area, int regiontype, const int xy[2]) ATTR_NONNULL(3)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
bool BLI_remlink_safe(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
MINLINE float max_ff(float a, float b)
MINLINE int mod_i(int i, int n)
MINLINE float square_f(float a)
float ceil_power_of_10(float f)
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void unit_m3(float m[3][3])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void orthogonalize_m3(float R[3][3], int axis)
void copy_m4_m3(float m1[4][4], const float m2[3][3])
void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
void normalize_m3(float R[3][3]) ATTR_NONNULL()
void mul_m4_v3(const float M[4][4], float r[3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void negate_v3(float r[3])
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void zero_v3(float r[3])
Scene * DEG_get_input_scene(const Depsgraph *graph)
Object is a sort of wrapper for general info.
#define SCE_SNAP_TO_VERTEX
@ SCE_SNAP_TO_EDGE_ENDPOINT
@ SCE_SNAP_TO_EDGE_MIDPOINT
@ SCE_SNAP_TO_EDGE_PERPENDICULAR
@ V3D_PLACE_ORIENT_SURFACE
@ V3D_PLACE_DEPTH_CURSOR_VIEW
@ V3D_PLACE_DEPTH_SURFACE
bool ED_region_overlap_isect_xy(const ARegion *region, const int event_xy[2])
void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3], float r_out[3])
void ED_view3d_win_to_3d(const View3D *v3d, const ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
float ED_view3d_pixel_size(const RegionView3D *rv3d, const float co[3])
@ V3D_SNAPCURSOR_SNAP_EDIT_GEOM_FINAL
@ V3D_SNAPCURSOR_TOGGLE_ALWAYS_TRUE
@ V3D_SNAPCURSOR_OCCLUSION_ALWAYS_TRUE
@ V3D_SNAPCURSOR_SNAP_EDIT_GEOM_CAGE
bool ED_view3d_win_to_3d_on_plane(const ARegion *region, const float plane[4], const float mval[2], bool do_clip, float r_out[3])
#define GPU_matrix_model_view_get(x)
#define GPU_matrix_set(x)
#define GPU_matrix_mul(x)
#define GPU_matrix_projection_set(x)
@ GPU_SHADER_3D_SMOOTH_COLOR
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ GPU_SHADER_3D_UNIFORM_COLOR
void GPU_line_width(float width)
void GPU_line_smooth(bool enable)
void GPU_blend(GPUBlend blend)
void GPU_viewport_size_get_f(float coords[4])
Read Guarded memory(de)allocation.
float UI_GetThemeValuef(int colorid)
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
BPy_StructRNA * depsgraph
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void * MEM_mallocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
blender::VecBase< uint8_t, 4 > uchar4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
static CursorSnapshot cursor_snap
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
struct ToolSettings * toolsettings
V3DSnapCursorState state_default
blender::ed::transform::SnapObjectContext * snap_context_v3d
V3DSnapCursorData snap_data
eSnapMode snap_elem_hidden
struct SnapCursorDataIntern::@371036144025202176171137130161162244366300312012 last_eventstate
V3DSnapCursorState snap_state
struct wmEvent * eventstate
V3DSnapCursorState * ED_view3d_cursor_snap_state_create()
static bool v3d_cursor_eventstate_has_changed(SnapCursorDataIntern *data_intern, V3DSnapCursorState *state, const blender::int2 &mval, uint8_t event_modifier)
void ED_view3d_cursor_snap_state_default_set(V3DSnapCursorState *state)
static void cursor_point_draw(uint attr_pos, const float loc[3], const float size, eSnapMode snap_type, const uchar color[4])
static const float eps_view_align
V3DSnapCursorState * ED_view3d_cursor_snap_state_active_get()
static void cursor_box_draw(const float dimensions[3], uchar color[4])
void ED_view3d_cursor_snap_state_prevpoint_set(V3DSnapCursorState *state, const float prev_point[3])
static void v3d_cursor_poject_surface_normal(const float normal[3], const float obmat[4][4], float r_mat[3][3])
#define STATE_INTERN_GET(state)
static void v3d_cursor_plane_draw(const RegionView3D *rv3d, const int plane_axis, const float matrix[4][4])
static void v3d_cursor_snap_activate()
static eSnapMode v3d_cursor_snap_elements(ToolSettings *tool_settings)
static SnapCursorDataIntern g_data_intern
static bool mat3_align_axis_to_v3(float mat[3][3], const int axis_align, const float v[3])
static bool v3d_cursor_snap_calc_plane()
static bool v3d_cursor_snap_poll_fn(bContext *C)
static void v3d_cursor_snap_context_ensure(Scene *scene)
void ED_view3d_cursor_snap_state_free(V3DSnapCursorState *state)
static void v3d_cursor_eventstate_save_modifier(SnapCursorDataIntern *data_intern, uint8_t event_modifier)
static void v3d_cursor_snap_free()
void ED_view3d_cursor_snap_state_active_set(V3DSnapCursorState *state)
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])
static void v3d_cursor_snap_draw_fn(bContext *C, const blender::int2 &xy, const blender::float2 &, void *)
static void v3d_cursor_eventstate_save_xy(SnapCursorDataIntern *cursor_snap, const blender::int2 &mval)
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 bool v3d_cursor_is_snap_invert(SnapCursorDataIntern *data_intern, uint8_t event_modifier)
static void v3d_cursor_snap_update(V3DSnapCursorState *state, const bContext *C, Depsgraph *depsgraph, Scene *scene, const ARegion *region, View3D *v3d, const blender::int2 &mval, uint8_t event_modifier)
V3DSnapCursorData * ED_view3d_cursor_snap_data_get()
void ED_view3d_cursor_snap_data_update(V3DSnapCursorState *state, const bContext *C, const ARegion *region, const blender::int2 &mval)
blender::ed::transform::SnapObjectContext * ED_view3d_cursor_snap_context_ensure(Scene *scene)
wmKeyMap * WM_keymap_active(const wmWindowManager *wm, wmKeyMap *keymap)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
bool WM_paint_cursor_end(wmPaintCursor *handle)
wmPaintCursor * WM_paint_cursor_activate(short space_type, short region_type, bool(*poll)(bContext *C), wmPaintCursorDraw draw, void *customdata)
void wmViewport(const rcti *winrct)
void wmWindowViewport(const wmWindow *win)