44#define STATE_INTERN_GET(state) \
46 (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;
172 const float *center = matrix[3];
184 const size_t coords_len = resolution * resolution;
185 float(*coords)[3] =
static_cast<float(*)[3]
>(
186 MEM_mallocN(
sizeof(*coords) * coords_len, __func__));
188 const int axis_x = (plane_axis + 0) % 3;
189 const int axis_y = (plane_axis + 1) % 3;
190 const int axis_z = (plane_axis + 2) % 3;
193 const float resolution_div =
float(1.0f) /
float(resolution);
195 for (
int x = 0;
x < resolution;
x++) {
196 const float x_fl = (
x * resolution_div) - 0.5f;
197 for (
int y = 0;
y < resolution;
y++) {
198 const float y_fl = (
y * resolution_div) - 0.5f;
199 coords[i][axis_x] = 0.0f;
200 coords[i][axis_y] = x_fl * scale;
201 coords[i][axis_z] = y_fl * scale;
209 for (
int x = 0;
x < resolution_min;
x++) {
210 for (
int y = 0;
y < resolution_min;
y++) {
215 max_ff(0.0f, (1.0f - square_f(((len_v3v3(v, center) / scale_fade) + resolution_div) * 2.0f)))
217 const float *v0 = coords[(resolution *
x) +
y];
218 const float *v1 = coords[(resolution * (
x + 1)) +
y];
219 const float *
v2 = coords[(resolution *
x) + (
y + 1)];
221 const float f0 =
FADE(v0);
222 const float f1 =
FADE(v1);
223 const float f2 =
FADE(
v2);
225 if (f0 > 0.0f || f1 > 0.0f) {
226 color_fade[3] =
color[3] * f0;
229 color_fade[3] =
color[3] * f1;
233 if (f0 > 0.0f || f2 > 0.0f) {
234 color_fade[3] =
color[3] * f0;
238 color_fade[3] =
color[3] * f2;
260 const int plane_axis,
261 const float matrix[4][4])
275 if (pixel_size > FLT_EPSILON) {
278 float color_alpha = 0.75f;
283 if (relative_pixel_scale < 1.0f) {
290 float view_vector[3];
292 float view_dot =
fabsf(
dot_v3v3(matrix[plane_axis], view_vector));
296 const float scale_mod =
U.gizmo_size * 2 *
UI_SCALE_FAC /
U.pixelsize;
298 float final_scale = (scale_mod * pixel_size);
300 const int lines_subdiv = 10;
301 int lines = lines_subdiv;
303 float final_scale_fade = final_scale;
306 float fac = final_scale_fade / final_scale;
308 float color[4] = {1, 1, 1, color_alpha};
310 if (
color[3] > 0.0f) {
312 lines * lines_subdiv, final_scale, final_scale_fade, matrix, plane_axis,
color);
315 color[3] = color_alpha;
319 final_scale = final_scale_fade;
355 float model_view_new[4][4];
386 immVertex3f(attr_pos, 0.0f, 0.866f * size_b, 0.0f);
421 const float source_loc[3],
422 const float target_loc[3],
425 const uchar source_color[4],
426 const uchar target_color[4])
428 if (!source_loc && !target_loc) {
462 float viewport_size[4];
464 immUniform2f(
"viewport_size", viewport_size[2], viewport_size[3]);
498#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
518#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
535 const int snap_on = data_intern->
snap_on;
544 if (kmi->propvalue == snap_on) {
587 data_intern->
scene = scene;
595 if (
state->snap_state.draw_plane ||
state->snap_state.draw_box) {
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) {
673 float dist_px = 12.0f *
U.pixelsize;
677 params.edit_mode_type = edit_mode_type;
715#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
721 if (calc_plane_omat) {
724 if (orient_surface) {
734 scene, view_layer, v3d, rv3d, ob,
nullptr, orient_index, pivot_point, omat);
747 if (orient_surface) {
753 "Use of variable `co` without it being computed");
761 if (
dot_v3v3(ray_dir, face_nor) >= 0.0f) {
775 if (!use_surface_co) {
780 snap_elem &= ~data_intern->snap_elem_hidden;
783 const float *plane_normal = omat[tool_settings->
plane_axis];
788 if (do_plane_isect) {
794 if (!do_plane_isect) {
799 snap_elem_index[0] = index;
804 snap_elem_index[1] = index;
807 snap_elem_index[2] = index;
878 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
1003 if (data_intern->
handle) {
1007 data_intern->
handle =
nullptr;
1032 if (!data_intern->
handle) {
1060 const float prev_point[3])
1071 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)
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
#define LISTBASE_FOREACH(type, var, list)
bool BLI_remlink_safe(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BLI_remlink(struct 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])
eSnapMode ED_transform_snap_object_project_view3d_ex(SnapObjectContext *sctx, Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const eSnapMode snap_to, const SnapObjectParams *params, const float init_co[3], const float mval[2], const float prev_co[3], float *dist_px, float r_loc[3], float r_no[3], int *r_index, const Object **r_ob, float r_obmat[4][4], float r_face_nor[3])
SnapObjectContext * ED_transform_snap_object_context_create(Scene *scene, int flag)
void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx)
eSnapMode ED_transform_snap_object_project_view3d(SnapObjectContext *sctx, Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const eSnapMode snap_to, const SnapObjectParams *params, const float init_co[3], const float mval[2], const float prev_co[3], float *dist_px, float r_loc[3], float r_no[3])
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_blend(eGPUBlend blend)
void GPU_line_width(float width)
void GPU_line_smooth(bool enable)
void GPU_viewport_size_get_f(float coords[4])
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
float UI_GetThemeValuef(int colorid)
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)
draw_view in_light_buf[] float
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
blender::VecBase< uint8_t, 4 > uchar4
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
SnapObjectContext * snap_context_v3d
struct SnapCursorDataIntern::@104312227314070056337326077032342361162111126016 last_eventstate
V3DSnapCursorData snap_data
eSnapMode snap_elem_hidden
V3DSnapCursorState snap_state
struct wmEvent * eventstate
V3DSnapCursorState * ED_view3d_cursor_snap_state_create()
static void v3d_cursor_eventstate_save_xy(SnapCursorDataIntern *cursor_snap, const int x, const int y)
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_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 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 bool v3d_cursor_eventstate_has_changed(SnapCursorDataIntern *data_intern, V3DSnapCursorState *state, const int x, const int y, uint8_t event_modifier)
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)
SnapObjectContext * ED_view3d_cursor_snap_context_ensure(Scene *scene)
void ED_view3d_cursor_snap_data_update(V3DSnapCursorState *state, const bContext *C, const ARegion *region, const int x, const int y)
static void v3d_cursor_snap_draw_fn(bContext *C, int x, int y, void *)
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_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)
V3DSnapCursorData * ED_view3d_cursor_snap_data_get()
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)