Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c101
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c31
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_navigate.c26
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c620
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c3
-rw-r--r--source/blender/editors/space_view3d/view3d_utils.c42
6 files changed, 302 insertions, 521 deletions
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 4c168c7a243..82cc499c729 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -469,16 +469,30 @@ static bool view3d_drop_in_main_region_poll(bContext *C, const wmEvent *event)
return ED_region_overlap_isect_any_xy(area, &event->x) == false;
}
-static ID *view3d_drop_id_in_main_region_poll_id(bContext *C,
- wmDrag *drag,
- const wmEvent *event,
- ID_Type id_type)
+static ID_Type view3d_drop_id_in_main_region_poll_get_id_type(bContext *C,
+ wmDrag *drag,
+ const wmEvent *event)
{
- ScrArea *area = CTX_wm_area(C);
+ const ScrArea *area = CTX_wm_area(C);
+
if (ED_region_overlap_isect_any_xy(area, &event->x)) {
- return NULL;
+ return 0;
+ }
+ if (!view3d_drop_in_main_region_poll(C, event)) {
+ return 0;
+ }
+
+ ID *local_id = WM_drag_get_local_ID(drag, 0);
+ if (local_id) {
+ return GS(local_id->name);
+ }
+
+ wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
+ if (asset_drag) {
+ return asset_drag->id_type;
}
- return view3d_drop_in_main_region_poll(C, event) ? WM_drag_get_local_ID(drag, id_type) : NULL;
+
+ return 0;
}
static bool view3d_drop_id_in_main_region_poll(bContext *C,
@@ -490,7 +504,7 @@ static bool view3d_drop_id_in_main_region_poll(bContext *C,
return false;
}
- return WM_drag_get_local_ID(drag, id_type) || WM_drag_get_asset_data(drag, id_type);
+ return WM_drag_is_ID_type(drag, id_type);
}
static bool view3d_ob_drop_poll(bContext *C,
@@ -522,9 +536,9 @@ static bool view3d_object_data_drop_poll(bContext *C,
const wmEvent *event,
const char **r_tooltip)
{
- ID *id = view3d_drop_id_in_main_region_poll_id(C, drag, event, 0);
- if (id != NULL) {
- if (BKE_object_obdata_to_type(id) != -1) {
+ ID_Type id_type = view3d_drop_id_in_main_region_poll_get_id_type(C, drag, event);
+ if (id_type) {
+ if (OB_DATA_SUPPORT_ID(id_type)) {
*r_tooltip = TIP_("Create object instance from object-data");
return true;
}
@@ -545,7 +559,7 @@ static bool view3d_ima_drop_poll(bContext *C,
return (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE));
}
- return WM_drag_get_local_ID(drag, ID_IM) || WM_drag_get_asset_data(drag, ID_IM);
+ return WM_drag_is_ID_type(drag, ID_IM);
}
static bool view3d_ima_bg_is_camera_view(bContext *C)
@@ -629,7 +643,7 @@ static void view3d_id_drop_copy(wmDrag *drag, wmDropBox *drop)
static void view3d_id_drop_copy_with_type(wmDrag *drag, wmDropBox *drop)
{
- ID *id = WM_drag_get_local_ID(drag, 0);
+ ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
RNA_string_set(drop->ptr, "name", id->name + 2);
RNA_enum_set(drop->ptr, "type", GS(id->name));
@@ -784,9 +798,13 @@ static void *view3d_main_region_duplicate(void *poin)
return NULL;
}
-static void view3d_main_region_listener(
- wmWindow *win, ScrArea *area, ARegion *region, wmNotifier *wmn, const Scene *scene)
+static void view3d_main_region_listener(const wmRegionListenerParams *params)
{
+ wmWindow *window = params->window;
+ ScrArea *area = params->area;
+ ARegion *region = params->region;
+ wmNotifier *wmn = params->notifier;
+ const Scene *scene = params->scene;
View3D *v3d = area->spacedata.first;
RegionView3D *rv3d = region->regiondata;
wmGizmoMap *gzmap = region->gizmo_map;
@@ -1007,10 +1025,10 @@ static void view3d_main_region_listener(
ED_view3d_xr_shading_update(G_MAIN->wm.first, v3d, scene);
#endif
- ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+ ViewLayer *view_layer = WM_window_get_active_view_layer(window);
Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer);
if (depsgraph) {
- ED_render_view3d_update(depsgraph, win, area, true);
+ ED_render_view3d_update(depsgraph, window, area, true);
}
}
ED_region_tag_redraw(region);
@@ -1048,14 +1066,13 @@ static void view3d_main_region_listener(
}
}
-static void view3d_main_region_message_subscribe(const struct bContext *C,
- struct WorkSpace *UNUSED(workspace),
- struct Scene *UNUSED(scene),
- struct bScreen *UNUSED(screen),
- struct ScrArea *area,
- struct ARegion *region,
- struct wmMsgBus *mbus)
+static void view3d_main_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
{
+ struct wmMsgBus *mbus = params->message_bus;
+ const bContext *C = params->context;
+ ScrArea *area = params->area;
+ ARegion *region = params->region;
+
/* Developer note: there are many properties that impact 3D view drawing,
* so instead of subscribing to individual properties, just subscribe to types
* accepting some redundant redraws.
@@ -1170,12 +1187,11 @@ static void view3d_header_region_draw(const bContext *C, ARegion *region)
ED_region_header(C, region);
}
-static void view3d_header_region_listener(wmWindow *UNUSED(win),
- ScrArea *UNUSED(area),
- ARegion *region,
- wmNotifier *wmn,
- const Scene *UNUSED(scene))
+static void view3d_header_region_listener(const wmRegionListenerParams *params)
{
+ ARegion *region = params->region;
+ wmNotifier *wmn = params->notifier;
+
/* context changes */
switch (wmn->category) {
case NC_SCENE:
@@ -1240,14 +1256,11 @@ static void view3d_header_region_listener(wmWindow *UNUSED(win),
#endif
}
-static void view3d_header_region_message_subscribe(const struct bContext *UNUSED(C),
- struct WorkSpace *UNUSED(workspace),
- struct Scene *UNUSED(scene),
- struct bScreen *UNUSED(screen),
- struct ScrArea *UNUSED(area),
- struct ARegion *region,
- struct wmMsgBus *mbus)
+static void view3d_header_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
{
+ struct wmMsgBus *mbus = params->message_bus;
+ ARegion *region = params->region;
+
wmMsgParams_RNA msg_key_params = {{0}};
/* Only subscribe to types. */
@@ -1385,12 +1398,11 @@ static void view3d_buttons_region_layout(const bContext *C, ARegion *region)
ED_view3d_buttons_region_layout_ex(C, region, NULL);
}
-static void view3d_buttons_region_listener(wmWindow *UNUSED(win),
- ScrArea *UNUSED(area),
- ARegion *region,
- wmNotifier *wmn,
- const Scene *UNUSED(scene))
+static void view3d_buttons_region_listener(const wmRegionListenerParams *params)
{
+ ARegion *region = params->region;
+ wmNotifier *wmn = params->notifier;
+
/* context changes */
switch (wmn->category) {
case NC_ANIMATION:
@@ -1509,11 +1521,10 @@ static void view3d_tools_region_draw(const bContext *C, ARegion *region)
}
/* area (not region) level listener */
-static void space_view3d_listener(wmWindow *UNUSED(win),
- ScrArea *area,
- struct wmNotifier *wmn,
- Scene *UNUSED(scene))
+static void space_view3d_listener(const wmSpaceTypeListenerParams *params)
{
+ ScrArea *area = params->area;
+ wmNotifier *wmn = params->notifier;
View3D *v3d = area->spacedata.first;
/* context changes */
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 8ae0e3b94fe..3c970781448 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -723,15 +723,24 @@ static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region,
}
if (ca->flag & CAM_SHOW_SAFE_MARGINS) {
- UI_draw_safe_areas(
- shdr_pos, x1, x2, y1, y2, scene->safe_areas.title, scene->safe_areas.action);
+ UI_draw_safe_areas(shdr_pos,
+ &(const rctf){
+ .xmin = x1,
+ .xmax = x2,
+ .ymin = y1,
+ .ymax = y2,
+ },
+ scene->safe_areas.title,
+ scene->safe_areas.action);
if (ca->flag & CAM_SHOW_SAFE_CENTER) {
UI_draw_safe_areas(shdr_pos,
- x1,
- x2,
- y1,
- y2,
+ &(const rctf){
+ .xmin = x1,
+ .xmax = x2,
+ .ymin = y1,
+ .ymax = y2,
+ },
scene->safe_areas.title_center,
scene->safe_areas.action_center);
}
@@ -1953,13 +1962,13 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph,
/* XXX(jbakker): `do_color_management` should be controlled by the caller. Currently when doing a
* viewport render animation and saving to an 8bit file format, color management would be applied
* twice. Once here, and once when saving the saving to disk. In this case the Save As Render
- * option cannot be controlled either. But when doing an offscreen render you want to do the
+ * option cannot be controlled either. But when doing an off-screen render you want to do the
* color management here.
*
- * This option was added here to increase the performance when rendering for a playblast. When
- * using workbench the color differences haven't been reported as a bug. But users also use the
- * viewport rendering to render Eevee scenes. In the later situation the saved colors
- * are totally wrong. */
+ * This option was added here to increase the performance for quick view-port preview renders.
+ * When using workbench the color differences haven't been reported as a bug. But users also use
+ * the viewport rendering to render Eevee scenes. In the later situation the saved colors are
+ * totally wrong. */
const bool do_color_management = (ibuf->rect_float == NULL);
ED_view3d_draw_offscreen(depsgraph,
scene,
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
index 7a201d8841c..c145497fa09 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate.c
@@ -45,14 +45,17 @@
/** \name View3D Navigation Gizmo Group
* \{ */
-/* Offset from screen edge. */
-#define GIZMO_OFFSET_FAC 1.2f
/* Size of main icon. */
-#define GIZMO_SIZE 80
-/* Factor for size of smaller button. */
-#define GIZMO_MINI_FAC 0.35f
-/* How much mini buttons offset from the primary. */
-#define GIZMO_MINI_OFFSET_FAC 0.38f
+#define GIZMO_SIZE U.gizmo_size_navigate_v3d
+
+/* Main gizmo offset from screen edges in unscaled pixels. */
+#define GIZMO_OFFSET 10.0f
+
+/* Width of smaller buttons in unscaled pixels. */
+#define GIZMO_MINI_SIZE 28.0f
+
+/* Margin around the smaller buttons. */
+#define GIZMO_MINI_OFFSET 2.0f
enum {
GZ_INDEX_MOVE = 0,
@@ -174,7 +177,7 @@ static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup)
}
/* may be overwritten later */
- gz->scale_basis = (GIZMO_SIZE * GIZMO_MINI_FAC) / 2;
+ gz->scale_basis = GIZMO_MINI_SIZE / 2.0f;
if (info->icon != 0) {
PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "icon");
RNA_property_enum_set(gz->ptr, prop, info->icon);
@@ -212,7 +215,7 @@ static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup)
{
wmGizmo *gz = navgroup->gz_array[GZ_INDEX_ROTATE];
- gz->scale_basis = GIZMO_SIZE / 2;
+ gz->scale_basis = GIZMO_SIZE / 2.0f;
const char mapping[6] = {
RV3D_VIEW_LEFT,
RV3D_VIEW_RIGHT,
@@ -263,9 +266,8 @@ static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *g
const bool show_navigate = (U.uiflag & USER_SHOW_GIZMO_NAVIGATE) != 0;
const bool show_rotate_gizmo = (U.mini_axis_type == USER_MINI_AXIS_TYPE_GIZMO);
- const float icon_size = GIZMO_SIZE;
- const float icon_offset = (icon_size * 0.52f) * GIZMO_OFFSET_FAC * UI_DPI_FAC;
- const float icon_offset_mini = icon_size * GIZMO_MINI_OFFSET_FAC * UI_DPI_FAC;
+ const float icon_offset = ((GIZMO_SIZE / 2.0f) + GIZMO_OFFSET) * UI_DPI_FAC;
+ const float icon_offset_mini = (GIZMO_MINI_SIZE + GIZMO_MINI_OFFSET) * UI_DPI_FAC;
const float co_rotate[2] = {
rect_visible->xmax - icon_offset,
rect_visible->ymax - icon_offset,
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
index 8f3d40584aa..4ac16e8fbe8 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate_type.c
@@ -40,6 +40,8 @@
#include "GPU_matrix.h"
#include "GPU_state.h"
+#include "BLF_api.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -53,169 +55,34 @@
#include "view3d_intern.h"
-#define USE_AXIS_FONT
-#define USE_FADE_BACKGROUND
-
-#ifdef USE_AXIS_FONT
-# include "BLF_api.h"
-#endif
-
-#define DIAL_RESOLUTION 32
-
-/* Sizes of axis spheres containing XYZ characters. */
-#define AXIS_HANDLE_SIZE_FG 0.19f
-/* When pointing away from the view. */
-#define AXIS_HANDLE_SIZE_BG 0.15f
-/* How far axis handles are away from the center. */
-#define AXIS_HANDLE_OFFSET (1.0f - AXIS_HANDLE_SIZE_FG)
-
-struct AxisDrawInfo {
- /* Matrix is needed for screen-aligned font drawing. */
-#ifdef USE_AXIS_FONT
- float matrix_final[4][4];
-#endif
-#ifdef USE_FADE_BACKGROUND
- float color_bg[3];
-#endif
-};
-
-#ifndef USE_AXIS_FONT
-/**
- * \param viewmat_local_unit: is typically the 'rv3d->viewmatob'
- * copied into a 3x3 matrix and normalized.
- */
-static void draw_xyz_wire(
- uint pos_id, const float viewmat_local_unit[3][3], const float c[3], float size, int axis)
-{
- int line_type;
- float buffer[4][3];
- int n = 0;
-
- float v1[3] = {0.0f, 0.0f, 0.0f}, v2[3] = {0.0f, 0.0f, 0.0f};
- float dim = size * 0.1f;
- float dx[3], dy[3];
-
- dx[0] = dim;
- dx[1] = 0.0f;
- dx[2] = 0.0f;
- dy[0] = 0.0f;
- dy[1] = dim;
- dy[2] = 0.0f;
-
- switch (axis) {
- case 0: /* x axis */
- line_type = GPU_PRIM_LINES;
-
- /* bottom left to top right */
- negate_v3_v3(v1, dx);
- sub_v3_v3(v1, dy);
- copy_v3_v3(v2, dx);
- add_v3_v3(v2, dy);
-
- copy_v3_v3(buffer[n++], v1);
- copy_v3_v3(buffer[n++], v2);
-
- /* top left to bottom right */
- mul_v3_fl(dy, 2.0f);
- add_v3_v3(v1, dy);
- sub_v3_v3(v2, dy);
-
- copy_v3_v3(buffer[n++], v1);
- copy_v3_v3(buffer[n++], v2);
-
- break;
- case 1: /* y axis */
- line_type = GPU_PRIM_LINES;
-
- /* bottom left to top right */
- mul_v3_fl(dx, 0.75f);
- negate_v3_v3(v1, dx);
- sub_v3_v3(v1, dy);
- copy_v3_v3(v2, dx);
- add_v3_v3(v2, dy);
-
- copy_v3_v3(buffer[n++], v1);
- copy_v3_v3(buffer[n++], v2);
-
- /* top left to center */
- mul_v3_fl(dy, 2.0f);
- add_v3_v3(v1, dy);
- zero_v3(v2);
-
- copy_v3_v3(buffer[n++], v1);
- copy_v3_v3(buffer[n++], v2);
-
- break;
- case 2: /* z axis */
- line_type = GPU_PRIM_LINE_STRIP;
-
- /* start at top left */
- negate_v3_v3(v1, dx);
- add_v3_v3(v1, dy);
-
- copy_v3_v3(buffer[n++], v1);
-
- mul_v3_fl(dx, 2.0f);
- add_v3_v3(v1, dx);
+/* Radius of the entire background. */
+#define WIDGET_RADIUS ((U.gizmo_size_navigate_v3d / 2.0f) * UI_DPI_FAC)
- copy_v3_v3(buffer[n++], v1);
+/* Sizes of axis spheres containing XYZ characters in relation to above. */
+#define AXIS_HANDLE_SIZE 0.20f
- mul_v3_fl(dy, 2.0f);
- sub_v3_v3(v1, dx);
- sub_v3_v3(v1, dy);
+#define AXIS_LINE_WIDTH ((U.gizmo_size_navigate_v3d / 40.0f) * U.pixelsize)
+#define AXIS_RING_WIDTH ((U.gizmo_size_navigate_v3d / 60.0f) * U.pixelsize)
+#define AXIS_TEXT_SIZE (WIDGET_RADIUS * AXIS_HANDLE_SIZE * 1.25f)
- copy_v3_v3(buffer[n++], v1);
+/* distance within this from center is considered positive. */
+#define AXIS_DEPTH_BIAS 0.01f
- add_v3_v3(v1, dx);
-
- copy_v3_v3(buffer[n++], v1);
-
- break;
- default:
- BLI_assert(0);
- return;
- }
-
- for (int i = 0; i < n; i++) {
- mul_transposed_m3_v3((float(*)[3])viewmat_local_unit, buffer[i]);
- add_v3_v3(buffer[i], c);
- }
-
- immBegin(line_type, n);
- for (int i = 0; i < n; i++) {
- immVertex3fv(pos_id, buffer[i]);
- }
- immEnd();
-}
-#endif /* !USE_AXIS_FONT */
-
-/**
- * \param draw_info: Extra data needed for drawing.
- */
-static void axis_geom_draw(const wmGizmo *gz,
- const float color[4],
- const bool select,
- const struct AxisDrawInfo *draw_info)
+static void gizmo_axis_draw(const bContext *C, wmGizmo *gz)
{
- float viewport[4];
- GPU_viewport_size_get_f(viewport);
-
- GPUVertFormat *format = immVertexFormat();
- const uint pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
-
struct {
float depth;
char index;
char axis;
+ char axis_opposite;
bool is_pos;
} axis_order[6] = {
- {-gz->matrix_offset[0][2], 0, 0, false},
- {+gz->matrix_offset[0][2], 1, 0, true},
- {-gz->matrix_offset[1][2], 2, 1, false},
- {+gz->matrix_offset[1][2], 3, 1, true},
- {-gz->matrix_offset[2][2], 4, 2, false},
- {+gz->matrix_offset[2][2], 5, 2, true},
+ {-gz->matrix_offset[0][2], 0, 0, 1, false},
+ {+gz->matrix_offset[0][2], 1, 0, 0, true},
+ {-gz->matrix_offset[1][2], 2, 1, 3, false},
+ {+gz->matrix_offset[1][2], 3, 1, 2, true},
+ {-gz->matrix_offset[2][2], 4, 2, 5, false},
+ {+gz->matrix_offset[2][2], 5, 2, 4, true},
};
int axis_align = -1;
@@ -226,25 +93,35 @@ static void axis_geom_draw(const wmGizmo *gz,
}
}
- /* Show backwards pointing highlight on-top (else we can't see it at all). */
- if ((select == false) && (gz->highlight_part > 0) && (axis_align != -1)) {
- if (axis_order[gz->highlight_part - 1].is_pos == false) {
- axis_order[gz->highlight_part - 1].depth = FLT_MAX;
- }
- }
-
qsort(&axis_order, ARRAY_SIZE(axis_order), sizeof(axis_order[0]), BLI_sortutil_cmp_float);
- static const float axis_highlight[4] = {1, 1, 1, 1};
- static const float axis_black[4] = {0, 0, 0, 1};
- static float axis_color[3][4];
+ /* When the cursor is over any of the gizmos (show circle backdrop). */
+ const bool is_active = ((gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0);
- const float axis_depth_bias = 0.01f;
- const float sphere_scale = 1.15f;
- /* TODO(fclem): Is there a way to get the widget radius? */
- const float widget_pix_size = 40.0f * U.dpi_fac;
+ /* Background color of the View3D, used to mix colors. */
+ float view_color[4];
+ ED_view3d_background_color_get(CTX_data_scene(C), CTX_wm_view3d(C), view_color);
+ view_color[3] = 1.0f;
+
+ float matrix_screen[4][4];
+ float matrix_unit[4][4];
+ unit_m4(matrix_unit);
+ WM_gizmo_calc_matrix_final_params(gz,
+ &((struct WM_GizmoMatrixParams){
+ .matrix_offset = matrix_unit,
+ }),
+ matrix_screen);
+ GPU_matrix_push();
+ GPU_matrix_mul(matrix_screen);
+
+ GPUVertFormat *format = immVertexFormat();
+ const uint pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ const uint color_id = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
+ float viewport_size[4];
+ GPU_viewport_size_get_f(viewport_size);
+
+ static float axis_color[3][4];
-#ifdef USE_AXIS_FONT
struct {
float matrix[4][4];
float matrix_m3[3][3];
@@ -252,38 +129,29 @@ static void axis_geom_draw(const wmGizmo *gz,
int id;
} font;
- if (select == false) {
- font.id = blf_mono_font;
- BLF_disable(font.id, BLF_ROTATION | BLF_SHADOW | BLF_MATRIX | BLF_ASPECT | BLF_WORD_WRAP);
- BLF_color4fv(font.id, axis_black);
- BLF_size(font.id, 12 * U.dpi_fac, 72);
-
- /* The view matrix is used to position the text. */
- BLF_position(font.id, 0, 0, 0);
-
- /* Calculate the inverse of the (matrix_final * matrix_offset).
- * This allows us to use the final location, while reversing the rotation so fonts
- * show without any rotation. */
- float m3[3][3];
- float m3_offset[3][3];
- copy_m3_m4(m3, draw_info->matrix_final);
- copy_m3_m4(m3_offset, gz->matrix_offset);
- mul_m3_m3m3(m3, m3, m3_offset);
- copy_m3_m3(font.matrix_m3_invert, m3);
- invert_m3(m3);
- copy_m3_m3(font.matrix_m3, m3);
- copy_m4_m3(font.matrix, m3);
- }
-#endif
-
- /* When the cursor is over any of the gizmos (show circle backdrop). */
- const bool is_active = (color[3] != 0.0f);
-
- const float clip_range = gz->scale_final * sphere_scale;
- bool use_project_matrix = (clip_range >= -GPU_MATRIX_ORTHO_CLIP_NEAR_DEFAULT);
+ font.id = BLF_default();
+ BLF_disable(font.id, BLF_ROTATION | BLF_SHADOW | BLF_MATRIX | BLF_ASPECT | BLF_WORD_WRAP);
+ BLF_enable(font.id, BLF_BOLD);
+ BLF_size(font.id, AXIS_TEXT_SIZE, 72);
+ BLF_position(font.id, 0, 0, 0);
+
+ /* Calculate the inverse of the (matrix_final * matrix_offset).
+ * This allows us to use the final location, while reversing the rotation so fonts
+ * show without any rotation. */
+ float m3[3][3];
+ float m3_offset[3][3];
+ copy_m3_m4(m3, matrix_screen);
+ copy_m3_m4(m3_offset, gz->matrix_offset);
+ mul_m3_m3m3(m3, m3, m3_offset);
+ copy_m3_m3(font.matrix_m3_invert, m3);
+ invert_m3(m3);
+ copy_m3_m3(font.matrix_m3, m3);
+ copy_m4_m3(font.matrix, m3);
+
+ bool use_project_matrix = (gz->scale_final >= -GPU_MATRIX_ORTHO_CLIP_NEAR_DEFAULT);
if (use_project_matrix) {
GPU_matrix_push_projection();
- GPU_matrix_ortho_set_z(-clip_range, clip_range);
+ GPU_matrix_ortho_set_z(-gz->scale_final, gz->scale_final);
}
UI_draw_roundbox_corner_set(UI_CNR_ALL);
@@ -291,263 +159,161 @@ static void axis_geom_draw(const wmGizmo *gz,
/* Circle defining active area. */
if (is_active) {
- immUnbindProgram();
-
- float rad = widget_pix_size;
+ const float rad = WIDGET_RADIUS;
GPU_matrix_push();
GPU_matrix_scale_1f(1.0f / rad);
-
- UI_draw_roundbox_4fv(true, -rad, -rad, rad, rad, rad, color);
-
+ UI_draw_roundbox_4fv(
+ &(const rctf){
+ .xmin = -rad,
+ .xmax = rad,
+ .ymin = -rad,
+ .ymax = rad,
+ },
+ true,
+ rad,
+ gz->color_hi);
GPU_matrix_pop();
-
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
}
- GPU_matrix_push();
GPU_matrix_mul(gz->matrix_offset);
for (int axis_index = 0; axis_index < ARRAY_SIZE(axis_order); axis_index++) {
const int index = axis_order[axis_index].index;
const int axis = axis_order[axis_index].axis;
const bool is_pos = axis_order[axis_index].is_pos;
- const bool is_highlight = index + 1 == gz->highlight_part;
+ const float depth = axis_order[axis_index].depth;
+ const bool is_behind = (depth <= (AXIS_DEPTH_BIAS * (is_pos ? -1 : 1)));
+ bool is_aligned_front = (axis_align != -1 && axis_align == axis && !is_behind);
+ bool is_aligned_back = (axis_align != -1 && axis_align == axis && is_behind);
+
+ const float v[3] = {0, 0, (1.0f - AXIS_HANDLE_SIZE) * (is_pos ? 1 : -1)};
+ const float v_final[3] = {v[(axis + 2) % 3], v[(axis + 1) % 3], v[axis]};
+
+ bool is_highlight = index + 1 == gz->highlight_part;
+ /* Check if highlight part is the other side when axis aligned. */
+ if (is_aligned_front && (axis_order[axis_index].axis_opposite + 1 == gz->highlight_part)) {
+ is_highlight = true;
+ }
UI_GetThemeColor3fv(TH_AXIS_X + axis, axis_color[axis]);
axis_color[axis][3] = 1.0f;
- const int index_z = axis;
- const int index_y = (axis + 1) % 3;
- const int index_x = (axis + 2) % 3;
-
- bool ok = true;
-
- /* Skip view align axis when selecting (allows to switch to opposite side). */
- if (select && ((axis_align == axis) && (gz->matrix_offset[axis][2] > 0.0f) == is_pos)) {
- ok = false;
+ /* Color that is full at front, but 50% view background when in back. */
+ float fading_color[4];
+ interp_v4_v4v4(fading_color, view_color, axis_color[axis], ((depth + 1) * 0.25) + 0.5);
+
+ /* Color that is midway between front and back. */
+ float middle_color[4];
+ interp_v4_v4v4(middle_color, view_color, axis_color[axis], 0.75f);
+
+ GPU_blend(GPU_BLEND_ALPHA);
+
+ /* Axis Line. */
+ if (is_pos || axis_align != -1) {
+
+ /* Extend slightly to meet better at the center. */
+ float v_start[3] = {0.0f, 0.0f, 0.0f};
+ mul_v3_v3fl(v_start, v_final, -(AXIS_LINE_WIDTH / WIDGET_RADIUS * 0.66f));
+
+ /* Decrease length of line by ball radius. */
+ float v_end[3] = {0.0f, 0.0f, 0.0f};
+ mul_v3_v3fl(v_end, v_final, 1.0f - AXIS_HANDLE_SIZE);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR);
+ immUniform2fv("viewportSize", &viewport_size[2]);
+ immUniform1f("lineWidth", AXIS_LINE_WIDTH);
+ immBegin(GPU_PRIM_LINES, 2);
+ immAttr4fv(color_id, middle_color);
+ immVertex3fv(pos_id, v_start);
+ immAttr4fv(color_id, fading_color);
+ immVertex3fv(pos_id, v_end);
+ immEnd();
+ immUnbindProgram();
}
- if (ok) {
- /* Check aligned, since the front axis won't display in this case,
- * and we want to make sure all 3 axes have a character at all times. */
- const bool show_axis_char = (is_pos || (axis == axis_align));
- const float v[3] = {0, 0, AXIS_HANDLE_OFFSET * (is_pos ? 1 : -1)};
- const float v_final[3] = {v[index_x], v[index_y], v[index_z]};
- const float *color_current = is_highlight ? axis_highlight : axis_color[axis];
- float color_current_fade[4];
-
- /* Flip the faded state when axis aligned, since we're hiding the front-mode axis
- * otherwise we see the color for the back-most axis, which is useful for
- * click-to-rotate 180d but not useful to visualize.
- *
- * Use depth bias so axis-aligned views show the positive axis as being in-front.
- * This is a detail so primary axes show as dominant.
- */
- const bool is_pos_color = (axis_order[axis_index].depth >
- (axis_depth_bias * (is_pos ? -1 : 1)));
-
- if (select == false) {
-#ifdef USE_FADE_BACKGROUND
- interp_v3_v3v3(
- color_current_fade, draw_info->color_bg, color_current, is_highlight ? 1.0 : 0.5f);
- color_current_fade[3] = color_current[3];
-#else
- copy_v4_v4(color_current_fade, color_current);
- color_current_fade[3] *= 0.2;
-#endif
- }
- else {
- copy_v4_fl(color_current_fade, 1.0f);
- }
-
- /* Axis Line. */
- if (is_pos) {
- float v_start[3];
- immUnbindProgram();
-
- GPU_blend(GPU_BLEND_ALPHA);
-
- immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR);
- immUniform2fv("viewportSize", &viewport[2]);
- immUniform1f("lineWidth", 2.0f * U.pixelsize);
- immUniformColor4fv(is_pos_color ? color_current : color_current_fade);
- immBegin(GPU_PRIM_LINES, 2);
- if (axis_align == -1) {
- zero_v3(v_start);
+ /* Axis Ball. */
+ if (!is_aligned_back) {
+ float *inner_color = fading_color;
+ float *outline_color = fading_color;
+ float negative_color[4];
+ if (!is_pos) {
+ if (is_aligned_front) {
+ interp_v4_v4v4(
+ negative_color, (float[4]){1.0f, 1.0f, 1.0f, 1.0f}, axis_color[axis], 0.5f);
+ negative_color[3] = MIN2(depth + 1, 1.0f);
+ outline_color = negative_color;
}
else {
- /* When axis aligned we don't draw the front most axis
- * (allowing us to switch to the opposite side).
- * In this case don't draw lines over axis pointing away from us
- * because it obscures character and looks noisy.
- */
- mul_v3_v3fl(v_start, v_final, 0.3f);
+ interp_v4_v4v4(negative_color, view_color, axis_color[axis], 0.25f);
+ negative_color[3] = MIN2(depth + 1, 1.0f);
+ inner_color = negative_color;
}
- immVertex3fv(pos_id, v_start);
- immVertex3fv(pos_id, v_final);
- immEnd();
-
- immUnbindProgram();
-
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
}
- /* Axis Ball. */
-#ifdef USE_AXIS_FONT
- if (select == false) {
- immUnbindProgram();
-
- GPU_matrix_push();
- GPU_matrix_translate_3fv(v_final);
- GPU_matrix_mul(font.matrix);
-
- float rad = widget_pix_size * (is_pos ? AXIS_HANDLE_SIZE_FG : AXIS_HANDLE_SIZE_BG);
-
- /* Black outlines for negative axis balls, otherwise they can be hard to see since
- * they use a faded color which can be similar to the circle backdrop in tone. */
- if (is_active && !is_highlight && !is_pos && !select && !(axis_align == axis)) {
- static const float axis_black_faded[4] = {0.0f, 0.0f, 0.0f, 0.2f};
- float outline = rad * sphere_scale;
- UI_draw_roundbox_4fv(
- true, -outline, -outline, outline, outline, outline, axis_black_faded);
- }
-
- const float *col = is_pos_color ? color_current : color_current_fade;
- UI_draw_roundbox_4fv(true, -rad, -rad, rad, rad, rad, col);
-
- GPU_matrix_pop();
-
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- }
- else
-#endif
- {
- GPU_matrix_push();
- GPU_matrix_translate_3fv(v_final);
- GPU_matrix_scale_1f(is_pos ? AXIS_HANDLE_SIZE_FG : AXIS_HANDLE_SIZE_BG);
-
- GPUBatch *sphere = GPU_batch_preset_sphere(0);
- GPU_batch_program_set_builtin(sphere, GPU_SHADER_3D_UNIFORM_COLOR);
-
- /* Black outlines for negative axis balls, otherwise they can be hard to see since
- * they use a faded color which can be similar to the circle backdrop in tone. */
- if (is_active && !is_highlight && !is_pos && !select && !(axis_align == axis)) {
- static const float axis_black_faded[4] = {0, 0, 0, 0.2f};
- GPU_matrix_scale_1f(sphere_scale);
- GPU_batch_uniform_4fv(sphere, "color", axis_black_faded);
- GPU_batch_draw(sphere);
- GPU_matrix_scale_1f(1.0 / sphere_scale);
- }
+ GPU_matrix_push();
+ GPU_matrix_translate_3fv(v_final);
+ GPU_matrix_mul(font.matrix);
+ /* Size change from back to front: 0.92f - 1.08f. */
+ float scale = ((depth + 1) * 0.08f) + 0.92f;
+ const float rad = WIDGET_RADIUS * AXIS_HANDLE_SIZE * scale;
+ UI_draw_roundbox_4fv_ex(
+ &(const rctf){
+ .xmin = -rad,
+ .xmax = rad,
+ .ymin = -rad,
+ .ymax = rad,
+ },
+ inner_color,
+ NULL,
+ 0.0f,
+ outline_color,
+ AXIS_RING_WIDTH,
+ rad);
+ GPU_matrix_pop();
+ }
- GPU_batch_program_set_builtin(sphere, GPU_SHADER_3D_UNIFORM_COLOR);
- GPU_batch_uniform_4fv(sphere, "color", is_pos_color ? color_current : color_current_fade);
- GPU_batch_draw(sphere);
- GPU_matrix_pop();
+ /* Axis XYZ Character. */
+ if ((is_pos || is_highlight || (axis == axis_align)) && !is_aligned_back) {
+ float axis_str_width, axis_string_height;
+ char axis_str[3] = {'X' + axis, 0, 0};
+ if (!is_pos) {
+ axis_str[0] = '-';
+ axis_str[1] = 'X' + axis;
}
-
- /* Axis XYZ Character. */
- if (show_axis_char && (select == false)) {
-#ifdef USE_AXIS_FONT
- float axis_str_size[2] = {0};
- const char axis_str[2] = {'X' + axis, 0};
- BLF_width_and_height(font.id, axis_str, 2, &axis_str_size[0], &axis_str_size[1]);
-
- /* Calculate pixel aligned location, without this text draws fuzzy. */
- float v_final_px[3];
- mul_v3_m3v3(v_final_px, font.matrix_m3_invert, v_final);
- /* Center the test and pixel align, it's important to round once
- * otherwise the characters are noticeably not-centered.
- * If this wasn't an issue we could use #BLF_position to place the text. */
- v_final_px[0] = roundf(v_final_px[0] - (axis_str_size[0] / 2.0f));
- v_final_px[1] = roundf(v_final_px[1] - (axis_str_size[1] / 2.0f));
- mul_m3_v3(font.matrix_m3, v_final_px);
-
- immUnbindProgram();
-
- GPU_matrix_push();
- GPU_matrix_translate_3fv(v_final_px);
- GPU_matrix_mul(font.matrix);
-
- BLF_draw_ascii(font.id, axis_str, 2);
- GPU_blend(GPU_BLEND_ALPHA); /* XXX, blf disables */
- GPU_matrix_pop();
-
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
-#else
- immUnbindProgram();
- immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- GPU_line_width(1.0f);
- float m3[3][3];
- copy_m3_m4(m3, gz->matrix_offset);
- immUniformColor4fv(axis_black);
- draw_xyz_wire(pos_id, m3, v_final, 1.0, axis);
- immUnbindProgram();
-#endif
+ BLF_width_and_height(font.id, axis_str, 3, &axis_str_width, &axis_string_height);
+
+ /* Calculate pixel-aligned location, without this text draws fuzzy. */
+ float v_final_px[3];
+ mul_v3_m3v3(v_final_px, font.matrix_m3_invert, v_final);
+ /* Center the text and pixel align, it's important to round once
+ * otherwise the characters are noticeably not-centered.
+ * If this wasn't an issue we could use #BLF_position to place the text. */
+ v_final_px[0] = roundf(v_final_px[0] - (axis_str_width * (is_pos ? 0.5f : 0.55f)));
+ v_final_px[1] = roundf(v_final_px[1] - (axis_string_height / 2.0f));
+ mul_m3_v3(font.matrix_m3, v_final_px);
+ GPU_matrix_push();
+ GPU_matrix_translate_3fv(v_final_px);
+ GPU_matrix_mul(font.matrix);
+ float text_color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ if (!is_highlight) {
+ zero_v4(text_color);
+ text_color[3] = is_active ? 1.0f : 0.9f;
}
+ BLF_color4fv(font.id, text_color);
+ BLF_draw_ascii(font.id, axis_str, 2);
+ GPU_matrix_pop();
}
}
- GPU_matrix_pop();
- immUnbindProgram();
-
if (use_project_matrix) {
GPU_matrix_pop_projection();
}
-}
-
-static void axis3d_draw_intern(const bContext *C,
- wmGizmo *gz,
- const bool select,
- const bool highlight)
-{
- const float *color = highlight ? gz->color_hi : gz->color;
- float matrix_final[4][4];
- float matrix_unit[4][4];
-
- unit_m4(matrix_unit);
-
- WM_gizmo_calc_matrix_final_params(gz,
- &((struct WM_GizmoMatrixParams){
- .matrix_offset = matrix_unit,
- }),
- matrix_final);
-
- GPU_matrix_push();
- GPU_matrix_mul(matrix_final);
-
- struct AxisDrawInfo draw_info;
-#ifdef USE_AXIS_FONT
- if (select == false) {
- copy_m4_m4(draw_info.matrix_final, matrix_final);
- }
-#endif
-#ifdef USE_FADE_BACKGROUND
- if (select == false) {
- ED_view3d_background_color_get(CTX_data_scene(C), CTX_wm_view3d(C), draw_info.color_bg);
- }
-#else
- UNUSED_VARS(C);
-#endif
-
- GPU_blend(GPU_BLEND_ALPHA);
- axis_geom_draw(gz, color, select, &draw_info);
GPU_blend(GPU_BLEND_NONE);
+ BLF_disable(font.id, BLF_BOLD);
GPU_matrix_pop();
}
-static void gizmo_axis_draw(const bContext *C, wmGizmo *gz)
-{
- const bool is_modal = gz->state & WM_GIZMO_STATE_MODAL;
- const bool is_highlight = (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
-
- (void)is_modal;
-
- GPU_blend(GPU_BLEND_ALPHA);
- axis3d_draw_intern(C, gz, false, is_highlight);
- GPU_blend(GPU_BLEND_NONE);
-}
-
static int gizmo_axis_test_select(bContext *UNUSED(C), wmGizmo *gz, const int mval[2])
{
float point_local[2] = {UNPACK2(mval)};
@@ -601,12 +367,19 @@ static int gizmo_axis_test_select(bContext *UNUSED(C), wmGizmo *gz, const int mv
return -1;
}
-static int gizmo_axis_cursor_get(wmGizmo *gz)
+static int gizmo_axis_cursor_get(wmGizmo *UNUSED(gz))
{
- if (gz->highlight_part > 0) {
- return WM_CURSOR_EDIT;
- }
- return WM_CURSOR_NSEW_SCROLL;
+ return WM_CURSOR_DEFAULT;
+}
+
+static void gizmo_axis_screen_bounds_get(bContext *C, wmGizmo *gz, rcti *r_bounding_box)
+{
+ ScrArea *area = CTX_wm_area(C);
+ const float rad = WIDGET_RADIUS;
+ r_bounding_box->xmin = gz->matrix_basis[3][0] + area->totrct.xmin - rad;
+ r_bounding_box->ymin = gz->matrix_basis[3][1] + area->totrct.ymin - rad;
+ r_bounding_box->xmax = r_bounding_box->xmin + rad;
+ r_bounding_box->ymax = r_bounding_box->ymin + rad;
}
void VIEW3D_GT_navigate_rotate(wmGizmoType *gzt)
@@ -618,6 +391,7 @@ void VIEW3D_GT_navigate_rotate(wmGizmoType *gzt)
gzt->draw = gizmo_axis_draw;
gzt->test_select = gizmo_axis_test_select;
gzt->cursor_get = gizmo_axis_cursor_get;
+ gzt->screen_bounds_get = gizmo_axis_screen_bounds_get;
gzt->struct_size = sizeof(wmGizmo);
}
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 35ec4de5077..9ee6e44f825 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -2494,8 +2494,7 @@ static int view3d_select_exec(bContext *C, wmOperator *op)
}
/* Pass-through allows tweaks
- * FINISHED to signal one operator worked
- * */
+ * FINISHED to signal one operator worked. */
if (retval) {
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index 2b7b8255068..a6a77ecd5f7 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -224,13 +224,11 @@ void view3d_region_operator_needs_opengl(wmWindow *UNUSED(win), ARegion *region)
*/
void ED_view3d_polygon_offset(const RegionView3D *rv3d, const float dist)
{
- float viewdist;
-
if (rv3d->rflag & RV3D_ZOFFSET_DISABLED) {
return;
}
- viewdist = rv3d->dist;
+ float viewdist = rv3d->dist;
/* special exception for ortho camera (viewdist isnt used for perspective cameras) */
if (dist != 0.0f) {
@@ -248,7 +246,6 @@ bool ED_view3d_context_activate(bContext *C)
{
bScreen *screen = CTX_wm_screen(C);
ScrArea *area = CTX_wm_area(C);
- ARegion *region;
/* area can be NULL when called from python */
if (area == NULL || area->spacetype != SPACE_VIEW3D) {
@@ -259,7 +256,7 @@ bool ED_view3d_context_activate(bContext *C)
return false;
}
- region = BKE_area_find_region_active_win(area);
+ ARegion *region = BKE_area_find_region_active_win(area);
if (region == NULL) {
return false;
}
@@ -282,9 +279,7 @@ void ED_view3d_clipping_calc_from_boundbox(float clip[4][4],
const BoundBox *bb,
const bool is_flip)
{
- int val;
-
- for (val = 0; val < 4; val++) {
+ for (int val = 0; val < 4; val++) {
normal_tri_v3(clip[val], bb->vec[val], bb->vec[val == 3 ? 0 : val + 1], bb->vec[val + 4]);
if (UNLIKELY(is_flip)) {
negate_v3(clip[val]);
@@ -752,14 +747,12 @@ bool ED_view3d_camera_lock_autokey(View3D *v3d,
static void view3d_boxview_clip(ScrArea *area)
{
- ARegion *region;
BoundBox *bb = MEM_callocN(sizeof(BoundBox), "clipbb");
float clip[6][4];
float x1 = 0.0f, y1 = 0.0f, z1 = 0.0f, ofs[3] = {0.0f, 0.0f, 0.0f};
- int val;
/* create bounding box */
- for (region = area->regionbase.first; region; region = region->next) {
+ LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
if (region->regiontype == RGN_TYPE_WINDOW) {
RegionView3D *rv3d = region->regiondata;
@@ -794,7 +787,7 @@ static void view3d_boxview_clip(ScrArea *area)
}
}
- for (val = 0; val < 8; val++) {
+ for (int val = 0; val < 8; val++) {
if (ELEM(val, 0, 3, 4, 7)) {
bb->vec[val][0] = -x1 - ofs[0];
}
@@ -826,12 +819,12 @@ static void view3d_boxview_clip(ScrArea *area)
normal_tri_v3(clip[5], bb->vec[0], bb->vec[2], bb->vec[1]);
/* then plane equations */
- for (val = 0; val < 6; val++) {
+ for (int val = 0; val < 6; val++) {
clip[val][3] = -dot_v3v3(clip[val], bb->vec[val % 5]);
}
/* create bounding box */
- for (region = area->regionbase.first; region; region = region->next) {
+ LISTBASE_FOREACH (ARegion *, region, &area->regionbase) {
if (region->regiontype == RGN_TYPE_WINDOW) {
RegionView3D *rv3d = region->regiondata;
@@ -950,11 +943,10 @@ void ED_view3d_quadview_update(ScrArea *area, ARegion *region, bool do_clip)
{
ARegion *region_sync = NULL;
RegionView3D *rv3d = region->regiondata;
- short viewlock;
/* this function copies flags from the first of the 3 other quadview
* regions to the 2 other, so it assumes this is the region whose
* properties are always being edited, weak */
- viewlock = rv3d->viewlock;
+ short viewlock = rv3d->viewlock;
if ((viewlock & RV3D_LOCK_ROTATION) == 0) {
do_clip = (viewlock & RV3D_BOXCLIP) != 0;
@@ -1015,10 +1007,7 @@ void ED_view3d_quadview_update(ScrArea *area, ARegion *region, bool do_clip)
static float view_autodist_depth_margin(ARegion *region, const int mval[2], int margin)
{
- ViewDepths depth_temp = {0};
rcti rect;
- float depth_close;
-
if (margin == 0) {
/* Get Z Depths, needed for perspective, nice for ortho */
rect.xmin = mval[0];
@@ -1030,8 +1019,9 @@ static float view_autodist_depth_margin(ARegion *region, const int mval[2], int
BLI_rcti_init_pt_radius(&rect, mval, margin);
}
+ ViewDepths depth_temp = {0};
view3d_update_depths_rect(region, &depth_temp, &rect);
- depth_close = view3d_depth_near(&depth_temp);
+ float depth_close = view3d_depth_near(&depth_temp);
MEM_SAFE_FREE(depth_temp.depths);
return depth_close;
}
@@ -1053,14 +1043,13 @@ bool ED_view3d_autodist(Depsgraph *depsgraph,
{
float depth_close;
int margin_arr[] = {0, 2, 4};
- int i;
bool depth_ok = false;
/* Get Z Depths, needed for perspective, nice for ortho */
ED_view3d_draw_depth(depsgraph, region, v3d, alphaoverride);
/* Attempt with low margin's first */
- i = 0;
+ int i = 0;
do {
depth_close = view_autodist_depth_margin(region, mval, margin_arr[i++] * U.pixelsize);
depth_ok = (depth_close != FLT_MAX);
@@ -1104,9 +1093,8 @@ bool ED_view3d_autodist_simple(ARegion *region,
int margin,
const float *force_depth)
{
- float depth;
-
/* Get Z Depths, needed for perspective, nice for ortho */
+ float depth;
if (force_depth) {
depth = *force_depth;
}
@@ -1237,7 +1225,6 @@ float ED_view3d_radius_to_dist(const View3D *v3d,
}
else {
float lens, sensor_size, zoom;
- float angle;
if (persp == RV3D_CAMOB) {
CameraParams params;
@@ -1259,7 +1246,7 @@ float ED_view3d_radius_to_dist(const View3D *v3d,
zoom = CAMERA_PARAM_ZOOM_INIT_PERSP;
}
- angle = focallength_to_fov(lens, sensor_size);
+ float angle = focallength_to_fov(lens, sensor_size);
/* zoom influences lens, correct this by scaling the angle as a distance
* (by the zoom-level) */
@@ -1319,14 +1306,13 @@ float ED_view3d_offset_distance(const float mat[4][4],
{
float pos[4] = {0.0f, 0.0f, 0.0f, 1.0f};
float dir[4] = {0.0f, 0.0f, 1.0f, 0.0f};
- float dist;
mul_m4_v4(mat, pos);
add_v3_v3(pos, ofs);
mul_m4_v4(mat, dir);
normalize_v3(dir);
- dist = dot_v3v3(pos, dir);
+ float dist = dot_v3v3(pos, dir);
if ((dist < FLT_EPSILON) && (fallback_dist != 0.0f)) {
dist = fallback_dist;