47#define STATE_INTERN_GET(state) \
49 (SnapStateIntern *)((char *)state - offsetof(SnapStateIntern, snap_state))
73#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
90 data.state_default.draw_point =
true;
104 const float obmat[4][4],
113 for (
int i = 1; i < 3; i++) {
115 if (dot_test > dot_best) {
120 if (
dot_v3v3(mat[i_best], normal) < 0.0f) {
138 float dot_best = -1.0f;
139 int axis_found = axis_align;
140 for (
int i = 0; i < 3; i++) {
142 if (dot_test > dot_best) {
148 if (axis_align != axis_found) {
151 const int offset =
mod_i(axis_found - axis_align, 3);
152 for (
int i = 0; i < 3; i++) {
166 const float scale_fade,
167 const float matrix[4][4],
168 const int plane_axis,
169 const float color[4])
172 const int resolution_min = resolution - 1;
174 const float *center = matrix[3];
183 format,
"color", gpu::VertAttrType::SFLOAT_32_32_32_32);
187 const size_t coords_len = resolution * resolution;
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])
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;
357 float model_view_new[4][4];
388 immVertex3f(attr_pos, 0.0f, 0.866f * size_b, 0.0f);
431 const float source_loc[3],
432 const float target_loc[3],
435 const uchar source_color[4],
436 const uchar target_color[4])
438 if (!source_loc && !target_loc) {
472 float viewport_size[4];
474 immUniform2f(
"viewport_size", viewport_size[2], viewport_size[3]);
507#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
524#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
541 const int snap_on = data_intern->
snap_on;
589 data_intern->
scene = scene;
597 if (
state.snap_state.draw_plane ||
state.snap_state.draw_box) {
606 Depsgraph *depsgraph,
622#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
628 if (!calc_plane_omat) {
637 const bool use_surface_co = snap_data->
is_enabled ||
640 float co[3], no[3], face_nor[3], obmat[4][4], omat[3][3];
642 int snap_elem_index[3] = {-1, -1, -1};
650 if (use_surface_nor || use_surface_co) {
660 float prev_co[3] = {0.0f};
661 if (
state->prevpoint) {
673 float dist_px = 12.0f *
U.pixelsize;
715#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
721 if (calc_plane_omat) {
724 if (orient_surface) {
735 *bmain, scene, view_layer, v3d, rv3d, ob,
nullptr, orient_index, pivot_point, omat);
748 if (orient_surface) {
754 "Use of variable `co` without it being computed");
762 if (
dot_v3v3(ray_dir, face_nor) >= 0.0f) {
776 if (!use_surface_co) {
781 snap_elem &= ~data_intern->snap_elem_hidden;
784 const float *plane_normal = omat[tool_settings->
plane_axis];
789 if (do_plane_isect) {
795 if (!do_plane_isect) {
800 snap_elem_index[0] =
index;
805 snap_elem_index[1] =
index;
808 snap_elem_index[2] =
index;
880 if (region ==
nullptr) {
900 const bool draw_plane =
state->draw_plane ||
state->draw_box;
930 state->target_color);
933 if (
state->draw_box) {
977 if (!data_intern->
handle) {
982#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
983 wmKeyConfig *keyconf = (
G.main->wm.first())->runtime->defaultconf;
1003 if (data_intern->
handle) {
1007 data_intern->
handle =
nullptr;
1032 if (!data_intern->
handle) {
1052 MEM_delete(state_intern);
1059 const float prev_point[3])
1070 state->prevpoint =
nullptr;
General operations, lookup, etc. for blender objects.
Object is a sort of wrapper for general info.
#define SCE_SNAP_TO_VERTEX
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
float3x3 scale(float3x3 mat, float2 scale)
float get_value_f(int colorid)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
wmKeyMap * WM_keymap_active(const wmWindowManager *wm, wmKeyMap *keymap)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE void negate_v3_v3(float r[3], const float a[3])
void orthogonalize_m3(float R[3][3], int axis)
VecBase< uint8_t, 4 > uchar4
MINLINE int mod_i(int i, int n)
ScrArea * CTX_wm_area(const bContext *C)
void wmViewport(const rcti *winrct)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
V3DSnapCursorState * ED_view3d_cursor_snap_state_create()
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void copy_m3_m4(float m1[3][3], const float m2[4][4])
bool ED_region_overlap_isect_xy(const ARegion *region, const int event_xy[2])
V3DSnapCursorState * ED_view3d_cursor_snap_state_active_get()
void wmWindowViewport(const wmWindow *win)
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void immUniform2f(const char *name, float x, float y)
void immBeginAtMost(GPUPrimType, uint max_vertex_len)
void copy_m4_m3(float m1[4][4], const float m2[3][3])
float ED_view3d_pixel_size(const RegionView3D *rv3d, const float co[3])
GPUVertFormat * immVertexFormat()
static void v3d_cursor_snap_draw_fn(bContext *C, const int2 &xy, const float2 &, void *)
void normalize_m3(float R[3][3]) ATTR_NONNULL()
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
static void v3d_cursor_snap_context_ensure(Scene *scene)
void immBegin(GPUPrimType, uint vertex_len)
void GPU_line_smooth(bool enable)
int BKE_scene_orientation_get_index(Scene *scene, int slot_index)
static bool v3d_cursor_is_snap_invert(SnapCursorDataIntern *data_intern, uint8_t event_modifier)
wmWindow * CTX_wm_window(const bContext *C)
void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static SnapCursorDataIntern g_data_intern
float ceil_power_of_10(float f)
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])
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3], float r_out[3])
ViewLayer * CTX_data_view_layer(const bContext *C)
void GPU_matrix_mul(const float m[4][4])
static const float eps_view_align
void GPU_line_width(float width)
static void v3d_cursor_snap_free()
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
V3DSnapCursorData * ED_view3d_cursor_snap_data_get()
static void v3d_cursor_poject_surface_normal(const float normal[3], const float obmat[4][4], float r_mat[3][3])
void ED_view3d_cursor_snap_state_default_set(V3DSnapCursorState *state)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
static bool v3d_cursor_snap_calc_plane()
static bool v3d_cursor_snap_poll_fn(bContext *C)
void mul_m4_v3(const float M[4][4], float r[3])
void ED_view3d_cursor_snap_state_free(V3DSnapCursorState *state)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void immUniform1f(const char *name, float x)
ed::transform::SnapObjectContext * ED_view3d_cursor_snap_context_ensure(Scene *scene)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void GPU_viewport_size_get_f(float coords[4])
void immAttr4fv(uint attr_id, const float data[4])
BMesh const char void * data
@ V3D_SNAPCURSOR_SNAP_EDIT_GEOM_CAGE
@ V3D_SNAPCURSOR_TOGGLE_ALWAYS_TRUE
@ V3D_SNAPCURSOR_SNAP_EDIT_GEOM_FINAL
@ V3D_SNAPCURSOR_OCCLUSION_ALWAYS_TRUE
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])
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])
@ GPU_SHADER_3D_SMOOTH_COLOR
@ GPU_SHADER_3D_UNIFORM_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_COLOR
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
static eSnapMode v3d_cursor_snap_elements(ToolSettings *tool_settings)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void imm_draw_cube_corners_3d(uint pos, const float center[3], const float aspect[3], float factor)
@ SCE_SNAP_TO_EDGE_MIDPOINT
@ SCE_SNAP_TO_EDGE_PERPENDICULAR
@ SCE_SNAP_TO_FACE_MIDPOINT
@ SCE_SNAP_TO_EDGE_ENDPOINT
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
MINLINE void negate_v3(float r[3])
void ED_view3d_cursor_snap_data_update(V3DSnapCursorState *state, const bContext *C, const ARegion *region, const int2 &mval)
void GPU_matrix_projection_set(const float m[4][4])
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
MINLINE void zero_v3(float r[3])
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
static void v3d_cursor_eventstate_save_modifier(SnapCursorDataIntern *data_intern, uint8_t event_modifier)
bool WM_event_modifier_flag_match_kmi_press(const wmEventModifierFlag event_modifier, const wmKeyMapItem *kmi)
wmPaintCursor * WM_paint_cursor_activate(short space_type, short region_type, wmPaintCursorPoll poll, wmPaintCursorDraw draw, void *customdata)
static bool v3d_cursor_eventstate_has_changed(SnapCursorDataIntern *data_intern, V3DSnapCursorState *state, const int2 &mval, uint8_t event_modifier)
void ED_view3d_cursor_snap_state_prevpoint_set(V3DSnapCursorState *state, const float prev_point[3])
@ V3D_PLACE_DEPTH_SURFACE
@ V3D_PLACE_DEPTH_CURSOR_VIEW
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
void immVertex3fv(uint attr_id, const float data[3])
static void v3d_cursor_snap_activate()
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Main * CTX_data_main(const bContext *C)
void unit_m3(float m[3][3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
MINLINE void copy_v3_fl(float r[3], float f)
static void cursor_box_draw(const float dimensions[3], uchar color[4])
MINLINE float max_ff(float a, float b)
static void v3d_cursor_eventstate_save_xy(SnapCursorDataIntern *cursor_snap, const int2 &mval)
Scene * DEG_get_input_scene(const Depsgraph *graph)
void ED_view3d_cursor_snap_state_active_set(V3DSnapCursorState *state)
MINLINE float square_f(float a)
static bool mat3_align_axis_to_v3(float mat[3][3], const int axis_align, const float v[3])
bool BLI_remlink_safe(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Scene * CTX_data_scene(const bContext *C)
void immVertex3f(uint attr_id, float x, float y, float z)
void GPU_blend(GPUBlend blend)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
VecBase< float, 3 > float3
static void cursor_point_draw(uint attr_pos, const float loc[3], const float size, eSnapMode snap_type, const uchar color[4])
void immUniformColor4ubv(const unsigned char rgba[4])
void imm_draw_circle_wire_3d(uint pos, float x, float y, float radius, int nsegments)
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])
@ V3D_PLACE_ORIENT_SURFACE
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ARegion * CTX_wm_region(const bContext *C)
void GPU_matrix_set(const float m[4][4])
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
static void v3d_cursor_plane_draw(const RegionView3D *rv3d, const int plane_axis, const float matrix[4][4])
View3D * CTX_wm_view3d(const bContext *C)
static void v3d_cursor_snap_update(V3DSnapCursorState *state, const bContext *C, Depsgraph *depsgraph, Scene *scene, const ARegion *region, View3D *v3d, const int2 &mval, uint8_t event_modifier)
bool WM_paint_cursor_end(wmPaintCursor *handle)
ARegion * BKE_area_find_region_xy(const ScrArea *area, int regiontype, const int xy[2]) ATTR_NONNULL(3)
const float(* GPU_matrix_model_view_get(float m[4][4]))[4]
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eRegion_Alignment alignment
struct ToolSettings * toolsettings
struct blender::SnapCursorDataIntern::@074041070204043305046355314270342045133105135075 last_eventstate
eSnapMode snap_elem_hidden
V3DSnapCursorState state_default
ed::transform::SnapObjectContext * snap_context_v3d
V3DSnapCursorData snap_data
ListBaseT< SnapStateIntern > state_intern
V3DSnapCursorState snap_state
bool(*) poll(ARegion *region, void *custom_poll_data)
ListBaseT< wmKeyMapItem > items
bke::WindowRuntime * runtime
#define STATE_INTERN_GET(state)