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/CMakeLists.txt3
-rw-r--r--source/blender/editors/space_view3d/drawobject.c25
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c21
-rw-r--r--source/blender/editors/space_view3d/view3d_buttons.c5
-rw-r--r--source/blender/editors/space_view3d/view3d_cursor_snap.c181
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c18
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c9
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_armature.c8
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_camera.c10
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_empty.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_forcefield.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_light.c12
-rw-r--r--source/blender/editors/space_view3d/view3d_gizmo_ruler.c14
-rw-r--r--source/blender/editors/space_view3d/view3d_header.c5
-rw-r--r--source/blender/editors/space_view3d/view3d_intern.h10
-rw-r--r--source/blender/editors/space_view3d/view3d_iterators.c33
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate.c87
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate.h24
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_dolly.c1
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_fly.c6
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_move.c1
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_ndof.c7
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_roll.c13
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_rotate.c1
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_smoothview.c278
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_walk.c112
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_zoom.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_navigate_zoom_border.c11
-rw-r--r--source/blender/editors/space_view3d/view3d_select.cc (renamed from source/blender/editors/space_view3d/view3d_select.c)747
-rw-r--r--source/blender/editors/space_view3d/view3d_utils.c62
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c25
31 files changed, 1035 insertions, 704 deletions
diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt
index a76cd3377bc..100266f4433 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -15,7 +15,6 @@ set(INC
../../makesrna
../../render
../../windowmanager
- ../../../../intern/glew-mx
../../../../intern/guardedalloc
../../../../intern/mantaflow/extern
@@ -61,7 +60,7 @@ set(SRC
view3d_ops.c
view3d_placement.c
view3d_project.c
- view3d_select.c
+ view3d_select.cc
view3d_snap.c
view3d_utils.c
view3d_view.c
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 8add6886584..36ced74a8b7 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -16,6 +16,7 @@
#include "BKE_customdata.h"
#include "BKE_editmesh.h"
#include "BKE_global.h"
+#include "BKE_mesh.h"
#include "BKE_object.h"
#include "DEG_depsgraph.h"
@@ -67,9 +68,9 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
if (facemap_data) {
GPU_blend(GPU_BLEND_ALPHA);
- const MVert *mvert = me->mvert;
- const MPoly *mpoly = me->mpoly;
- const MLoop *mloop = me->mloop;
+ const MVert *verts = BKE_mesh_verts(me);
+ const MPoly *polys = BKE_mesh_polys(me);
+ const MLoop *loops = BKE_mesh_loops(me);
int mpoly_len = me->totpoly;
int mloop_len = me->totloop;
@@ -95,12 +96,12 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
int i;
if (me->runtime.looptris.array) {
const MLoopTri *mlt = me->runtime.looptris.array;
- for (mp = mpoly, i = 0; i < mpoly_len; i++, mp++) {
+ for (mp = polys, i = 0; i < mpoly_len; i++, mp++) {
if (facemap_data[i] == facemap) {
for (int j = 2; j < mp->totloop; j++) {
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), mvert[mloop[mlt->tri[0]].v].co);
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), mvert[mloop[mlt->tri[1]].v].co);
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), mvert[mloop[mlt->tri[2]].v].co);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[loops[mlt->tri[0]].v].co);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[loops[mlt->tri[1]].v].co);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[loops[mlt->tri[2]].v].co);
vbo_len_used += 3;
mlt++;
}
@@ -112,15 +113,15 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
}
else {
/* No tessellation data, fan-fill. */
- for (mp = mpoly, i = 0; i < mpoly_len; i++, mp++) {
+ for (mp = polys, i = 0; i < mpoly_len; i++, mp++) {
if (facemap_data[i] == facemap) {
- const MLoop *ml_start = &mloop[mp->loopstart];
+ const MLoop *ml_start = &loops[mp->loopstart];
const MLoop *ml_a = ml_start + 1;
const MLoop *ml_b = ml_start + 2;
for (int j = 2; j < mp->totloop; j++) {
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), mvert[ml_start->v].co);
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), mvert[ml_a->v].co);
- copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), mvert[ml_b->v].co);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[ml_start->v].co);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[ml_a->v].co);
+ copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), verts[ml_b->v].co);
vbo_len_used += 3;
ml_a++;
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 9ed2fec96db..86c796e6be4 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -960,7 +960,7 @@ static void view3d_widgets(void)
WM_gizmogrouptype_append_and_link(gzmap_type, VIEW3D_GGT_camera);
WM_gizmogrouptype_append_and_link(gzmap_type, VIEW3D_GGT_camera_view);
WM_gizmogrouptype_append_and_link(gzmap_type, VIEW3D_GGT_empty_image);
- /* TODO(campbell): Not working well enough, disable for now. */
+ /* TODO(@campbellbarton): Not working well enough, disable for now. */
#if 0
WM_gizmogrouptype_append_and_link(gzmap_type, VIEW3D_GGT_armature_spline);
#endif
@@ -1037,7 +1037,7 @@ 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 wmNotifier *wmn = params->notifier;
const Scene *scene = params->scene;
View3D *v3d = area->spacedata.first;
RegionView3D *rv3d = region->regiondata;
@@ -1210,6 +1210,9 @@ static void view3d_main_region_listener(const wmRegionListenerParams *params)
break;
}
break;
+ case NC_NODE:
+ ED_region_tag_redraw(region);
+ break;
case NC_WORLD:
switch (wmn->data) {
case ND_WORLD_DRAW:
@@ -1300,6 +1303,10 @@ static void view3d_main_region_listener(const wmRegionListenerParams *params)
ED_region_tag_redraw(region);
}
break;
+ case NC_WORKSPACE:
+ /* In case the region displays workspace settings. */
+ ED_region_tag_redraw(region);
+ break;
}
}
@@ -1398,7 +1405,7 @@ static void view3d_main_region_message_subscribe(const wmRegionMessageSubscribeP
WM_msg_subscribe_rna_anon_type(mbus, ObjectDisplay, &msg_sub_value_region_tag_redraw);
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *obact = OBACT(view_layer);
+ Object *obact = BKE_view_layer_active_object_get(view_layer);
if (obact != NULL) {
switch (obact->mode) {
case OB_MODE_PARTICLE_EDIT:
@@ -1433,7 +1440,7 @@ static void view3d_main_region_cursor(wmWindow *win, ScrArea *area, ARegion *reg
}
ViewLayer *view_layer = WM_window_get_active_view_layer(win);
- Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
+ Object *obedit = BKE_view_layer_edit_object_get(view_layer);
if (obedit) {
WM_cursor_set(win, WM_CURSOR_EDIT);
}
@@ -1460,7 +1467,7 @@ static void view3d_header_region_draw(const bContext *C, ARegion *region)
static void view3d_header_region_listener(const wmRegionListenerParams *params)
{
ARegion *region = params->region;
- wmNotifier *wmn = params->notifier;
+ const wmNotifier *wmn = params->notifier;
/* context changes */
switch (wmn->category) {
@@ -1677,7 +1684,7 @@ static void view3d_buttons_region_layout(const bContext *C, ARegion *region)
static void view3d_buttons_region_listener(const wmRegionListenerParams *params)
{
ARegion *region = params->region;
- wmNotifier *wmn = params->notifier;
+ const wmNotifier *wmn = params->notifier;
/* context changes */
switch (wmn->category) {
@@ -1800,7 +1807,7 @@ static void view3d_tools_region_draw(const bContext *C, ARegion *region)
static void space_view3d_listener(const wmSpaceTypeListenerParams *params)
{
ScrArea *area = params->area;
- wmNotifier *wmn = params->notifier;
+ const wmNotifier *wmn = params->notifier;
View3D *v3d = area->spacedata.first;
/* context changes */
diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c
index 6786bf8404e..5a5747bdf84 100644
--- a/source/blender/editors/space_view3d/view3d_buttons.c
+++ b/source/blender/editors/space_view3d/view3d_buttons.c
@@ -36,6 +36,7 @@
#include "BKE_customdata.h"
#include "BKE_deform.h"
#include "BKE_editmesh.h"
+#include "BKE_layer.h"
#include "BKE_object.h"
#include "BKE_object_deform.h"
#include "BKE_report.h"
@@ -1283,7 +1284,7 @@ static void do_view3d_vgroup_buttons(bContext *C, void *UNUSED(arg), int event)
static bool view3d_panel_vgroup_poll(const bContext *C, PanelType *UNUSED(pt))
{
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
if (ob && (BKE_object_is_in_editmode_vgroup(ob) || BKE_object_is_in_wpaint_select_vert(ob))) {
MDeformVert *dvert_act = ED_mesh_active_dvert_get_only(ob);
if (dvert_act) {
@@ -1683,7 +1684,7 @@ static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event
{
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
switch (event) {
diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.c b/source/blender/editors/space_view3d/view3d_cursor_snap.c
index 395df42b2cb..195806fbecc 100644
--- a/source/blender/editors/space_view3d/view3d_cursor_snap.c
+++ b/source/blender/editors/space_view3d/view3d_cursor_snap.c
@@ -16,6 +16,7 @@
#include "BKE_context.h"
#include "BKE_global.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_scene.h"
@@ -495,6 +496,16 @@ static void v3d_cursor_eventstate_save_xy(SnapCursorDataIntern *cursor_snap,
}
#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
+static void v3d_cursor_eventstate_save_modifier(SnapCursorDataIntern *data_intern,
+ const wmWindowManager *wm)
+{
+ if (!wm || !wm->winactive) {
+ return;
+ }
+ const wmEvent *event = wm->winactive->eventstate;
+ data_intern->last_eventstate.modifier = event->modifier;
+}
+
static bool v3d_cursor_is_snap_invert(SnapCursorDataIntern *data_intern, const wmWindowManager *wm)
{
if (!wm || !wm->winactive) {
@@ -582,10 +593,14 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state,
{
SnapCursorDataIntern *data_intern = &g_data_intern;
V3DSnapCursorData *snap_data = &data_intern->snap_data;
- v3d_cursor_snap_context_ensure(scene);
+
+ const bool use_surface_nor = state->plane_orient == V3D_PLACE_ORIENT_SURFACE;
+ const bool use_surface_co = state->plane_depth == V3D_PLACE_DEPTH_SURFACE;
+ const bool calc_plane_omat = v3d_cursor_snap_calc_plane();
float co[3], no[3], face_nor[3], obmat[4][4], omat[3][3];
eSnapMode snap_elem = SCE_SNAP_MODE_NONE;
+ eSnapMode snap_elements = v3d_cursor_snap_elements(state, scene);
int snap_elem_index[3] = {-1, -1, -1};
int index = -1;
@@ -594,86 +609,90 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state,
zero_v3(face_nor);
unit_m3(omat);
- eSnapMode snap_elements = v3d_cursor_snap_elements(state, scene);
- data_intern->snap_elem_hidden = SCE_SNAP_MODE_NONE;
- const bool calc_plane_omat = v3d_cursor_snap_calc_plane();
- if (calc_plane_omat && !(snap_elements & SCE_SNAP_MODE_FACE)) {
- data_intern->snap_elem_hidden = SCE_SNAP_MODE_FACE;
- snap_elements |= SCE_SNAP_MODE_FACE;
- }
+ if (use_surface_nor || use_surface_co) {
+ v3d_cursor_snap_context_ensure(scene);
+
+ data_intern->snap_elem_hidden = SCE_SNAP_MODE_NONE;
+ if (calc_plane_omat && !(snap_elements & SCE_SNAP_MODE_FACE_RAYCAST)) {
+ data_intern->snap_elem_hidden = SCE_SNAP_MODE_FACE_RAYCAST;
+ snap_elements |= SCE_SNAP_MODE_FACE_RAYCAST;
+ }
- snap_data->is_enabled = true;
+ snap_data->is_enabled = true;
#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
- if (!(state->flag & V3D_SNAPCURSOR_TOGGLE_ALWAYS_TRUE)) {
- snap_data->is_snap_invert = v3d_cursor_is_snap_invert(data_intern, wm);
-
- const ToolSettings *ts = scene->toolsettings;
- if (snap_data->is_snap_invert != !(ts->snap_flag & SCE_SNAP)) {
- snap_data->is_enabled = false;
- if (!calc_plane_omat) {
- snap_data->snap_elem = SCE_SNAP_MODE_NONE;
- return;
+ if (!(state->flag & V3D_SNAPCURSOR_TOGGLE_ALWAYS_TRUE)) {
+ snap_data->is_snap_invert = v3d_cursor_is_snap_invert(data_intern, wm);
+
+ const ToolSettings *ts = scene->toolsettings;
+ if (snap_data->is_snap_invert != !(ts->snap_flag & SCE_SNAP)) {
+ snap_data->is_enabled = false;
+ if (!calc_plane_omat) {
+ snap_data->snap_elem = SCE_SNAP_MODE_NONE;
+ return;
+ }
+ snap_elements = data_intern->snap_elem_hidden = SCE_SNAP_MODE_FACE_RAYCAST;
}
- snap_elements = data_intern->snap_elem_hidden = SCE_SNAP_MODE_FACE;
}
- }
#endif
- if (snap_elements & SCE_SNAP_MODE_GEOM) {
- float prev_co[3] = {0.0f};
- if (state->prevpoint) {
- copy_v3_v3(prev_co, state->prevpoint);
- }
- else {
- snap_elements &= ~SCE_SNAP_MODE_EDGE_PERPENDICULAR;
- }
+ if (snap_elements & SCE_SNAP_MODE_GEOM) {
+ float prev_co[3] = {0.0f};
+ if (state->prevpoint) {
+ copy_v3_v3(prev_co, state->prevpoint);
+ }
+ else {
+ snap_elements &= ~SCE_SNAP_MODE_EDGE_PERPENDICULAR;
+ }
- eSnapEditType edit_mode_type = (state->flag & V3D_SNAPCURSOR_SNAP_EDIT_GEOM_FINAL) ?
- SNAP_GEOM_FINAL :
- (state->flag & V3D_SNAPCURSOR_SNAP_EDIT_GEOM_CAGE) ?
- SNAP_GEOM_CAGE :
- SNAP_GEOM_EDIT;
-
- bool use_occlusion_test = (state->flag & V3D_SNAPCURSOR_OCCLUSION_ALWAYS_TRUE) ? false : true;
-
- float dist_px = 12.0f * U.pixelsize;
-
- snap_elem = ED_transform_snap_object_project_view3d_ex(
- data_intern->snap_context_v3d,
- depsgraph,
- region,
- v3d,
- snap_elements,
- &(const struct SnapObjectParams){
- .snap_target_select = SCE_SNAP_TARGET_ALL,
- .edit_mode_type = edit_mode_type,
- .use_occlusion_test = use_occlusion_test,
- },
- mval_fl,
- prev_co,
- &dist_px,
- co,
- no,
- &index,
- NULL,
- obmat,
- face_nor);
- }
-
- if (is_zero_v3(face_nor)) {
- face_nor[state->plane_axis] = 1.0f;
+ eSnapEditType edit_mode_type = (state->flag & V3D_SNAPCURSOR_SNAP_EDIT_GEOM_FINAL) ?
+ SNAP_GEOM_FINAL :
+ (state->flag & V3D_SNAPCURSOR_SNAP_EDIT_GEOM_CAGE) ?
+ SNAP_GEOM_CAGE :
+ SNAP_GEOM_EDIT;
+
+ bool use_occlusion_test = (state->flag & V3D_SNAPCURSOR_OCCLUSION_ALWAYS_TRUE) ? false :
+ true;
+
+ float dist_px = 12.0f * U.pixelsize;
+
+ snap_elem = ED_transform_snap_object_project_view3d_ex(
+ data_intern->snap_context_v3d,
+ depsgraph,
+ region,
+ v3d,
+ snap_elements,
+ &(const struct SnapObjectParams){
+ .snap_target_select = SCE_SNAP_TARGET_ALL,
+ .edit_mode_type = edit_mode_type,
+ .use_occlusion_test = use_occlusion_test,
+ },
+ NULL,
+ mval_fl,
+ prev_co,
+ &dist_px,
+ co,
+ no,
+ &index,
+ NULL,
+ obmat,
+ face_nor);
+ }
}
+#ifdef USE_SNAP_DETECT_FROM_KEYMAP_HACK
+ else {
+ v3d_cursor_eventstate_save_modifier(data_intern, wm);
+ }
+#endif
if (calc_plane_omat) {
RegionView3D *rv3d = region->regiondata;
- bool orient_surface = (snap_elem != SCE_SNAP_MODE_NONE) &&
- (state->plane_orient == V3D_PLACE_ORIENT_SURFACE);
+ bool orient_surface = use_surface_nor && (snap_elem != SCE_SNAP_MODE_NONE);
if (orient_surface) {
copy_m3_m4(omat, obmat);
}
else {
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
const int orient_index = BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT);
const int pivot_point = scene->toolsettings->transform_pivot_point;
ED_transform_calc_orientation_from_type_ex(
@@ -691,16 +710,40 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state,
orthogonalize_m3(omat, state->plane_axis);
if (orient_surface) {
- if (dot_v3v3(rv3d->viewinv[2], face_nor) < 0.0f) {
- negate_v3(face_nor);
+ if (!is_zero_v3(face_nor)) {
+ /* Negate the face normal according to the view. */
+ float ray_dir[3];
+ if (rv3d->is_persp) {
+ BLI_assert_msg(snap_elem != SCE_SNAP_MODE_NONE,
+ "Use of variable `co` without it being computed");
+
+ sub_v3_v3v3(ray_dir, co, rv3d->viewinv[3]); /* No need to normalize. */
+ }
+ else {
+ negate_v3_v3(ray_dir, rv3d->viewinv[2]);
+ }
+
+ if (dot_v3v3(ray_dir, face_nor) >= 0.0f) {
+ negate_v3(face_nor);
+ }
+ }
+ else if (!is_zero_v3(no)) {
+ copy_v3_v3(face_nor, no);
+ }
+ else {
+ face_nor[state->plane_axis] = 1.0f;
}
v3d_cursor_poject_surface_normal(face_nor, obmat, omat);
}
}
+ if (!use_surface_co) {
+ snap_elem = SCE_SNAP_MODE_NONE;
+ }
+
float *co_depth = (snap_elem != SCE_SNAP_MODE_NONE) ? co : scene->cursor.location;
snap_elem &= ~data_intern->snap_elem_hidden;
- if (snap_elem == 0) {
+ if (snap_elem == SCE_SNAP_MODE_NONE) {
RegionView3D *rv3d = region->regiondata;
const float *plane_normal = omat[state->plane_axis];
bool do_plane_isect = (state->plane_depth != V3D_PLACE_DEPTH_CURSOR_VIEW) &&
@@ -728,7 +771,7 @@ static void v3d_cursor_snap_update(V3DSnapCursorState *state,
(SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_EDGE_MIDPOINT | SCE_SNAP_MODE_EDGE_PERPENDICULAR)) {
snap_elem_index[1] = index;
}
- else if (snap_elem == SCE_SNAP_MODE_FACE) {
+ else if (snap_elem == SCE_SNAP_MODE_FACE_RAYCAST) {
snap_elem_index[2] = index;
}
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index b9e4c19295d..7ae1b86806a 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -567,7 +567,7 @@ static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region,
/* First, solid lines. */
{
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
/* passepartout, specified in camera edit buttons */
if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001f) {
@@ -618,7 +618,7 @@ static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region,
}
/* And now, the dashed lines! */
- immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR);
{
float viewport_size[4];
@@ -800,7 +800,7 @@ static void drawrenderborder(ARegion *region, View3D *v3d)
GPU_line_width(1.0f);
- immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR);
float viewport_size[4];
GPU_viewport_size_get_f(viewport_size);
@@ -982,7 +982,7 @@ static void draw_view_axis(RegionView3D *rv3d, const rcti *rect)
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
- immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR);
immBegin(GPU_PRIM_LINES, 6);
for (int axis_i = 0; axis_i < 3; axis_i++) {
@@ -1294,7 +1294,7 @@ static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *y
static void draw_selected_name(
Scene *scene, ViewLayer *view_layer, Object *ob, int xoffset, int *yoffset)
{
- const int cfra = CFRA;
+ const int cfra = scene->r.cfra;
const char *msg_pin = " (Pinned)";
const char *msg_sep = " : ";
@@ -1497,7 +1497,7 @@ void view3d_draw_region_info(const bContext *C, ARegion *region)
}
if (U.uiflag & USER_DRAWVIEWINFO) {
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
draw_selected_name(scene, view_layer, ob, xoffset, &yoffset);
}
@@ -2247,16 +2247,16 @@ void view3d_depths_rect_create(ARegion *region, rcti *rect, ViewDepths *r_d)
static ViewDepths *view3d_depths_create(ARegion *region)
{
ViewDepths *d = MEM_callocN(sizeof(ViewDepths), "ViewDepths");
- d->w = region->winx;
- d->h = region->winy;
{
GPUViewport *viewport = WM_draw_region_get_viewport(region);
GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport);
uint32_t *int_depths = GPU_texture_read(depth_tx, GPU_DATA_UINT_24_8, 0);
+ d->w = GPU_texture_width(depth_tx);
+ d->h = GPU_texture_height(depth_tx);
d->depths = (float *)int_depths;
/* Convert in-place. */
- int pixel_count = GPU_texture_width(depth_tx) * GPU_texture_height(depth_tx);
+ int pixel_count = d->w * d->h;
for (int i = 0; i < pixel_count; i++) {
d->depths[i] = (int_depths[i] >> 8u) / (float)0xFFFFFF;
}
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 5fbdbef676c..6001f701c00 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -413,7 +413,9 @@ static void view3d_set_1_to_1_viewborder(Scene *scene,
{
RegionView3D *rv3d = region->regiondata;
float size[2];
- int im_width = (scene->r.size * scene->r.xsch) / 100;
+
+ int im_width, im_height;
+ BKE_render_resolution(&scene->r, false, &im_width, &im_height);
ED_view3d_calc_camera_border_size(scene, depsgraph, region, v3d, rv3d, size);
@@ -695,7 +697,7 @@ static int drop_world_exec(bContext *C, wmOperator *op)
id_us_plus(&world->id);
scene->world = world;
- DEG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_SCENE | ND_WORLD, scene);
@@ -908,12 +910,13 @@ void ED_view3d_cursor3d_position_rotation(bContext *C,
CTX_data_ensure_evaluated_depsgraph(C),
region,
v3d,
- SCE_SNAP_MODE_FACE,
+ SCE_SNAP_MODE_FACE_RAYCAST,
&(const struct SnapObjectParams){
.snap_target_select = SCE_SNAP_TARGET_ALL,
.edit_mode_type = SNAP_GEOM_FINAL,
.use_occlusion_test = true,
},
+ NULL,
mval_fl,
NULL,
&dist_px,
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_armature.c b/source/blender/editors/space_view3d/view3d_gizmo_armature.c
index 3f6167d92ca..89b46069df1 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_armature.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_armature.c
@@ -37,7 +37,7 @@
* \{ */
/*
- * TODO(campbell): Current conversion is a approximation (usable not correct),
+ * TODO(@campbellbarton): Current conversion is a approximation (usable not correct),
* we'll need to take the next/previous bones into account to get the tangent directions.
* First last matrices from 'BKE_pchan_bbone_spline_setup' are close but also not quite accurate
* since they're not at either end-points on the curve.
@@ -114,7 +114,7 @@ static bool WIDGETGROUP_armature_spline_poll(const bContext *C, wmGizmoGroupType
}
ViewLayer *view_layer = CTX_data_view_layer(C);
- Base *base = BASACT(view_layer);
+ Base *base = view_layer->basact;
if (base && BASE_SELECTABLE(v3d, base)) {
Object *ob = BKE_object_pose_armature_get(base->object);
if (ob) {
@@ -133,7 +133,7 @@ static bool WIDGETGROUP_armature_spline_poll(const bContext *C, wmGizmoGroupType
static void WIDGETGROUP_armature_spline_setup(const bContext *C, wmGizmoGroup *gzgroup)
{
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = BKE_object_pose_armature_get(OBACT(view_layer));
+ Object *ob = BKE_object_pose_armature_get(BKE_view_layer_active_object_get(view_layer));
bPoseChannel *pchan = BKE_pose_channel_active_if_layer_visible(ob);
const wmGizmoType *gzt_move = WM_gizmotype_find("GIZMO_GT_move_3d", true);
@@ -166,7 +166,7 @@ static void WIDGETGROUP_armature_spline_setup(const bContext *C, wmGizmoGroup *g
static void WIDGETGROUP_armature_spline_refresh(const bContext *C, wmGizmoGroup *gzgroup)
{
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = BKE_object_pose_armature_get(OBACT(view_layer));
+ Object *ob = BKE_object_pose_armature_get(BKE_view_layer_active_object_get(view_layer));
if (!gzgroup->customdata) {
return;
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_camera.c b/source/blender/editors/space_view3d/view3d_gizmo_camera.c
index 83f589a64c9..d4720d01d70 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_camera.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_camera.c
@@ -56,7 +56,7 @@ static bool WIDGETGROUP_camera_poll(const bContext *C, wmGizmoGroupType *UNUSED(
}
ViewLayer *view_layer = CTX_data_view_layer(C);
- Base *base = BASACT(view_layer);
+ Base *base = view_layer->basact;
if (base && BASE_SELECTABLE(v3d, base)) {
Object *ob = base->object;
if (ob->type == OB_CAMERA) {
@@ -73,7 +73,7 @@ static bool WIDGETGROUP_camera_poll(const bContext *C, wmGizmoGroupType *UNUSED(
static void WIDGETGROUP_camera_setup(const bContext *C, wmGizmoGroup *gzgroup)
{
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
float dir[3];
const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true);
@@ -125,7 +125,7 @@ static void WIDGETGROUP_camera_refresh(const bContext *C, wmGizmoGroup *gzgroup)
struct CameraWidgetGroup *cagzgroup = gzgroup->customdata;
View3D *v3d = CTX_wm_view3d(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
Camera *ca = ob->data;
PointerRNA camera_ptr;
float dir[3];
@@ -242,7 +242,7 @@ static void WIDGETGROUP_camera_message_subscribe(const bContext *C,
{
ARegion *region = CTX_wm_region(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
Camera *ca = ob->data;
wmMsgSubscribeValue msg_sub_value_gz_tag_refresh = {
@@ -370,7 +370,7 @@ static bool WIDGETGROUP_camera_view_poll(const bContext *C, wmGizmoGroupType *UN
* We could change the rules for when to show. */
{
ViewLayer *view_layer = CTX_data_view_layer(C);
- if (scene->camera != OBACT(view_layer)) {
+ if (scene->camera != BKE_view_layer_active_object_get(view_layer)) {
return false;
}
}
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_empty.c b/source/blender/editors/space_view3d/view3d_gizmo_empty.c
index f113cc60224..a7febe11672 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_empty.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_empty.c
@@ -100,7 +100,7 @@ static bool WIDGETGROUP_empty_image_poll(const bContext *C, wmGizmoGroupType *UN
}
ViewLayer *view_layer = CTX_data_view_layer(C);
- Base *base = BASACT(view_layer);
+ Base *base = view_layer->basact;
if (base && BASE_SELECTABLE(v3d, base)) {
Object *ob = base->object;
if (ob->type == OB_EMPTY) {
@@ -133,7 +133,7 @@ static void WIDGETGROUP_empty_image_refresh(const bContext *C, wmGizmoGroup *gzg
struct EmptyImageWidgetGroup *igzgroup = gzgroup->customdata;
wmGizmo *gz = igzgroup->gizmo;
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
copy_m4_m4(gz->matrix_basis, ob->obmat);
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_forcefield.c b/source/blender/editors/space_view3d/view3d_gizmo_forcefield.c
index 456e939eba7..f2f9e9092fa 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_forcefield.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_forcefield.c
@@ -43,7 +43,7 @@ static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmGizmoGroupType *UNU
}
ViewLayer *view_layer = CTX_data_view_layer(C);
- Base *base = BASACT(view_layer);
+ Base *base = view_layer->basact;
if (base && BASE_SELECTABLE(v3d, base)) {
Object *ob = base->object;
if (ob->pd && ob->pd->forcefield) {
@@ -74,7 +74,7 @@ static void WIDGETGROUP_forcefield_refresh(const bContext *C, wmGizmoGroup *gzgr
wmGizmoWrapper *wwrapper = gzgroup->customdata;
wmGizmo *gz = wwrapper->gizmo;
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
PartDeflect *pd = ob->pd;
if (pd->forcefield == PFIELD_WIND) {
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_light.c b/source/blender/editors/space_view3d/view3d_gizmo_light.c
index b3bc0bc70cb..d0f58f43c2b 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_light.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_light.c
@@ -46,7 +46,7 @@ static bool WIDGETGROUP_light_spot_poll(const bContext *C, wmGizmoGroupType *UNU
}
ViewLayer *view_layer = CTX_data_view_layer(C);
- Base *base = BASACT(view_layer);
+ Base *base = view_layer->basact;
if (base && BASE_SELECTABLE(v3d, base)) {
Object *ob = base->object;
if (ob->type == OB_LAMP) {
@@ -77,7 +77,7 @@ static void WIDGETGROUP_light_spot_refresh(const bContext *C, wmGizmoGroup *gzgr
wmGizmoWrapper *wwrapper = gzgroup->customdata;
wmGizmo *gz = wwrapper->gizmo;
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
Light *la = ob->data;
float dir[3];
@@ -157,7 +157,7 @@ static bool WIDGETGROUP_light_area_poll(const bContext *C, wmGizmoGroupType *UNU
}
ViewLayer *view_layer = CTX_data_view_layer(C);
- Base *base = BASACT(view_layer);
+ Base *base = view_layer->basact;
if (base && BASE_SELECTABLE(v3d, base)) {
Object *ob = base->object;
if (ob->type == OB_LAMP) {
@@ -187,7 +187,7 @@ static void WIDGETGROUP_light_area_refresh(const bContext *C, wmGizmoGroup *gzgr
{
wmGizmoWrapper *wwrapper = gzgroup->customdata;
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
Light *la = ob->data;
wmGizmo *gz = wwrapper->gizmo;
@@ -240,7 +240,7 @@ static bool WIDGETGROUP_light_target_poll(const bContext *C, wmGizmoGroupType *U
}
ViewLayer *view_layer = CTX_data_view_layer(C);
- Base *base = BASACT(view_layer);
+ Base *base = view_layer->basact;
if (base && BASE_SELECTABLE(v3d, base)) {
Object *ob = base->object;
if (ob->type == OB_LAMP) {
@@ -281,7 +281,7 @@ static void WIDGETGROUP_light_target_draw_prepare(const bContext *C, wmGizmoGrou
{
wmGizmoWrapper *wwrapper = gzgroup->customdata;
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
wmGizmo *gz = wwrapper->gizmo;
normalize_m4_m4(gz->matrix_basis, ob->obmat);
diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
index 9aae30c4a7e..41a0e137b03 100644
--- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c
@@ -17,6 +17,7 @@
#include "BKE_main.h"
#include "BKE_report.h"
+#include "BKE_layer.h"
#include "BKE_material.h"
#include "BKE_object.h"
#include "BKE_scene.h"
@@ -357,11 +358,12 @@ static bool view3d_ruler_item_mousemove(const bContext *C,
depsgraph,
ruler_info->region,
v3d,
- SCE_SNAP_MODE_FACE,
+ SCE_SNAP_MODE_FACE_RAYCAST,
&(const struct SnapObjectParams){
.snap_target_select = SCE_SNAP_TARGET_ALL,
.edit_mode_type = SNAP_GEOM_CAGE,
},
+ NULL,
mval_fl,
NULL,
&dist_px,
@@ -419,7 +421,7 @@ static bool view3d_ruler_item_mousemove(const bContext *C,
Scene *scene = DEG_get_input_scene(depsgraph);
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
RegionView3D *rv3d = ruler_info->region->regiondata;
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
Object *obedit = OBEDIT_FROM_OBACT(ob);
short orient_index = BKE_scene_orientation_get_index(scene, SCE_ORIENT_DEFAULT);
@@ -522,7 +524,7 @@ static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup)
gpl->flag |= GP_LAYER_HIDE | GP_LAYER_IS_RULER;
}
- gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_ADD_NEW);
+ gpf = BKE_gpencil_layer_frame_get(gpl, scene->r.cfra, GP_GETFRAME_ADD_NEW);
BKE_gpencil_free_strokes(gpf);
for (ruler_item = gzgroup_ruler_item_first_get(gzgroup); ruler_item;
@@ -576,7 +578,7 @@ static bool view3d_ruler_from_gpencil(const bContext *C, wmGizmoGroup *gzgroup)
gpl = view3d_ruler_layer_get(scene->gpd);
if (gpl) {
bGPDframe *gpf;
- gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_USE_PREV);
+ gpf = BKE_gpencil_layer_frame_get(gpl, scene->r.cfra, GP_GETFRAME_USE_PREV);
if (gpf) {
bGPDstroke *gps;
for (gps = gpf->strokes.first; gps; gps = gps->next) {
@@ -782,7 +784,7 @@ static void gizmo_ruler_draw(const bContext *C, wmGizmo *gz)
immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
if (ruler_item->flag & RULERITEM_USE_ANGLE) {
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
/* capping */
{
float rot_90_vec_a[2];
@@ -884,7 +886,7 @@ static void gizmo_ruler_draw(const bContext *C, wmGizmo *gz)
}
}
else {
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
sub_v2_v2v2(dir_ruler, co_ss[0], co_ss[2]);
diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c
index 6e8d9e96abd..90d108c23cc 100644
--- a/source/blender/editors/space_view3d/view3d_header.c
+++ b/source/blender/editors/space_view3d/view3d_header.c
@@ -20,6 +20,7 @@
#include "BKE_context.h"
#include "BKE_editmesh.h"
+#include "BKE_layer.h"
#include "DEG_depsgraph.h"
@@ -125,7 +126,7 @@ void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C)
static void uiTemplatePaintModeSelection(uiLayout *layout, struct bContext *C)
{
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
/* Gizmos aren't used in paint modes */
if (!ELEM(ob->mode, OB_MODE_SCULPT, OB_MODE_PARTICLE_EDIT)) {
@@ -147,7 +148,7 @@ static void uiTemplatePaintModeSelection(uiLayout *layout, struct bContext *C)
void uiTemplateHeader3D_mode(uiLayout *layout, struct bContext *C)
{
ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
Object *obedit = CTX_data_edit_object(C);
bGPdata *gpd = CTX_data_gpencil_data(C);
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index 53fc450107a..4c9e2595023 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -9,6 +9,10 @@
#include "ED_view3d.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* internal exports only */
struct ARegion;
@@ -83,7 +87,7 @@ void view3d_depths_rect_create(struct ARegion *region, struct rcti *rect, struct
*/
float view3d_depth_near(struct ViewDepths *d);
-/* view3d_select.c */
+/* view3d_select.cc */
void VIEW3D_OT_select(struct wmOperatorType *ot);
void VIEW3D_OT_select_circle(struct wmOperatorType *ot);
@@ -241,3 +245,7 @@ void VIEW3D_GGT_placement(struct wmGizmoGroupType *gzgt);
extern uchar view3d_camera_border_hack_col[3];
extern bool view3d_camera_border_hack_test;
#endif
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/editors/space_view3d/view3d_iterators.c b/source/blender/editors/space_view3d/view3d_iterators.c
index 4606908b91f..60141fd00cd 100644
--- a/source/blender/editors/space_view3d/view3d_iterators.c
+++ b/source/blender/editors/space_view3d/view3d_iterators.c
@@ -23,6 +23,7 @@
#include "BKE_curve.h"
#include "BKE_displist.h"
#include "BKE_editmesh.h"
+#include "BKE_mesh.h"
#include "BKE_mesh_iterators.h"
#include "BKE_mesh_runtime.h"
#include "BKE_mesh_wrapper.h"
@@ -205,6 +206,8 @@ typedef struct foreachScreenObjectVert_userData {
void (*func)(void *userData, MVert *mv, const float screen_co[2], int index);
void *userData;
ViewContext vc;
+ MVert *verts;
+ const bool *hide_vert;
eV3DProjTest clip_flag;
} foreachScreenObjectVert_userData;
@@ -262,18 +265,19 @@ static void meshobject_foreachScreenVert__mapFunc(void *userData,
const float UNUSED(no[3]))
{
foreachScreenObjectVert_userData *data = userData;
- struct MVert *mv = &((Mesh *)(data->vc.obact->data))->mvert[index];
-
- if (!(mv->flag & ME_HIDE)) {
- float screen_co[2];
+ if (data->hide_vert && data->hide_vert[index]) {
+ return;
+ }
+ MVert *mv = &data->verts[index];
- if (ED_view3d_project_float_object(data->vc.region, co, screen_co, data->clip_flag) !=
- V3D_PROJ_RET_OK) {
- return;
- }
+ float screen_co[2];
- data->func(data->userData, mv, screen_co, index);
+ if (ED_view3d_project_float_object(data->vc.region, co, screen_co, data->clip_flag) !=
+ V3D_PROJ_RET_OK) {
+ return;
}
+
+ data->func(data->userData, mv, screen_co, index);
}
void meshobject_foreachScreenVert(
@@ -297,6 +301,9 @@ void meshobject_foreachScreenVert(
data.func = func;
data.userData = userData;
data.clip_flag = clip_flag;
+ data.verts = BKE_mesh_verts_for_write((Mesh *)vc->obact->data);
+ data.hide_vert = (const bool *)CustomData_get_layer_named(
+ &me->vdata, CD_PROP_BOOL, ".hide_vert");
if (clip_flag & V3D_PROJ_TEST_CLIP_BB) {
ED_view3d_clipping_local(vc->rv3d, vc->obact->obmat);
@@ -335,7 +342,7 @@ void mesh_foreachScreenVert(
Mesh *me = editbmesh_get_eval_cage_from_orig(
vc->depsgraph, vc->scene, vc->obedit, &CD_MASK_BAREMESH);
- me = BKE_mesh_wrapper_ensure_subdivision(vc->obedit, me);
+ me = BKE_mesh_wrapper_ensure_subdivision(me);
ED_view3d_check_mats_rv3d(vc->rv3d);
@@ -398,7 +405,7 @@ void mesh_foreachScreenEdge(ViewContext *vc,
Mesh *me = editbmesh_get_eval_cage_from_orig(
vc->depsgraph, vc->scene, vc->obedit, &CD_MASK_BAREMESH);
- me = BKE_mesh_wrapper_ensure_subdivision(vc->obedit, me);
+ me = BKE_mesh_wrapper_ensure_subdivision(me);
ED_view3d_check_mats_rv3d(vc->rv3d);
@@ -486,7 +493,7 @@ void mesh_foreachScreenEdge_clip_bb_segment(ViewContext *vc,
Mesh *me = editbmesh_get_eval_cage_from_orig(
vc->depsgraph, vc->scene, vc->obedit, &CD_MASK_BAREMESH);
- me = BKE_mesh_wrapper_ensure_subdivision(vc->obedit, me);
+ me = BKE_mesh_wrapper_ensure_subdivision(me);
ED_view3d_check_mats_rv3d(vc->rv3d);
@@ -558,7 +565,7 @@ void mesh_foreachScreenFace(
Mesh *me = editbmesh_get_eval_cage_from_orig(
vc->depsgraph, vc->scene, vc->obedit, &CD_MASK_BAREMESH);
- me = BKE_mesh_wrapper_ensure_subdivision(vc->obedit, me);
+ me = BKE_mesh_wrapper_ensure_subdivision(me);
ED_view3d_check_mats_rv3d(vc->rv3d);
data.vc = *vc;
diff --git a/source/blender/editors/space_view3d/view3d_navigate.c b/source/blender/editors/space_view3d/view3d_navigate.c
index 50d7626a57d..684b3539943 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate.c
@@ -166,7 +166,7 @@ bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
View3D *v3d = CTX_wm_view3d(C);
- Object *ob_act_eval = OBACT(view_layer_eval);
+ Object *ob_act_eval = BKE_view_layer_active_object_get(view_layer_eval);
Object *ob_act = DEG_get_original_object(ob_act_eval);
if (ob_act && (ob_act->mode & OB_MODE_ALL_PAINT) &&
@@ -203,12 +203,11 @@ bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
}
else if (ob_act == NULL || ob_act->mode == OB_MODE_OBJECT) {
/* object mode use boundbox centers */
- Base *base_eval;
uint tot = 0;
float select_center[3];
zero_v3(select_center);
- for (base_eval = FIRSTBASE(view_layer_eval); base_eval; base_eval = base_eval->next) {
+ LISTBASE_FOREACH (Base *, base_eval, &view_layer_eval->object_bases) {
if (BASE_SELECTED(v3d, base_eval)) {
/* use the boundbox if we can */
Object *ob_eval = base_eval->object;
@@ -495,6 +494,8 @@ static void axis_set_view(bContext *C,
.camera_old = v3d->camera,
.ofs = rv3d->ofs,
.quat = quat,
+ /* No undo because this switches to/from camera. */
+ .undo_str = NULL,
});
}
else if (orig_persp == RV3D_CAMOB && v3d->camera) {
@@ -518,6 +519,8 @@ static void axis_set_view(bContext *C,
.ofs = ofs,
.quat = quat,
.dist = &dist,
+ /* No undo because this switches to/from camera. */
+ .undo_str = NULL,
});
}
else {
@@ -540,6 +543,8 @@ static void axis_set_view(bContext *C,
&(const V3D_SmoothParams){
.quat = quat,
.dyn_ofs = dyn_ofs_pt,
+ /* No undo because this isn't a camera view. */
+ .undo_str = NULL,
});
}
}
@@ -694,6 +699,8 @@ static void view3d_from_minmax(bContext *C,
.camera_old = v3d->camera,
.ofs = new_ofs,
.dist = ok_dist ? &new_dist : NULL,
+ /* The caller needs to use undo begin/end calls. */
+ .undo_str = NULL,
});
}
else {
@@ -704,6 +711,8 @@ static void view3d_from_minmax(bContext *C,
&(const V3D_SmoothParams){
.ofs = new_ofs,
.dist = ok_dist ? &new_dist : NULL,
+ /* The caller needs to use undo begin/end calls. */
+ .undo_str = NULL,
});
}
@@ -736,6 +745,7 @@ static void view3d_from_minmax_multi(bContext *C,
static int view3d_all_exec(bContext *C, wmOperator *op)
{
+ ScrArea *area = CTX_wm_area(C);
ARegion *region = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
@@ -802,6 +812,7 @@ static int view3d_all_exec(bContext *C, wmOperator *op)
/* This is an approximation, see function documentation for details. */
ED_view3d_clipping_clamp_minmax(rv3d, min, max);
}
+ ED_view3d_smooth_view_undo_begin(C, area);
if (use_all_regions) {
view3d_from_minmax_multi(C, v3d, min, max, true, smooth_viewtx);
@@ -810,6 +821,8 @@ static int view3d_all_exec(bContext *C, wmOperator *op)
view3d_from_minmax(C, v3d, region, min, max, true, smooth_viewtx);
}
+ ED_view3d_smooth_view_undo_end(C, area, op->type->name, false);
+
return OPERATOR_FINISHED;
}
@@ -842,13 +855,14 @@ void VIEW3D_OT_view_all(wmOperatorType *ot)
static int viewselected_exec(bContext *C, wmOperator *op)
{
+ ScrArea *area = CTX_wm_area(C);
ARegion *region = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
Scene *scene = CTX_data_scene(C);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
- Object *ob_eval = OBACT(view_layer_eval);
+ Object *ob_eval = BKE_view_layer_active_object_get(view_layer_eval);
Object *obedit = CTX_data_edit_object(C);
const bGPdata *gpd_eval = ob_eval && (ob_eval->type == OB_GPENCIL) ? ob_eval->data : NULL;
const bool is_gp_edit = gpd_eval ? GPENCIL_ANY_MODE(gpd_eval) : false;
@@ -948,8 +962,7 @@ static int viewselected_exec(bContext *C, wmOperator *op)
ok_dist = 0; /* don't zoom */
}
else {
- Base *base_eval;
- for (base_eval = FIRSTBASE(view_layer_eval); base_eval; base_eval = base_eval->next) {
+ LISTBASE_FOREACH (Base *, base_eval, &view_layer_eval->object_bases) {
if (BASE_SELECTED(v3d, base_eval)) {
bool only_center = false;
Object *ob = DEG_get_original_object(base_eval->object);
@@ -971,6 +984,8 @@ static int viewselected_exec(bContext *C, wmOperator *op)
ED_view3d_clipping_clamp_minmax(rv3d, min, max);
}
+ ED_view3d_smooth_view_undo_begin(C, area);
+
if (use_all_regions) {
view3d_from_minmax_multi(C, v3d, min, max, ok_dist, smooth_viewtx);
}
@@ -978,6 +993,8 @@ static int viewselected_exec(bContext *C, wmOperator *op)
view3d_from_minmax(C, v3d, region, min, max, ok_dist, smooth_viewtx);
}
+ ED_view3d_smooth_view_undo_end(C, area, op->type->name, false);
+
return OPERATOR_FINISHED;
}
@@ -1020,8 +1037,14 @@ static int viewcenter_cursor_exec(bContext *C, wmOperator *op)
/* non camera center */
float new_ofs[3];
negate_v3_v3(new_ofs, scene->cursor.location);
- ED_view3d_smooth_view(
- C, v3d, region, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs});
+ ED_view3d_smooth_view(C,
+ v3d,
+ region,
+ smooth_viewtx,
+ &(const V3D_SmoothParams){
+ .ofs = new_ofs,
+ .undo_str = op->type->name,
+ });
/* Smooth view does view-lock #RV3D_BOXVIEW copy. */
}
@@ -1074,8 +1097,14 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev
ED_view3d_win_to_3d_int(v3d, region, new_ofs, event->mval, new_ofs);
}
negate_v3(new_ofs);
- ED_view3d_smooth_view(
- C, v3d, region, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs});
+ ED_view3d_smooth_view(C,
+ v3d,
+ region,
+ smooth_viewtx,
+ &(const V3D_SmoothParams){
+ .ofs = new_ofs,
+ .undo_str = op->type->name,
+ });
}
return OPERATOR_FINISHED;
@@ -1275,7 +1304,7 @@ static int view_camera_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
if (rv3d->persp != RV3D_CAMOB) {
- Object *ob = OBACT(view_layer);
+ Object *ob = BKE_view_layer_active_object_get(view_layer);
if (!rv3d->smooth_timer) {
/* store settings of current view before allowing overwriting with camera view
@@ -1318,17 +1347,20 @@ static int view_camera_exec(bContext *C, wmOperator *op)
/* finally do snazzy view zooming */
rv3d->persp = RV3D_CAMOB;
- ED_view3d_smooth_view(C,
- v3d,
- region,
- smooth_viewtx,
- &(const V3D_SmoothParams){
- .camera = v3d->camera,
- .ofs = rv3d->ofs,
- .quat = rv3d->viewquat,
- .dist = &rv3d->dist,
- .lens = &v3d->lens,
- });
+ ED_view3d_smooth_view(
+ C,
+ v3d,
+ region,
+ smooth_viewtx,
+ &(const V3D_SmoothParams){
+ .camera = v3d->camera,
+ .ofs = rv3d->ofs,
+ .quat = rv3d->viewquat,
+ .dist = &rv3d->dist,
+ .lens = &v3d->lens,
+ /* No undo because this changes cameras (and wont move the camera). */
+ .undo_str = NULL,
+ });
}
else {
/* return to settings of last view */
@@ -1417,7 +1449,12 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
ED_view3d_smooth_view_force_finish(C, v3d, region);
if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0 || (view_opposite != RV3D_VIEW_USER)) {
- if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) {
+ const bool is_camera_lock = ED_view3d_camera_lock_check(v3d, rv3d);
+ if ((rv3d->persp != RV3D_CAMOB) || is_camera_lock) {
+ if (is_camera_lock) {
+ const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+ ED_view3d_camera_lock_init(depsgraph, v3d, rv3d);
+ }
int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
float quat_mul[4];
float quat_new[4];
@@ -1475,6 +1512,9 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
&(const V3D_SmoothParams){
.quat = quat_new,
.dyn_ofs = dyn_ofs_pt,
+ /* Group as successive orbit may run by holding a key. */
+ .undo_str = op->type->name,
+ .undo_grouped = true,
});
return OPERATOR_FINISHED;
@@ -1554,6 +1594,7 @@ static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
viewmove_apply(vod, vod->prev.event_xy[0] + x, vod->prev.event_xy[1] + y);
+ ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
viewops_data_free(C, vod);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_view3d/view3d_navigate.h b/source/blender/editors/space_view3d/view3d_navigate.h
index fc7bc11295a..925acd90573 100644
--- a/source/blender/editors/space_view3d/view3d_navigate.h
+++ b/source/blender/editors/space_view3d/view3d_navigate.h
@@ -231,6 +231,14 @@ typedef struct V3D_SmoothParams {
/** Alternate rotation center, when set `ofs` must be NULL. */
const float *dyn_ofs;
+
+ /** When non-NULL, perform undo pushes when transforming the camera. */
+ const char *undo_str;
+ /**
+ * When true use grouped undo pushes, use for incremental viewport manipulation
+ * which are likely to be activated by holding a key or from the mouse-wheel.
+ */
+ bool undo_grouped;
} V3D_SmoothParams;
/**
@@ -252,6 +260,22 @@ void ED_view3d_smooth_view(struct bContext *C,
const V3D_SmoothParams *sview);
/**
+ * Call before multiple smooth-view operations begin to properly handle undo.
+ *
+ * \note Only use explicit undo calls when multiple calls to smooth-view are necessary
+ * or when calling #ED_view3d_smooth_view_ex.
+ * Otherwise pass in #V3D_SmoothParams.undo_str so an undo step is pushed as needed.
+ */
+void ED_view3d_smooth_view_undo_begin(struct bContext *C, const struct ScrArea *area);
+/**
+ * Run after multiple smooth-view operations have run to push undo as needed.
+ */
+void ED_view3d_smooth_view_undo_end(struct bContext *C,
+ const struct ScrArea *area,
+ const char *undo_str,
+ bool undo_grouped);
+
+/**
* Apply the smooth-view immediately, use when we need to start a new view operation.
* (so we don't end up half-applying a view operation when pressing keys quickly).
*/
diff --git a/source/blender/editors/space_view3d/view3d_navigate_dolly.c b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
index d45b0c436ac..376e8ba190b 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_dolly.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_dolly.c
@@ -181,6 +181,7 @@ static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
if (ret & OPERATOR_FINISHED) {
+ ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
viewops_data_free(C, vod);
op->customdata = NULL;
}
diff --git a/source/blender/editors/space_view3d/view3d_navigate_fly.c b/source/blender/editors/space_view3d/view3d_navigate_fly.c
index 399f422f411..b607abe8226 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_fly.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_fly.c
@@ -247,7 +247,7 @@ static void drawFlyPixel(const struct bContext *UNUSED(C), ARegion *UNUSED(regio
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformThemeColor3(TH_VIEW_OVERLAY);
@@ -1079,6 +1079,7 @@ static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event)
int exit_code;
bool do_draw = false;
FlyInfo *fly = op->customdata;
+ View3D *v3d = fly->v3d;
RegionView3D *rv3d = fly->rv3d;
Object *fly_object = ED_view3d_cameracontrol_object_get(fly->v3d_camera_control);
@@ -1102,6 +1103,9 @@ static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event)
exit_code = flyEnd(C, fly);
+ if (exit_code == OPERATOR_FINISHED) {
+ ED_view3d_camera_lock_undo_push(op->type->name, v3d, rv3d, C);
+ }
if (exit_code != OPERATOR_RUNNING_MODAL) {
do_draw = true;
}
diff --git a/source/blender/editors/space_view3d/view3d_navigate_move.c b/source/blender/editors/space_view3d/view3d_navigate_move.c
index e653b349a2f..e236b702fb8 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_move.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_move.c
@@ -140,6 +140,7 @@ static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
if (ret & OPERATOR_FINISHED) {
+ ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
viewops_data_free(C, op->customdata);
op->customdata = NULL;
}
diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.c b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
index 1ce9bdcb211..88abf602c26 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_ndof.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.c
@@ -373,6 +373,9 @@ static int view3d_ndof_cameraview_pan_zoom(bContext *C, const wmEvent *event)
const bool has_translate = !is_zero_v2(ndof->tvec);
const bool has_zoom = ndof->tvec[2] != 0.0f;
+ float pan_vec[3];
+ WM_event_ndof_pan_get(ndof, pan_vec, true);
+
/* NOTE(@campbellbarton): In principle rotating could pass through to regular
* non-camera NDOF behavior (exiting the camera-view and rotating).
* Disabled this block since in practice it's difficult to control NDOF devices
@@ -388,14 +391,14 @@ static int view3d_ndof_cameraview_pan_zoom(bContext *C, const wmEvent *event)
if (has_translate) {
const float speed = ndof->dt * NDOF_PIXELS_PER_SECOND;
- float event_ofs[2] = {ndof->tvec[0] * speed, ndof->tvec[1] * speed};
+ float event_ofs[2] = {pan_vec[0] * speed, pan_vec[1] * speed};
if (ED_view3d_camera_view_pan(region, event_ofs)) {
changed = true;
}
}
if (has_zoom) {
- const float scale = 1.0f + (ndof->dt * ndof->tvec[2]);
+ const float scale = 1.0f + (ndof->dt * pan_vec[2]);
if (ED_view3d_camera_view_zoom_scale(rv3d, scale)) {
changed = true;
}
diff --git a/source/blender/editors/space_view3d/view3d_navigate_roll.c b/source/blender/editors/space_view3d/view3d_navigate_roll.c
index 087ca72211e..af93aa50238 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_roll.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_roll.c
@@ -15,6 +15,8 @@
#include "RNA_access.h"
#include "RNA_define.h"
+#include "DEG_depsgraph_query.h"
+
#include "ED_screen.h"
#include "view3d_intern.h"
@@ -167,7 +169,13 @@ static int viewroll_exec(bContext *C, wmOperator *op)
}
rv3d = region->regiondata;
- if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) {
+
+ const bool is_camera_lock = ED_view3d_camera_lock_check(v3d, rv3d);
+ if ((rv3d->persp != RV3D_CAMOB) || is_camera_lock) {
+ if (is_camera_lock) {
+ const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+ ED_view3d_camera_lock_init(depsgraph, v3d, rv3d);
+ }
ED_view3d_smooth_view_force_finish(C, v3d, region);
@@ -202,6 +210,9 @@ static int viewroll_exec(bContext *C, wmOperator *op)
&(const V3D_SmoothParams){
.quat = quat_new,
.dyn_ofs = dyn_ofs_pt,
+ /* Group as successive roll may run by holding a key. */
+ .undo_str = op->type->name,
+ .undo_grouped = true,
});
viewops_data_free(C, op->customdata);
diff --git a/source/blender/editors/space_view3d/view3d_navigate_rotate.c b/source/blender/editors/space_view3d/view3d_navigate_rotate.c
index 989fa152acc..20385e15c48 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_rotate.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_rotate.c
@@ -375,6 +375,7 @@ static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
if (ret & OPERATOR_FINISHED) {
+ ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
viewops_data_free(C, op->customdata);
op->customdata = NULL;
}
diff --git a/source/blender/editors/space_view3d/view3d_navigate_smoothview.c b/source/blender/editors/space_view3d/view3d_navigate_smoothview.c
index 48af126d8a9..6b150d1e771 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_smoothview.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_smoothview.c
@@ -8,6 +8,7 @@
#include "MEM_guardedalloc.h"
+#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BKE_context.h"
@@ -21,6 +22,115 @@
#include "view3d_intern.h"
#include "view3d_navigate.h" /* own include */
+static void view3d_smoothview_apply_with_interp(
+ bContext *C, View3D *v3d, RegionView3D *rv3d, const bool use_autokey, const float factor);
+
+/* -------------------------------------------------------------------- */
+/** \name Smooth View Undo Handling
+ *
+ * When the camera is locked to the viewport smooth-view operations
+ * may need to perform an undo push.
+ *
+ * In this case the smooth-view camera transformation is temporarily completed,
+ * undo is pushed then the change is rewound, and smooth-view completes from it's timer.
+ * In the case smooth-view executed the change immediately - an undo push is called.
+ *
+ * NOTE(@campbellbarton): While this is not ideal it's necessary as making the undo-push
+ * once smooth-view is complete because smooth-view is non-blocking and it's possible other
+ * operations are executed once smooth-view has started.
+ * \{ */
+
+void ED_view3d_smooth_view_undo_begin(bContext *C, const ScrArea *area)
+{
+ const View3D *v3d = area->spacedata.first;
+ Object *camera = v3d->camera;
+ if (!camera) {
+ return;
+ }
+
+ /* Tag the camera object so it's known smooth-view is applied to the view-ports camera
+ * (needed to detect when a locked camera is being manipulated).
+ * NOTE: It doesn't matter if the actual object being manipulated is the camera or not. */
+ camera->id.tag &= ~LIB_TAG_DOIT;
+
+ LISTBASE_FOREACH (const ARegion *, region, &area->regionbase) {
+ if (region->regiontype != RGN_TYPE_WINDOW) {
+ continue;
+ }
+ const RegionView3D *rv3d = region->regiondata;
+ if (ED_view3d_camera_lock_undo_test(v3d, rv3d, C)) {
+ camera->id.tag |= LIB_TAG_DOIT;
+ break;
+ }
+ }
+}
+
+void ED_view3d_smooth_view_undo_end(bContext *C,
+ const ScrArea *area,
+ const char *undo_str,
+ const bool undo_grouped)
+{
+ View3D *v3d = area->spacedata.first;
+ Object *camera = v3d->camera;
+ if (!camera) {
+ return;
+ }
+ if (camera->id.tag & LIB_TAG_DOIT) {
+ /* Smooth view didn't touch the camera. */
+ camera->id.tag &= ~LIB_TAG_DOIT;
+ return;
+ }
+
+ if ((U.uiflag & USER_GLOBALUNDO) == 0) {
+ return;
+ }
+
+ /* NOTE(@campbellbarton): It is not possible that a single viewport references different cameras
+ * so even in the case there is a quad-view with multiple camera views set, these will all
+ * reference the same camera. In this case it doesn't matter which region is used.
+ * If in the future multiple cameras are supported, this logic can be extended. */
+ const ARegion *region_camera = NULL;
+
+ /* An undo push should be performed. */
+ bool is_interactive = false;
+ LISTBASE_FOREACH (const ARegion *, region, &area->regionbase) {
+ if (region->regiontype != RGN_TYPE_WINDOW) {
+ continue;
+ }
+ const RegionView3D *rv3d = region->regiondata;
+ if (ED_view3d_camera_lock_undo_test(v3d, rv3d, C)) {
+ region_camera = region;
+ if (rv3d->sms) {
+ is_interactive = true;
+ }
+ }
+ }
+
+ if (region_camera == NULL) {
+ return;
+ }
+
+ RegionView3D *rv3d = region_camera->regiondata;
+
+ /* Fast forward, undo push, then rewind. */
+ if (is_interactive) {
+ view3d_smoothview_apply_with_interp(C, v3d, rv3d, false, 1.0f);
+ }
+
+ if (undo_grouped) {
+ ED_view3d_camera_lock_undo_grouped_push(undo_str, v3d, rv3d, C);
+ }
+ else {
+ ED_view3d_camera_lock_undo_push(undo_str, v3d, rv3d, C);
+ }
+
+ if (is_interactive) {
+ view3d_smoothview_apply_with_interp(C, v3d, rv3d, false, 0.0f);
+ }
+}
+
+/** \} */
+
/* -------------------------------------------------------------------- */
/** \name Smooth View Operator & Utilities
*
@@ -86,6 +196,11 @@ void ED_view3d_smooth_view_ex(
const int smooth_viewtx,
const V3D_SmoothParams *sview)
{
+ /* In this case use #ED_view3d_smooth_view_undo_begin & end functions
+ * instead of passing in undo. */
+ BLI_assert_msg(sview->undo_str == NULL,
+ "Only the 'ED_view3d_smooth_view' version of this function handles undo!");
+
RegionView3D *rv3d = region->regiondata;
struct SmoothView3DStore sms = {{0}};
@@ -236,6 +351,13 @@ void ED_view3d_smooth_view_ex(
WM_event_add_mousemove(win);
}
+
+ if (sms.to_camera == false) {
+ /* See comments in #ED_view3d_smooth_view_undo_begin for why this is needed. */
+ if (v3d->camera) {
+ v3d->camera->id.tag &= ~LIB_TAG_DOIT;
+ }
+ }
}
void ED_view3d_smooth_view(bContext *C,
@@ -249,97 +371,129 @@ void ED_view3d_smooth_view(bContext *C,
wmWindow *win = CTX_wm_window(C);
ScrArea *area = CTX_wm_area(C);
- ED_view3d_smooth_view_ex(depsgraph, wm, win, area, v3d, region, smooth_viewtx, sview);
+ /* #ED_view3d_smooth_view_ex asserts this is not set as it doesn't support undo. */
+ struct V3D_SmoothParams sview_no_undo = *sview;
+ sview_no_undo.undo_str = NULL;
+ sview_no_undo.undo_grouped = false;
+
+ const bool do_undo = (sview->undo_str != NULL);
+ if (do_undo) {
+ ED_view3d_smooth_view_undo_begin(C, area);
+ }
+
+ ED_view3d_smooth_view_ex(depsgraph, wm, win, area, v3d, region, smooth_viewtx, &sview_no_undo);
+
+ if (do_undo) {
+ ED_view3d_smooth_view_undo_end(C, area, sview->undo_str, sview->undo_grouped);
+ }
}
-/* only meant for timer usage */
-static void view3d_smoothview_apply(bContext *C, View3D *v3d, ARegion *region, bool sync_boxview)
+/**
+ * Apply with interpolation, on completion run #view3d_smoothview_apply_and_finish.
+ */
+static void view3d_smoothview_apply_with_interp(
+ bContext *C, View3D *v3d, RegionView3D *rv3d, const bool use_autokey, const float factor)
{
- wmWindowManager *wm = CTX_wm_manager(C);
- RegionView3D *rv3d = region->regiondata;
struct SmoothView3DStore *sms = rv3d->sms;
- float step, step_inv;
- if (sms->time_allowed != 0.0) {
- step = (float)((rv3d->smooth_timer->duration) / sms->time_allowed);
+ interp_qt_qtqt(rv3d->viewquat, sms->src.quat, sms->dst.quat, factor);
+
+ if (sms->use_dyn_ofs) {
+ view3d_orbit_apply_dyn_ofs(
+ rv3d->ofs, sms->src.ofs, sms->src.quat, rv3d->viewquat, sms->dyn_ofs);
}
else {
- step = 1.0f;
+ interp_v3_v3v3(rv3d->ofs, sms->src.ofs, sms->dst.ofs, factor);
}
- /* end timer */
- if (step >= 1.0f) {
- wmWindow *win = CTX_wm_window(C);
+ rv3d->dist = interpf(sms->dst.dist, sms->src.dist, factor);
+ v3d->lens = interpf(sms->dst.lens, sms->src.lens, factor);
- /* if we went to camera, store the original */
- if (sms->to_camera) {
- rv3d->persp = RV3D_CAMOB;
- view3d_smooth_view_state_restore(&sms->org, v3d, rv3d);
- }
- else {
- const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
-
- view3d_smooth_view_state_restore(&sms->dst, v3d, rv3d);
-
- ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d);
+ const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+ if (ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d)) {
+ if (use_autokey) {
ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true);
}
+ }
+}
- if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) {
- rv3d->view = sms->org_view;
- }
-
- MEM_freeN(rv3d->sms);
- rv3d->sms = NULL;
+/**
+ * Apply the view-port transformation & free smooth-view related data.
+ */
+static void view3d_smoothview_apply_and_finish(bContext *C, View3D *v3d, RegionView3D *rv3d)
+{
+ wmWindowManager *wm = CTX_wm_manager(C);
+ struct SmoothView3DStore *sms = rv3d->sms;
- WM_event_remove_timer(wm, win, rv3d->smooth_timer);
- rv3d->smooth_timer = NULL;
- rv3d->rflag &= ~RV3D_NAVIGATING;
+ wmWindow *win = CTX_wm_window(C);
- /* Event handling won't know if a UI item has been moved under the pointer. */
- WM_event_add_mousemove(win);
+ /* if we went to camera, store the original */
+ if (sms->to_camera) {
+ rv3d->persp = RV3D_CAMOB;
+ view3d_smooth_view_state_restore(&sms->org, v3d, rv3d);
}
else {
- /* ease in/out */
- step = (3.0f * step * step - 2.0f * step * step * step);
-
- step_inv = 1.0f - step;
-
- interp_qt_qtqt(rv3d->viewquat, sms->src.quat, sms->dst.quat, step);
-
- if (sms->use_dyn_ofs) {
- view3d_orbit_apply_dyn_ofs(
- rv3d->ofs, sms->src.ofs, sms->src.quat, rv3d->viewquat, sms->dyn_ofs);
- }
- else {
- interp_v3_v3v3(rv3d->ofs, sms->src.ofs, sms->dst.ofs, step);
- }
+ const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- rv3d->dist = sms->dst.dist * step + sms->src.dist * step_inv;
- v3d->lens = sms->dst.lens * step + sms->src.lens * step_inv;
+ view3d_smooth_view_state_restore(&sms->dst, v3d, rv3d);
- const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d);
- if (ED_screen_animation_playing(wm)) {
+ if (ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d)) {
ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true);
}
}
- if (sync_boxview && (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW)) {
- view3d_boxview_copy(CTX_wm_area(C), region);
+ if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) {
+ rv3d->view = sms->org_view;
}
+ MEM_freeN(rv3d->sms);
+ rv3d->sms = NULL;
+
+ WM_event_remove_timer(wm, win, rv3d->smooth_timer);
+ rv3d->smooth_timer = NULL;
+ rv3d->rflag &= ~RV3D_NAVIGATING;
+
+ /* Event handling won't know if a UI item has been moved under the pointer. */
+ WM_event_add_mousemove(win);
+
/* NOTE: this doesn't work right because the v3d->lens is now used in ortho mode r51636,
* when switching camera in quad-view the other ortho views would zoom & reset.
*
* For now only redraw all regions when smooth-view finishes.
*/
- if (step >= 1.0f) {
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
+ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
+}
+
+/* only meant for timer usage */
+
+static void view3d_smoothview_apply_from_timer(bContext *C, View3D *v3d, ARegion *region)
+{
+ wmWindowManager *wm = CTX_wm_manager(C);
+ RegionView3D *rv3d = region->regiondata;
+ struct SmoothView3DStore *sms = rv3d->sms;
+ float factor;
+
+ if (sms->time_allowed != 0.0) {
+ factor = (float)((rv3d->smooth_timer->duration) / sms->time_allowed);
}
else {
- ED_region_tag_redraw(region);
+ factor = 1.0f;
+ }
+ if (factor >= 1.0f) {
+ view3d_smoothview_apply_and_finish(C, v3d, rv3d);
}
+ else {
+ /* Ease in/out smoothing. */
+ factor = (3.0f * factor * factor - 2.0f * factor * factor * factor);
+ const bool use_autokey = ED_screen_animation_playing(wm);
+ view3d_smoothview_apply_with_interp(C, v3d, rv3d, use_autokey, factor);
+ }
+
+ if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
+ view3d_boxview_copy(CTX_wm_area(C), region);
+ }
+
+ ED_region_tag_redraw(region);
}
static int view3d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
@@ -353,7 +507,7 @@ static int view3d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const w
return OPERATOR_PASS_THROUGH;
}
- view3d_smoothview_apply(C, v3d, region, true);
+ view3d_smoothview_apply_from_timer(C, v3d, region);
return OPERATOR_FINISHED;
}
@@ -361,12 +515,10 @@ static int view3d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const w
void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region)
{
RegionView3D *rv3d = region->regiondata;
-
if (rv3d && rv3d->sms) {
- rv3d->sms->time_allowed = 0.0; /* force finishing */
- view3d_smoothview_apply(C, v3d, region, false);
+ view3d_smoothview_apply_and_finish(C, v3d, rv3d);
- /* force update of view matrix so tools that run immediately after
+ /* Force update of view matrix so tools that run immediately after
* can use them without redrawing first */
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Scene *scene = CTX_data_scene(C);
diff --git a/source/blender/editors/space_view3d/view3d_navigate_walk.c b/source/blender/editors/space_view3d/view3d_navigate_walk.c
index c4eff01375b..7e537d0c141 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_walk.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_walk.c
@@ -55,9 +55,6 @@
#define USE_TABLET_SUPPORT
-/* ensure the target position is one we can reach, see: T45771 */
-#define USE_PIXELSIZE_NATIVE_SUPPORT
-
/* -------------------------------------------------------------------- */
/** \name Modal Key-map
* \{ */
@@ -226,8 +223,8 @@ typedef struct WalkInfo {
/** Previous 2D mouse values. */
int prev_mval[2];
- /** Center mouse values. */
- int center_mval[2];
+ /** Initial mouse location. */
+ int init_mval[2];
int moffset[2];
@@ -271,9 +268,6 @@ typedef struct WalkInfo {
bool is_reversed;
#ifdef USE_TABLET_SUPPORT
- /** Check if we had a cursor event before. */
- bool is_cursor_first;
-
/** Tablet devices (we can't relocate the cursor). */
bool is_cursor_absolute;
#endif
@@ -341,7 +335,7 @@ static void drawWalkPixel(const struct bContext *UNUSED(C), ARegion *region, voi
GPUVertFormat *format = immVertexFormat();
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
- immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
immUniformThemeColorAlpha(TH_VIEW_OVERLAY, 1.0f);
@@ -484,7 +478,7 @@ enum {
static float base_speed = -1.0f;
static float userdef_speed = -1.0f;
-static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
+static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op, const int mval[2])
{
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win = CTX_wm_window(C);
@@ -565,8 +559,6 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
walk->is_reversed = ((U.walk_navigation.flag & USER_WALK_MOUSE_REVERSE) != 0);
#ifdef USE_TABLET_SUPPORT
- walk->is_cursor_first = true;
-
walk->is_cursor_absolute = false;
#endif
@@ -599,28 +591,10 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
walk->v3d_camera_control = ED_view3d_cameracontrol_acquire(
walk->depsgraph, walk->scene, walk->v3d, walk->rv3d);
- /* center the mouse */
- walk->center_mval[0] = walk->region->winx * 0.5f;
- walk->center_mval[1] = walk->region->winy * 0.5f;
-
-#ifdef USE_PIXELSIZE_NATIVE_SUPPORT
- walk->center_mval[0] += walk->region->winrct.xmin;
- walk->center_mval[1] += walk->region->winrct.ymin;
-
- WM_cursor_compatible_xy(win, &walk->center_mval[0], &walk->center_mval[1]);
-
- walk->center_mval[0] -= walk->region->winrct.xmin;
- walk->center_mval[1] -= walk->region->winrct.ymin;
-#endif
-
- copy_v2_v2_int(walk->prev_mval, walk->center_mval);
-
- WM_cursor_warp(win,
- walk->region->winrct.xmin + walk->center_mval[0],
- walk->region->winrct.ymin + walk->center_mval[1]);
+ copy_v2_v2_int(walk->init_mval, mval);
+ copy_v2_v2_int(walk->prev_mval, mval);
- /* remove the mouse cursor temporarily */
- WM_cursor_modal_set(win, WM_CURSOR_NONE);
+ WM_cursor_grab_enable(win, 0, true, NULL);
return 1;
}
@@ -669,18 +643,7 @@ static int walkEnd(bContext *C, WalkInfo *walk)
}
#endif
- /* restore the cursor */
- WM_cursor_modal_restore(win);
-
-#ifdef USE_TABLET_SUPPORT
- if (walk->is_cursor_absolute == false)
-#endif
- {
- /* center the mouse */
- WM_cursor_warp(win,
- walk->region->winrct.xmin + walk->center_mval[0],
- walk->region->winrct.ymin + walk->center_mval[1]);
- }
+ WM_cursor_grab_enable(win, 0, true, NULL);
if (walk->state == WALK_CONFIRM) {
MEM_freeN(walk);
@@ -691,34 +654,16 @@ static int walkEnd(bContext *C, WalkInfo *walk)
return OPERATOR_CANCELLED;
}
-static void walkEvent(bContext *C, WalkInfo *walk, const wmEvent *event)
+static void walkEvent(WalkInfo *walk, const wmEvent *event)
{
if (event->type == TIMER && event->customdata == walk->timer) {
walk->redraw = true;
}
- else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
+ else if (ISMOUSE_MOTION(event->type)) {
#ifdef USE_TABLET_SUPPORT
- if (walk->is_cursor_first) {
- /* wait until we get the 'warp' event */
- if ((walk->center_mval[0] == event->mval[0]) && (walk->center_mval[1] == event->mval[1])) {
- walk->is_cursor_first = false;
- }
- else {
- /* NOTE: its possible the system isn't giving us the warp event
- * ideally we shouldn't have to worry about this, see: T45361 */
- wmWindow *win = CTX_wm_window(C);
- WM_cursor_warp(win,
- walk->region->winrct.xmin + walk->center_mval[0],
- walk->region->winrct.ymin + walk->center_mval[1]);
- }
- return;
- }
-
if ((walk->is_cursor_absolute == false) && event->tablet.is_motion_absolute) {
walk->is_cursor_absolute = true;
- copy_v2_v2_int(walk->prev_mval, event->mval);
- copy_v2_v2_int(walk->center_mval, event->mval);
}
#endif /* USE_TABLET_SUPPORT */
@@ -727,29 +672,8 @@ static void walkEvent(bContext *C, WalkInfo *walk, const wmEvent *event)
copy_v2_v2_int(walk->prev_mval, event->mval);
- if ((walk->center_mval[0] != event->mval[0]) || (walk->center_mval[1] != event->mval[1])) {
+ if (walk->moffset[0] || walk->moffset[1]) {
walk->redraw = true;
-
-#ifdef USE_TABLET_SUPPORT
- if (walk->is_cursor_absolute) {
- /* pass */
- }
- else
-#endif
- if (WM_event_is_last_mousemove(event)) {
- wmWindow *win = CTX_wm_window(C);
-
-#ifdef __APPLE__
- if ((abs(walk->prev_mval[0] - walk->center_mval[0]) > walk->center_mval[0] / 2) ||
- (abs(walk->prev_mval[1] - walk->center_mval[1]) > walk->center_mval[1] / 2))
-#endif
- {
- WM_cursor_warp(win,
- walk->region->winrct.xmin + walk->center_mval[0],
- walk->region->winrct.ymin + walk->center_mval[1]);
- copy_v2_v2_int(walk->prev_mval, walk->center_mval);
- }
- }
}
}
#ifdef WITH_INPUT_NDOF
@@ -1436,12 +1360,12 @@ static int walk_invoke(bContext *C, wmOperator *op, const wmEvent *event)
op->customdata = walk;
- if (initWalkInfo(C, walk, op) == false) {
+ if (initWalkInfo(C, walk, op, event->mval) == false) {
MEM_freeN(op->customdata);
return OPERATOR_CANCELLED;
}
- walkEvent(C, walk, event);
+ walkEvent(walk, event);
WM_event_add_modal_handler(C, op);
@@ -1462,12 +1386,13 @@ static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event)
int exit_code;
bool do_draw = false;
WalkInfo *walk = op->customdata;
+ View3D *v3d = walk->v3d;
RegionView3D *rv3d = walk->rv3d;
Object *walk_object = ED_view3d_cameracontrol_object_get(walk->v3d_camera_control);
walk->redraw = false;
- walkEvent(C, walk, event);
+ walkEvent(walk, event);
#ifdef WITH_INPUT_NDOF
if (walk->ndof) { /* 3D mouse overrules [2D mouse + timer] */
@@ -1488,6 +1413,9 @@ static int walk_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (exit_code != OPERATOR_RUNNING_MODAL) {
do_draw = true;
}
+ if (exit_code == OPERATOR_FINISHED) {
+ ED_view3d_camera_lock_undo_push(op->type->name, v3d, rv3d, C);
+ }
if (do_draw) {
if (rv3d->persp == RV3D_CAMOB) {
@@ -1515,7 +1443,9 @@ void VIEW3D_OT_walk(wmOperatorType *ot)
ot->poll = ED_operator_region_view3d_active;
/* flags */
- ot->flag = OPTYPE_BLOCKING;
+ /* NOTE: #OPTYPE_BLOCKING isn't used because this needs to grab & hide the cursor.
+ * where as blocking confines the cursor to the window bounds, even when hidden. */
+ ot->flag = 0;
}
/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom.c b/source/blender/editors/space_view3d/view3d_navigate_zoom.c
index a67c0850ad9..9230aa09b1a 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_zoom.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_zoom.c
@@ -425,6 +425,7 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
if (ret & OPERATOR_FINISHED) {
+ ED_view3d_camera_lock_undo_push(op->type->name, vod->v3d, vod->rv3d, C);
viewops_data_free(C, op->customdata);
op->customdata = NULL;
}
@@ -507,6 +508,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
ED_region_tag_redraw(region);
+ ED_view3d_camera_lock_undo_grouped_push(op->type->name, v3d, rv3d, C);
viewops_data_free(C, op->customdata);
op->customdata = NULL;
diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c b/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c
index f834efe4a7b..7cafc3dfd42 100644
--- a/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c
+++ b/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c
@@ -159,11 +159,15 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
/* clamp after because we may have been zooming out */
CLAMP(new_dist, dist_range[0], dist_range[1]);
- /* TODO(campbell): 'is_camera_lock' not currently working well. */
const bool is_camera_lock = ED_view3d_camera_lock_check(v3d, rv3d);
- if ((rv3d->persp == RV3D_CAMOB) && (is_camera_lock == false)) {
+ if (rv3d->persp == RV3D_CAMOB) {
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- ED_view3d_persp_switch_from_camera(depsgraph, v3d, rv3d, RV3D_PERSP);
+ if (is_camera_lock) {
+ ED_view3d_camera_lock_init(depsgraph, v3d, rv3d);
+ }
+ else {
+ ED_view3d_persp_switch_from_camera(depsgraph, v3d, rv3d, RV3D_PERSP);
+ }
}
ED_view3d_smooth_view(C,
@@ -173,6 +177,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
&(const V3D_SmoothParams){
.ofs = new_ofs,
.dist = &new_dist,
+ .undo_str = op->type->name,
});
if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) {
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.cc
index 01f94bcab55..f00bee54ed6 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.cc
@@ -5,10 +5,10 @@
* \ingroup spview3d
*/
-#include <float.h>
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
+#include <cfloat>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
#include "DNA_action_types.h"
#include "DNA_armature_types.h"
@@ -23,7 +23,6 @@
#include "MEM_guardedalloc.h"
-#include "BLI_array.h"
#include "BLI_bitmap.h"
#include "BLI_lasso_2d.h"
#include "BLI_linklist.h"
@@ -32,6 +31,7 @@
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
+#include "BLI_vector.hh"
#ifdef __BIG_ENDIAN__
# include "BLI_endian_switch.h"
@@ -204,14 +204,14 @@ static void editselect_buf_cache_init(ViewContext *vc, short select_mode)
}
}
-static void editselect_buf_cache_free(struct EditSelectBuf_Cache *esel)
+static void editselect_buf_cache_free(EditSelectBuf_Cache *esel)
{
MEM_SAFE_FREE(esel->select_bitmap);
}
static void editselect_buf_cache_free_voidp(void *esel_voidp)
{
- editselect_buf_cache_free(esel_voidp);
+ editselect_buf_cache_free(static_cast<EditSelectBuf_Cache *>(esel_voidp));
MEM_freeN(esel_voidp);
}
@@ -219,7 +219,7 @@ static void editselect_buf_cache_init_with_generic_userdata(wmGenericUserData *w
ViewContext *vc,
short select_mode)
{
- struct EditSelectBuf_Cache *esel = MEM_callocN(sizeof(*esel), __func__);
+ EditSelectBuf_Cache *esel = MEM_cnew<EditSelectBuf_Cache>(__func__);
wm_userdata->data = esel;
wm_userdata->free_fn = editselect_buf_cache_free_voidp;
wm_userdata->use_free = true;
@@ -232,7 +232,7 @@ static void editselect_buf_cache_init_with_generic_userdata(wmGenericUserData *w
/** \name Internal Edit-Mesh Utilities
* \{ */
-static bool edbm_backbuf_check_and_select_verts(struct EditSelectBuf_Cache *esel,
+static bool edbm_backbuf_check_and_select_verts(EditSelectBuf_Cache *esel,
Depsgraph *depsgraph,
Object *ob,
BMEditMesh *em,
@@ -264,7 +264,7 @@ static bool edbm_backbuf_check_and_select_verts(struct EditSelectBuf_Cache *esel
return changed;
}
-static bool edbm_backbuf_check_and_select_edges(struct EditSelectBuf_Cache *esel,
+static bool edbm_backbuf_check_and_select_edges(EditSelectBuf_Cache *esel,
Depsgraph *depsgraph,
Object *ob,
BMEditMesh *em,
@@ -296,7 +296,7 @@ static bool edbm_backbuf_check_and_select_edges(struct EditSelectBuf_Cache *esel
return changed;
}
-static bool edbm_backbuf_check_and_select_faces(struct EditSelectBuf_Cache *esel,
+static bool edbm_backbuf_check_and_select_faces(EditSelectBuf_Cache *esel,
Depsgraph *depsgraph,
Object *ob,
BMEditMesh *em,
@@ -330,18 +330,21 @@ static bool edbm_backbuf_check_and_select_faces(struct EditSelectBuf_Cache *esel
/* object mode, edbm_ prefix is confusing here, rename? */
static bool edbm_backbuf_check_and_select_verts_obmode(Mesh *me,
- struct EditSelectBuf_Cache *esel,
+ EditSelectBuf_Cache *esel,
const eSelectOp sel_op)
{
- MVert *mv = me->mvert;
- uint index;
+ MVert *verts = BKE_mesh_verts_for_write(me);
+ MVert *mv = verts;
bool changed = false;
const BLI_bitmap *select_bitmap = esel->select_bitmap;
if (mv) {
- for (index = 0; index < me->totvert; index++, mv++) {
- if (!(mv->flag & ME_HIDE)) {
+ const bool *hide_vert = (const bool *)CustomData_get_layer_named(
+ &me->vdata, CD_PROP_BOOL, ".hide_vert");
+
+ for (int index = 0; index < me->totvert; index++, mv++) {
+ if (!(hide_vert && hide_vert[index])) {
const bool is_select = mv->flag & SELECT;
const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index);
const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
@@ -357,23 +360,25 @@ static bool edbm_backbuf_check_and_select_verts_obmode(Mesh *me,
/* object mode, edbm_ prefix is confusing here, rename? */
static bool edbm_backbuf_check_and_select_faces_obmode(Mesh *me,
- struct EditSelectBuf_Cache *esel,
+ EditSelectBuf_Cache *esel,
const eSelectOp sel_op)
{
- MPoly *mpoly = me->mpoly;
- uint index;
+ MPoly *polys = BKE_mesh_polys_for_write(me);
bool changed = false;
const BLI_bitmap *select_bitmap = esel->select_bitmap;
- if (mpoly) {
- for (index = 0; index < me->totpoly; index++, mpoly++) {
- if (!(mpoly->flag & ME_HIDE)) {
- const bool is_select = mpoly->flag & ME_FACE_SEL;
+ if (polys) {
+ const bool *hide_poly = (const bool *)CustomData_get_layer_named(
+ &me->vdata, CD_PROP_BOOL, ".hide_poly");
+
+ for (int index = 0; index < me->totpoly; index++) {
+ if (!(hide_poly && hide_poly[index])) {
+ const bool is_select = polys[index].flag & ME_FACE_SEL;
const bool is_inside = BLI_BITMAP_TEST_BOOL(select_bitmap, index);
const int sel_op_result = ED_select_op_action_deselected(sel_op, is_select, is_inside);
if (sel_op_result != -1) {
- SET_FLAG_FROM_TEST(mpoly->flag, sel_op_result, ME_FACE_SEL);
+ SET_FLAG_FROM_TEST(polys[index].flag, sel_op_result, ME_FACE_SEL);
changed = true;
}
}
@@ -388,7 +393,7 @@ static bool edbm_backbuf_check_and_select_faces_obmode(Mesh *me,
/** \name Lasso Select
* \{ */
-typedef struct LassoSelectUserData {
+struct LassoSelectUserData {
ViewContext *vc;
const rcti *rect;
const rctf *rect_fl;
@@ -402,7 +407,7 @@ typedef struct LassoSelectUserData {
int pass;
bool is_done;
bool is_changed;
-} LassoSelectUserData;
+};
static void view3d_userdata_lassoselect_init(LassoSelectUserData *r_data,
ViewContext *vc,
@@ -421,7 +426,7 @@ static void view3d_userdata_lassoselect_init(LassoSelectUserData *r_data,
r_data->mcoords_len = mcoords_len;
r_data->sel_op = sel_op;
/* SELECT by default, but can be changed if needed (only few cases use and respect this). */
- r_data->select_flag = SELECT;
+ r_data->select_flag = (eBezTriple_Flag)SELECT;
/* runtime */
r_data->pass = 0;
@@ -434,24 +439,24 @@ static bool view3d_selectable_data(bContext *C)
Object *ob = CTX_data_active_object(C);
if (!ED_operator_region_view3d_active(C)) {
- return 0;
+ return false;
}
if (ob) {
if (ob->mode & OB_MODE_EDIT) {
if (ob->type == OB_FONT) {
- return 0;
+ return false;
}
}
else {
if ((ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) &&
!BKE_paint_select_elem_test(ob)) {
- return 0;
+ return false;
}
}
}
- return 1;
+ return true;
}
/* helper also for box_select */
@@ -466,21 +471,21 @@ static bool edge_inside_rect(const rctf *rect, const float v1[2], const float v2
/* check points in rect */
if (edge_fully_inside_rect(rect, v1, v2)) {
- return 1;
+ return true;
}
/* check points completely out rect */
if (v1[0] < rect->xmin && v2[0] < rect->xmin) {
- return 0;
+ return false;
}
if (v1[0] > rect->xmax && v2[0] > rect->xmax) {
- return 0;
+ return false;
}
if (v1[1] < rect->ymin && v2[1] < rect->ymin) {
- return 0;
+ return false;
}
if (v1[1] > rect->ymax && v2[1] > rect->ymax) {
- return 0;
+ return false;
}
/* simple check lines intersecting. */
@@ -490,22 +495,22 @@ static bool edge_inside_rect(const rctf *rect, const float v1[2], const float v2
d4 = (v1[1] - v2[1]) * (v1[0] - rect->xmax) + (v2[0] - v1[0]) * (v1[1] - rect->ymin);
if (d1 < 0 && d2 < 0 && d3 < 0 && d4 < 0) {
- return 0;
+ return false;
}
if (d1 > 0 && d2 > 0 && d3 > 0 && d4 > 0) {
- return 0;
+ return false;
}
- return 1;
+ return true;
}
static void do_lasso_select_pose__do_tag(void *userData,
- struct bPoseChannel *pchan,
+ bPoseChannel *pchan,
const float screen_co_a[2],
const float screen_co_b[2])
{
- LassoSelectUserData *data = userData;
- const bArmature *arm = data->vc->obact->data;
+ LassoSelectUserData *data = static_cast<LassoSelectUserData *>(userData);
+ const bArmature *arm = static_cast<bArmature *>(data->vc->obact->data);
if (!PBONE_SELECTABLE(arm, pchan->bone)) {
return;
}
@@ -526,7 +531,7 @@ static void do_lasso_tag_pose(ViewContext *vc,
LassoSelectUserData data;
rcti rect;
- if ((ob->type != OB_ARMATURE) || (ob->pose == NULL)) {
+ if ((ob->type != OB_ARMATURE) || (ob->pose == nullptr)) {
return;
}
@@ -535,7 +540,8 @@ static void do_lasso_tag_pose(ViewContext *vc,
BLI_lasso_boundbox(&rect, mcoords, mcoords_len);
- view3d_userdata_lassoselect_init(&data, vc, &rect, mcoords, mcoords_len, 0);
+ view3d_userdata_lassoselect_init(
+ &data, vc, &rect, mcoords, mcoords_len, static_cast<eSelectOp>(0));
ED_view3d_init_mats_rv3d(vc_tmp.obact, vc->rv3d);
@@ -559,7 +565,7 @@ static bool do_lasso_select_objects(ViewContext *vc,
changed |= object_deselect_all_visible(vc->view_layer, vc->v3d);
}
- for (base = vc->view_layer->object_bases.first; base; base = base->next) {
+ for (base = static_cast<Base *>(vc->view_layer->object_bases.first); base; base = base->next) {
if (BASE_SELECTABLE(v3d, base)) { /* Use this to avoid unnecessary lasso look-ups. */
const bool is_select = base->flag & BASE_SELECTED;
const bool is_inside = ((ED_view3d_project_base(vc->region, base) == V3D_PROJ_RET_OK) &&
@@ -583,32 +589,31 @@ static bool do_lasso_select_objects(ViewContext *vc,
/**
* Use for lasso & box select.
*/
-static Base **do_pose_tag_select_op_prepare(ViewContext *vc, uint *r_bases_len)
+static blender::Vector<Base *> do_pose_tag_select_op_prepare(ViewContext *vc)
{
- Base **bases = NULL;
- BLI_array_declare(bases);
+ blender::Vector<Base *> bases;
+
FOREACH_BASE_IN_MODE_BEGIN (vc->view_layer, vc->v3d, OB_ARMATURE, OB_MODE_POSE, base_iter) {
Object *ob_iter = base_iter->object;
- bArmature *arm = ob_iter->data;
+ bArmature *arm = static_cast<bArmature *>(ob_iter->data);
LISTBASE_FOREACH (bPoseChannel *, pchan, &ob_iter->pose->chanbase) {
Bone *bone = pchan->bone;
bone->flag &= ~BONE_DONE;
}
arm->id.tag |= LIB_TAG_DOIT;
ob_iter->id.tag &= ~LIB_TAG_DOIT;
- BLI_array_append(bases, base_iter);
+ bases.append(base_iter);
}
FOREACH_BASE_IN_MODE_END;
- *r_bases_len = BLI_array_len(bases);
return bases;
}
-static bool do_pose_tag_select_op_exec(Base **bases, const uint bases_len, const eSelectOp sel_op)
+static bool do_pose_tag_select_op_exec(blender::MutableSpan<Base *> bases, const eSelectOp sel_op)
{
bool changed_multi = false;
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
- for (int i = 0; i < bases_len; i++) {
+ for (const int i : bases.index_range()) {
Base *base_iter = bases[i];
Object *ob_iter = base_iter->object;
if (ED_pose_deselect_all(ob_iter, SEL_DESELECT, false)) {
@@ -618,10 +623,10 @@ static bool do_pose_tag_select_op_exec(Base **bases, const uint bases_len, const
}
}
- for (int i = 0; i < bases_len; i++) {
+ for (const int i : bases.index_range()) {
Base *base_iter = bases[i];
Object *ob_iter = base_iter->object;
- bArmature *arm = ob_iter->data;
+ bArmature *arm = static_cast<bArmature *>(ob_iter->data);
/* Don't handle twice. */
if (arm->id.tag & LIB_TAG_DOIT) {
@@ -642,7 +647,7 @@ static bool do_pose_tag_select_op_exec(Base **bases, const uint bases_len, const
SET_FLAG_FROM_TEST(bone->flag, sel_op_result, BONE_SELECTED);
if (sel_op_result == 0) {
if (arm->act_bone == bone) {
- arm->act_bone = NULL;
+ arm->act_bone = nullptr;
}
}
changed = true;
@@ -662,22 +667,20 @@ static bool do_lasso_select_pose(ViewContext *vc,
const int mcoords_len,
const eSelectOp sel_op)
{
- uint bases_len;
- Base **bases = do_pose_tag_select_op_prepare(vc, &bases_len);
+ blender::Vector<Base *> bases = do_pose_tag_select_op_prepare(vc);
- for (int i = 0; i < bases_len; i++) {
+ for (const int i : bases.index_range()) {
Base *base_iter = bases[i];
Object *ob_iter = base_iter->object;
do_lasso_tag_pose(vc, ob_iter, mcoords, mcoords_len);
}
- const bool changed_multi = do_pose_tag_select_op_exec(bases, bases_len, sel_op);
+ const bool changed_multi = do_pose_tag_select_op_exec(bases, sel_op);
if (changed_multi) {
DEG_id_tag_update(&vc->scene->id, ID_RECALC_SELECT);
WM_main_add_notifier(NC_SCENE | ND_OB_SELECT, vc->scene);
}
- MEM_freeN(bases);
return changed_multi;
}
@@ -686,7 +689,7 @@ static void do_lasso_select_mesh__doSelectVert(void *userData,
const float screen_co[2],
int UNUSED(index))
{
- LassoSelectUserData *data = userData;
+ LassoSelectUserData *data = static_cast<LassoSelectUserData *>(userData);
const bool is_select = BM_elem_flag_test(eve, BM_ELEM_SELECT);
const bool is_inside =
(BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
@@ -700,7 +703,7 @@ static void do_lasso_select_mesh__doSelectVert(void *userData,
}
struct LassoSelectUserData_ForMeshEdge {
LassoSelectUserData *data;
- struct EditSelectBuf_Cache *esel;
+ EditSelectBuf_Cache *esel;
uint backbuf_offset;
};
static void do_lasso_select_mesh__doSelectEdge_pass0(void *user_data,
@@ -709,7 +712,8 @@ static void do_lasso_select_mesh__doSelectEdge_pass0(void *user_data,
const float screen_co_b[2],
int index)
{
- struct LassoSelectUserData_ForMeshEdge *data_for_edge = user_data;
+ LassoSelectUserData_ForMeshEdge *data_for_edge = static_cast<LassoSelectUserData_ForMeshEdge *>(
+ user_data);
LassoSelectUserData *data = data_for_edge->data;
bool is_visible = true;
if (data_for_edge->backbuf_offset) {
@@ -737,7 +741,8 @@ static void do_lasso_select_mesh__doSelectEdge_pass1(void *user_data,
const float screen_co_b[2],
int index)
{
- struct LassoSelectUserData_ForMeshEdge *data_for_edge = user_data;
+ LassoSelectUserData_ForMeshEdge *data_for_edge = static_cast<LassoSelectUserData_ForMeshEdge *>(
+ user_data);
LassoSelectUserData *data = data_for_edge->data;
bool is_visible = true;
if (data_for_edge->backbuf_offset) {
@@ -763,7 +768,7 @@ static void do_lasso_select_mesh__doSelectFace(void *userData,
const float screen_co[2],
int UNUSED(index))
{
- LassoSelectUserData *data = userData;
+ LassoSelectUserData *data = static_cast<LassoSelectUserData *>(userData);
const bool is_select = BM_elem_flag_test(efa, BM_ELEM_SELECT);
const bool is_inside =
(BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
@@ -807,13 +812,13 @@ static bool do_lasso_select_mesh(ViewContext *vc,
const bool use_zbuf = !XRAY_FLAG_ENABLED(vc->v3d);
- struct EditSelectBuf_Cache *esel = wm_userdata->data;
+ EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
if (use_zbuf) {
- if (wm_userdata->data == NULL) {
+ if (wm_userdata->data == nullptr) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, ts->selectmode);
- esel = wm_userdata->data;
+ esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
esel->select_bitmap = DRW_select_buffer_bitmap_from_poly(
- vc->depsgraph, vc->region, vc->v3d, mcoords, mcoords_len, &rect, NULL);
+ vc->depsgraph, vc->region, vc->v3d, mcoords, mcoords_len, &rect, nullptr);
}
}
@@ -829,16 +834,15 @@ static bool do_lasso_select_mesh(ViewContext *vc,
}
if (ts->selectmode & SCE_SELECT_EDGE) {
/* Does both use_zbuf and non-use_zbuf versions (need screen cos for both) */
- struct LassoSelectUserData_ForMeshEdge data_for_edge = {
- .data = &data,
- .esel = use_zbuf ? esel : NULL,
- .backbuf_offset = use_zbuf ? DRW_select_buffer_context_offset_for_object_elem(
- vc->depsgraph, vc->obedit, SCE_SELECT_EDGE) :
- 0,
- };
+ LassoSelectUserData_ForMeshEdge data_for_edge{};
+ data_for_edge.data = &data;
+ data_for_edge.esel = use_zbuf ? esel : nullptr;
+ data_for_edge.backbuf_offset = use_zbuf ? DRW_select_buffer_context_offset_for_object_elem(
+ vc->depsgraph, vc->obedit, SCE_SELECT_EDGE) :
+ 0;
const eV3DProjTest clip_flag = V3D_PROJ_TEST_CLIP_NEAR |
- (use_zbuf ? 0 : V3D_PROJ_TEST_CLIP_BB);
+ (use_zbuf ? (eV3DProjTest)0 : V3D_PROJ_TEST_CLIP_BB);
/* Fully inside. */
mesh_foreachScreenEdge_clip_bb_segment(
vc, do_lasso_select_mesh__doSelectEdge_pass0, &data_for_edge, clip_flag);
@@ -877,7 +881,7 @@ static void do_lasso_select_curve__doSelect(void *userData,
bool handles_visible,
const float screen_co[2])
{
- LassoSelectUserData *data = userData;
+ LassoSelectUserData *data = static_cast<LassoSelectUserData *>(userData);
const bool is_inside = BLI_lasso_is_point_inside(
data->mcoords, data->mcoords_len, screen_co[0], screen_co[1], IS_CLIPPED);
@@ -943,14 +947,14 @@ static bool do_lasso_select_curve(ViewContext *vc,
}
if (data.is_changed) {
- BKE_curve_nurb_vert_active_validate(vc->obedit->data);
+ BKE_curve_nurb_vert_active_validate(static_cast<Curve *>(vc->obedit->data));
}
return data.is_changed;
}
static void do_lasso_select_lattice__doSelect(void *userData, BPoint *bp, const float screen_co[2])
{
- LassoSelectUserData *data = userData;
+ LassoSelectUserData *data = static_cast<LassoSelectUserData *>(userData);
const bool is_select = bp->f1 & SELECT;
const bool is_inside =
(BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
@@ -989,8 +993,8 @@ static void do_lasso_select_armature__doSelectBone(void *userData,
const float screen_co_a[2],
const float screen_co_b[2])
{
- LassoSelectUserData *data = userData;
- const bArmature *arm = data->vc->obedit->data;
+ LassoSelectUserData *data = static_cast<LassoSelectUserData *>(userData);
+ const bArmature *arm = static_cast<const bArmature *>(data->vc->obedit->data);
if (!EBONE_VISIBLE(arm, ebone)) {
return;
}
@@ -1038,8 +1042,8 @@ static void do_lasso_select_armature__doSelectBone_clip_content(void *userData,
const float screen_co_a[2],
const float screen_co_b[2])
{
- LassoSelectUserData *data = userData;
- bArmature *arm = data->vc->obedit->data;
+ LassoSelectUserData *data = static_cast<LassoSelectUserData *>(userData);
+ bArmature *arm = static_cast<bArmature *>(data->vc->obedit->data);
if (!EBONE_VISIBLE(arm, ebone)) {
return;
}
@@ -1078,7 +1082,7 @@ static bool do_lasso_select_armature(ViewContext *vc,
data.is_changed |= ED_armature_edit_deselect_all_visible(vc->obedit);
}
- bArmature *arm = vc->obedit->data;
+ bArmature *arm = static_cast<bArmature *>(vc->obedit->data);
ED_armature_ebone_listbase_temp_clear(arm->edbo);
@@ -1096,7 +1100,7 @@ static bool do_lasso_select_armature(ViewContext *vc,
&data,
V3D_PROJ_TEST_CLIP_DEFAULT | V3D_PROJ_TEST_CLIP_CONTENT_DEFAULT);
- data.is_changed |= ED_armature_edit_select_op_from_tagged(vc->obedit->data, sel_op);
+ data.is_changed |= ED_armature_edit_select_op_from_tagged(arm, sel_op);
if (data.is_changed) {
WM_main_add_notifier(NC_OBJECT | ND_BONE_SELECT, vc->obedit);
@@ -1105,10 +1109,10 @@ static bool do_lasso_select_armature(ViewContext *vc,
}
static void do_lasso_select_mball__doSelectElem(void *userData,
- struct MetaElem *ml,
+ MetaElem *ml,
const float screen_co[2])
{
- LassoSelectUserData *data = userData;
+ LassoSelectUserData *data = static_cast<LassoSelectUserData *>(userData);
const bool is_select = ml->flag & SELECT;
const bool is_inside =
(BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
@@ -1151,7 +1155,7 @@ static void do_lasso_select_meshobject__doSelectVert(void *userData,
const float screen_co[2],
int UNUSED(index))
{
- LassoSelectUserData *data = userData;
+ LassoSelectUserData *data = static_cast<LassoSelectUserData *>(userData);
const bool is_select = mv->flag & SELECT;
const bool is_inside =
(BLI_rctf_isect_pt_v(data->rect_fl, screen_co) &&
@@ -1171,10 +1175,10 @@ static bool do_lasso_select_paintvert(ViewContext *vc,
{
const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
Object *ob = vc->obact;
- Mesh *me = ob->data;
+ Mesh *me = static_cast<Mesh *>(ob->data);
rcti rect;
- if (me == NULL || me->totvert == 0) {
+ if (me == nullptr || me->totvert == 0) {
return false;
}
@@ -1186,18 +1190,18 @@ static bool do_lasso_select_paintvert(ViewContext *vc,
BLI_lasso_boundbox(&rect, mcoords, mcoords_len);
- struct EditSelectBuf_Cache *esel = wm_userdata->data;
+ EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
if (use_zbuf) {
- if (wm_userdata->data == NULL) {
+ if (wm_userdata->data == nullptr) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_VERTEX);
- esel = wm_userdata->data;
+ esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
esel->select_bitmap = DRW_select_buffer_bitmap_from_poly(
- vc->depsgraph, vc->region, vc->v3d, mcoords, mcoords_len, &rect, NULL);
+ vc->depsgraph, vc->region, vc->v3d, mcoords, mcoords_len, &rect, nullptr);
}
}
if (use_zbuf) {
- if (esel->select_bitmap != NULL) {
+ if (esel->select_bitmap != nullptr) {
changed |= edbm_backbuf_check_and_select_verts_obmode(me, esel, sel_op);
}
}
@@ -1231,10 +1235,10 @@ static bool do_lasso_select_paintface(ViewContext *vc,
const eSelectOp sel_op)
{
Object *ob = vc->obact;
- Mesh *me = ob->data;
+ Mesh *me = static_cast<Mesh *>(ob->data);
rcti rect;
- if (me == NULL || me->totpoly == 0) {
+ if (me == nullptr || me->totpoly == 0) {
return false;
}
@@ -1246,12 +1250,12 @@ static bool do_lasso_select_paintface(ViewContext *vc,
BLI_lasso_boundbox(&rect, mcoords, mcoords_len);
- struct EditSelectBuf_Cache *esel = wm_userdata->data;
- if (esel == NULL) {
+ EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
+ if (esel == nullptr) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_FACE);
- esel = wm_userdata->data;
+ esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
esel->select_bitmap = DRW_select_buffer_bitmap_from_poly(
- vc->depsgraph, vc->region, vc->v3d, mcoords, mcoords_len, &rect, NULL);
+ vc->depsgraph, vc->region, vc->v3d, mcoords, mcoords_len, &rect, nullptr);
}
if (esel->select_bitmap) {
@@ -1259,7 +1263,7 @@ static bool do_lasso_select_paintface(ViewContext *vc,
}
if (changed) {
- paintface_flush_flags(vc->C, ob, SELECT);
+ paintface_flush_flags(vc->C, ob, true, false);
}
return changed;
}
@@ -1273,10 +1277,10 @@ static bool view3d_lasso_select(bContext *C,
Object *ob = CTX_data_active_object(C);
bool changed_multi = false;
- wmGenericUserData wm_userdata_buf = {0};
+ wmGenericUserData wm_userdata_buf = {nullptr, nullptr, false};
wmGenericUserData *wm_userdata = &wm_userdata_buf;
- if (vc->obedit == NULL) { /* Object Mode */
+ if (vc->obedit == nullptr) { /* Object Mode */
if (BKE_paint_select_face_test(ob)) {
changed_multi |= do_lasso_select_paintface(vc, wm_userdata, mcoords, mcoords_len, sel_op);
}
@@ -1288,7 +1292,7 @@ static bool view3d_lasso_select(bContext *C,
/* pass */
}
else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
- changed_multi |= PE_lasso_select(C, mcoords, mcoords_len, sel_op);
+ changed_multi |= PE_lasso_select(C, mcoords, mcoords_len, sel_op) != OPERATOR_CANCELLED;
}
else if (ob && (ob->mode & OB_MODE_POSE)) {
changed_multi |= do_lasso_select_pose(vc, mcoords, mcoords_len, sel_op);
@@ -1334,7 +1338,7 @@ static bool view3d_lasso_select(bContext *C,
}
if (changed) {
- DEG_id_tag_update(vc->obedit->data, ID_RECALC_SELECT);
+ DEG_id_tag_update(static_cast<ID *>(vc->obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc->obedit->data);
changed_multi = true;
}
@@ -1363,7 +1367,7 @@ static int view3d_lasso_select_exec(bContext *C, wmOperator *op)
/* setup view context for argument to callbacks */
ED_view3d_viewcontext_init(C, &vc, depsgraph);
- eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
+ eSelectOp sel_op = static_cast<eSelectOp>(RNA_enum_get(op->ptr, "mode"));
bool changed_multi = view3d_lasso_select(C, &vc, mcoords, mcoords_len, sel_op);
MEM_freeN((void *)mcoords);
@@ -1403,12 +1407,12 @@ void VIEW3D_OT_select_lasso(wmOperatorType *ot)
* \{ */
/* The max number of menu items in an object select menu */
-typedef struct SelMenuItemF {
+struct SelMenuItemF {
char idname[MAX_ID_NAME - 2];
int icon;
Base *base_ptr;
void *item_ptr;
-} SelMenuItemF;
+};
#define SEL_MENU_SIZE 22
static SelMenuItemF object_mouse_select_menu_data[SEL_MENU_SIZE];
@@ -1419,12 +1423,12 @@ static const EnumPropertyItem *object_select_menu_enum_itemf(bContext *C,
PropertyRNA *UNUSED(prop),
bool *r_free)
{
- EnumPropertyItem *item = NULL, item_tmp = {0};
+ EnumPropertyItem *item = nullptr, item_tmp = {0};
int totitem = 0;
int i = 0;
/* Don't need context but avoid API doc-generation using this. */
- if (C == NULL || object_mouse_select_menu_data[i].idname[0] == '\0') {
+ if (C == nullptr || object_mouse_select_menu_data[i].idname[0] == '\0') {
return DummyRNA_NULL_items;
}
@@ -1453,9 +1457,9 @@ static int object_select_menu_exec(bContext *C, wmOperator *op)
View3D *v3d = CTX_wm_view3d(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
- const Base *oldbasact = BASACT(view_layer);
+ const Base *oldbasact = view_layer->basact;
- Base *basact = NULL;
+ Base *basact = nullptr;
CTX_DATA_BEGIN (C, Base *, base, selectable_bases) {
/* This is a bit dodgy, there should only be ONE object with this name,
* but library objects can mess this up. */
@@ -1466,7 +1470,7 @@ static int object_select_menu_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
- if (basact == NULL) {
+ if (basact == nullptr) {
return OPERATOR_CANCELLED;
}
UNUSED_VARS_NDEBUG(v3d);
@@ -1537,14 +1541,14 @@ void VIEW3D_OT_select_menu(wmOperatorType *ot)
/* #Object.id.name to select (dynamic enum). */
prop = RNA_def_enum(ot->srna, "name", DummyRNA_NULL_items, 0, "Object Name", "");
RNA_def_enum_funcs(prop, object_select_menu_enum_itemf);
- RNA_def_property_flag(prop, PROP_HIDDEN | PROP_ENUM_NO_TRANSLATE);
+ RNA_def_property_flag(prop, (PropertyFlag)(PROP_HIDDEN | PROP_ENUM_NO_TRANSLATE));
ot->prop = prop;
- prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "");
+ prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "");
+ prop = RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
+ prop = RNA_def_boolean(ot->srna, "toggle", false, "Toggle", "");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
@@ -1556,12 +1560,12 @@ static bool object_mouse_select_menu(bContext *C,
const GPUSelectResult *buffer,
const int hits,
const int mval[2],
- const struct SelectPick_Params *params,
+ const SelectPick_Params *params,
Base **r_basact)
{
int base_count = 0;
bool ok;
- LinkNodePair linklist = {NULL, NULL};
+ LinkNodePair linklist = {nullptr, nullptr};
/* handle base->object->select_id */
CTX_DATA_BEGIN (C, Base *, base, selectable_bases) {
@@ -1598,14 +1602,14 @@ static bool object_mouse_select_menu(bContext *C,
}
CTX_DATA_END;
- *r_basact = NULL;
+ *r_basact = nullptr;
if (base_count == 0) {
return false;
}
if (base_count == 1) {
Base *base = (Base *)linklist.list->link;
- BLI_linklist_free(linklist.list, NULL);
+ BLI_linklist_free(linklist.list, nullptr);
*r_basact = base;
return false;
}
@@ -1617,7 +1621,7 @@ static bool object_mouse_select_menu(bContext *C,
memset(object_mouse_select_menu_data, 0, sizeof(object_mouse_select_menu_data));
for (node = linklist.list, i = 0; node; node = node->next, i++) {
- Base *base = node->link;
+ Base *base = static_cast<Base *>(node->link);
Object *ob = base->object;
const char *name = ob->id.name + 2;
@@ -1632,10 +1636,10 @@ static bool object_mouse_select_menu(bContext *C,
RNA_boolean_set(&ptr, "extend", params->sel_op == SEL_OP_ADD);
RNA_boolean_set(&ptr, "deselect", params->sel_op == SEL_OP_SUB);
RNA_boolean_set(&ptr, "toggle", params->sel_op == SEL_OP_XOR);
- WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr, NULL);
+ WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr, nullptr);
WM_operator_properties_free(&ptr);
- BLI_linklist_free(linklist.list, NULL);
+ BLI_linklist_free(linklist.list, nullptr);
return true;
}
@@ -1643,17 +1647,16 @@ static int bone_select_menu_exec(bContext *C, wmOperator *op)
{
const int name_index = RNA_enum_get(op->ptr, "name");
- const struct SelectPick_Params params = {
- .sel_op = ED_select_op_from_operator(op->ptr),
- };
+ SelectPick_Params params{};
+ params.sel_op = ED_select_op_from_operator(op->ptr);
View3D *v3d = CTX_wm_view3d(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
- const Base *oldbasact = BASACT(view_layer);
+ const Base *oldbasact = view_layer->basact;
Base *basact = object_mouse_select_menu_data[name_index].base_ptr;
- if (basact == NULL) {
+ if (basact == nullptr) {
return OPERATOR_CANCELLED;
}
@@ -1728,14 +1731,14 @@ void VIEW3D_OT_bone_select_menu(wmOperatorType *ot)
/* #Object.id.name to select (dynamic enum). */
prop = RNA_def_enum(ot->srna, "name", DummyRNA_NULL_items, 0, "Bone Name", "");
RNA_def_enum_funcs(prop, object_select_menu_enum_itemf);
- RNA_def_property_flag(prop, PROP_HIDDEN | PROP_ENUM_NO_TRANSLATE);
+ RNA_def_property_flag(prop, (PropertyFlag)(PROP_HIDDEN | PROP_ENUM_NO_TRANSLATE));
ot->prop = prop;
- prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "");
+ prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "");
+ prop = RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
+ prop = RNA_def_boolean(ot->srna, "toggle", false, "Toggle", "");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
@@ -1746,19 +1749,19 @@ static bool bone_mouse_select_menu(bContext *C,
const GPUSelectResult *buffer,
const int hits,
const bool is_editmode,
- const struct SelectPick_Params *params)
+ const SelectPick_Params *params)
{
BLI_assert(buffer);
int bone_count = 0;
- LinkNodePair base_list = {NULL, NULL};
- LinkNodePair bone_list = {NULL, NULL};
+ LinkNodePair base_list = {nullptr, nullptr};
+ LinkNodePair bone_list = {nullptr, nullptr};
GSet *added_bones = BLI_gset_ptr_new("Bone mouse select menu");
/* Select logic taken from ed_armature_pick_bone_from_selectbuffer_impl in armature_select.c */
for (int a = 0; a < hits; a++) {
- void *bone_ptr = NULL;
- Base *bone_base = NULL;
+ void *bone_ptr = nullptr;
+ Base *bone_base = nullptr;
uint hitresult = buffer[a].id;
if (!(hitresult & BONESEL_ANY)) {
@@ -1786,8 +1789,8 @@ static bool bone_mouse_select_menu(bContext *C,
if (is_editmode) {
EditBone *ebone;
const uint hit_bone = (hitresult & ~BONESEL_ANY) >> 16;
- bArmature *arm = bone_base->object->data;
- ebone = BLI_findlink(arm->edbo, hit_bone);
+ bArmature *arm = static_cast<bArmature *>(bone_base->object->data);
+ ebone = static_cast<EditBone *>(BLI_findlink(arm->edbo, hit_bone));
if (ebone && !(ebone->flag & BONE_UNSELECTABLE)) {
bone_ptr = ebone;
}
@@ -1795,7 +1798,8 @@ static bool bone_mouse_select_menu(bContext *C,
else {
bPoseChannel *pchan;
const uint hit_bone = (hitresult & ~BONESEL_ANY) >> 16;
- pchan = BLI_findlink(&bone_base->object->pose->chanbase, hit_bone);
+ pchan = static_cast<bPoseChannel *>(
+ BLI_findlink(&bone_base->object->pose->chanbase, hit_bone));
if (pchan && !(pchan->bone->flag & BONE_UNSELECTABLE)) {
bone_ptr = pchan;
}
@@ -1820,14 +1824,14 @@ static bool bone_mouse_select_menu(bContext *C,
}
}
- BLI_gset_free(added_bones, NULL);
+ BLI_gset_free(added_bones, nullptr);
if (bone_count == 0) {
return false;
}
if (bone_count == 1) {
- BLI_linklist_free(base_list.list, NULL);
- BLI_linklist_free(bone_list.list, NULL);
+ BLI_linklist_free(base_list.list, nullptr);
+ BLI_linklist_free(bone_list.list, nullptr);
return false;
}
@@ -1841,15 +1845,15 @@ static bool bone_mouse_select_menu(bContext *C,
base_node = base_node->next, bone_node = bone_node->next, i++) {
char *name;
- object_mouse_select_menu_data[i].base_ptr = base_node->link;
+ object_mouse_select_menu_data[i].base_ptr = static_cast<Base *>(base_node->link);
if (is_editmode) {
- EditBone *ebone = bone_node->link;
+ EditBone *ebone = static_cast<EditBone *>(bone_node->link);
object_mouse_select_menu_data[i].item_ptr = ebone;
name = ebone->name;
}
else {
- bPoseChannel *pchan = bone_node->link;
+ bPoseChannel *pchan = static_cast<bPoseChannel *>(bone_node->link);
object_mouse_select_menu_data[i].item_ptr = pchan;
name = pchan->name;
}
@@ -1865,11 +1869,11 @@ static bool bone_mouse_select_menu(bContext *C,
RNA_boolean_set(&ptr, "extend", params->sel_op == SEL_OP_ADD);
RNA_boolean_set(&ptr, "deselect", params->sel_op == SEL_OP_SUB);
RNA_boolean_set(&ptr, "toggle", params->sel_op == SEL_OP_XOR);
- WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr, NULL);
+ WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr, nullptr);
WM_operator_properties_free(&ptr);
- BLI_linklist_free(base_list.list, NULL);
- BLI_linklist_free(bone_list.list, NULL);
+ BLI_linklist_free(base_list.list, nullptr);
+ BLI_linklist_free(bone_list.list, nullptr);
return true;
}
@@ -1927,7 +1931,7 @@ static int mixed_bones_object_selectbuffer(ViewContext *vc,
int hits15, hits9 = 0, hits5 = 0;
bool has_bones15 = false, has_bones9 = false, has_bones5 = false;
- int select_mode = (do_nearest ? VIEW3D_SELECT_PICK_NEAREST : VIEW3D_SELECT_PICK_ALL);
+ eV3DSelectMode select_mode = (do_nearest ? VIEW3D_SELECT_PICK_NEAREST : VIEW3D_SELECT_PICK_ALL);
int hits = 0;
if (do_nearest_xray_if_supported) {
@@ -2083,7 +2087,7 @@ static int gpu_select_buffer_depth_id_cmp(const void *sel_a_p, const void *sel_b
* that are visible but not select-able,
* since you may be in pose mode with an un-selectable object.
*
- * \return the active base or NULL.
+ * \return the active base or nullptr.
*/
static Base *mouse_select_eval_buffer(ViewContext *vc,
const GPUSelectResult *buffer,
@@ -2135,7 +2139,8 @@ static Base *mouse_select_eval_buffer(ViewContext *vc,
else {
{
- GPUSelectResult *buffer_sorted = MEM_mallocN(sizeof(*buffer_sorted) * hits, __func__);
+ GPUSelectResult *buffer_sorted = static_cast<GPUSelectResult *>(
+ MEM_mallocN(sizeof(*buffer_sorted) * hits, __func__));
memcpy(buffer_sorted, buffer, sizeof(*buffer_sorted) * hits);
/* Remove non-bone objects. */
if (has_bones && do_bones_get_priotity) {
@@ -2155,8 +2160,8 @@ static Base *mouse_select_eval_buffer(ViewContext *vc,
/* It's possible there are no hits (all objects contained bones). */
if (hits > 0) {
/* Only exclude active object when it is selected. */
- if (BASACT(view_layer) && (BASACT(view_layer)->flag & BASE_SELECTED)) {
- const int select_id_active = BASACT(view_layer)->object->runtime.select_id;
+ if (view_layer->basact && (view_layer->basact->flag & BASE_SELECTED)) {
+ const int select_id_active = view_layer->basact->object->runtime.select_id;
for (int i_next = 0, i_prev = hits - 1; i_next < hits; i_prev = i_next++) {
if ((select_id_active == (buffer[i_prev].id & 0xFFFF)) &&
(select_id_active != (buffer[i_next].id & 0xFFFF))) {
@@ -2181,9 +2186,9 @@ static Base *mouse_select_eval_buffer(ViewContext *vc,
MEM_freeN((void *)buffer);
}
- Base *basact = NULL;
+ Base *basact = nullptr;
if (found) {
- for (Base *base = FIRSTBASE(view_layer); base; base = base->next) {
+ LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
if (has_bones ? BASE_VISIBLE(v3d, base) : BASE_SELECTABLE(v3d, base)) {
if (base->object->runtime.select_id == select_id) {
basact = base;
@@ -2206,11 +2211,11 @@ static Base *mouse_select_object_center(ViewContext *vc, Base *startbase, const
ViewLayer *view_layer = vc->view_layer;
View3D *v3d = vc->v3d;
- Base *oldbasact = BASACT(view_layer);
+ Base *oldbasact = view_layer->basact;
const float mval_fl[2] = {(float)mval[0], (float)mval[1]};
float dist = ED_view3d_select_dist_px() * 1.3333f;
- Base *basact = NULL;
+ Base *basact = nullptr;
/* Put the active object at a disadvantage to cycle through other objects. */
const float penalty_dist = 10.0f * UI_DPI_FAC;
@@ -2233,8 +2238,8 @@ static Base *mouse_select_object_center(ViewContext *vc, Base *startbase, const
}
base = base->next;
- if (base == NULL) {
- base = FIRSTBASE(view_layer);
+ if (base == nullptr) {
+ base = static_cast<Base *>(view_layer->object_bases.first);
}
if (base == startbase) {
break;
@@ -2249,7 +2254,7 @@ static Base *ed_view3d_give_base_under_cursor_ex(bContext *C,
{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc;
- Base *basact = NULL;
+ Base *basact = nullptr;
GPUSelectResult buffer[MAXPICKELEMS];
/* setup view context for argument to callbacks */
@@ -2259,7 +2264,7 @@ static Base *ed_view3d_give_base_under_cursor_ex(bContext *C,
ED_view3d_viewcontext_init(C, &vc, depsgraph);
const bool do_nearest = !XRAY_ACTIVE(vc.v3d);
- const bool do_material_slot_selection = r_material_slot != NULL;
+ const bool do_material_slot_selection = r_material_slot != nullptr;
const int hits = mixed_bones_object_selectbuffer(&vc,
buffer,
ARRAY_SIZE(buffer),
@@ -2270,7 +2275,7 @@ static Base *ed_view3d_give_base_under_cursor_ex(bContext *C,
do_material_slot_selection);
if (hits > 0) {
- const bool has_bones = (r_material_slot == NULL) && selectbuffer_has_bones(buffer, hits);
+ const bool has_bones = (r_material_slot == nullptr) && selectbuffer_has_bones(buffer, hits);
basact = mouse_select_eval_buffer(
&vc, buffer, hits, do_nearest, has_bones, true, r_material_slot);
}
@@ -2280,7 +2285,7 @@ static Base *ed_view3d_give_base_under_cursor_ex(bContext *C,
Base *ED_view3d_give_base_under_cursor(bContext *C, const int mval[2])
{
- return ed_view3d_give_base_under_cursor_ex(C, mval, NULL);
+ return ed_view3d_give_base_under_cursor_ex(C, mval, nullptr);
}
Object *ED_view3d_give_object_under_cursor(bContext *C, const int mval[2])
@@ -2289,33 +2294,33 @@ Object *ED_view3d_give_object_under_cursor(bContext *C, const int mval[2])
if (base) {
return base->object;
}
- return NULL;
+ return nullptr;
}
-struct Object *ED_view3d_give_material_slot_under_cursor(struct bContext *C,
- const int mval[2],
- int *r_material_slot)
+Object *ED_view3d_give_material_slot_under_cursor(bContext *C,
+ const int mval[2],
+ int *r_material_slot)
{
Base *base = ed_view3d_give_base_under_cursor_ex(C, mval, r_material_slot);
if (base) {
return base->object;
}
- return NULL;
+ return nullptr;
}
bool ED_view3d_is_object_under_cursor(bContext *C, const int mval[2])
{
- return ED_view3d_give_object_under_cursor(C, mval) != NULL;
+ return ED_view3d_give_object_under_cursor(C, mval) != nullptr;
}
static void deselect_all_tracks(MovieTracking *tracking)
{
MovieTrackingObject *object;
- object = tracking->objects.first;
+ object = static_cast<MovieTrackingObject *>(tracking->objects.first);
while (object) {
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
- MovieTrackingTrack *track = tracksbase->first;
+ MovieTrackingTrack *track = static_cast<MovieTrackingTrack *>(tracksbase->first);
while (track) {
BKE_tracking_track_deselect(track, TRACK_AREA_ALL);
@@ -2331,16 +2336,16 @@ static bool ed_object_select_pick_camera_track(bContext *C,
Scene *scene,
Base *basact,
MovieClip *clip,
- const struct GPUSelectResult *buffer,
+ const GPUSelectResult *buffer,
const short hits,
- const struct SelectPick_Params *params)
+ const SelectPick_Params *params)
{
bool changed = false;
bool found = false;
MovieTracking *tracking = &clip->tracking;
- ListBase *tracksbase = NULL;
- MovieTrackingTrack *track = NULL;
+ ListBase *tracksbase = nullptr;
+ MovieTrackingTrack *track = nullptr;
for (int i = 0; i < hits; i++) {
const int hitresult = buffer[i].id;
@@ -2428,7 +2433,7 @@ static bool ed_object_select_pick_camera_track(bContext *C,
*/
static bool ed_object_select_pick(bContext *C,
const int mval[2],
- const struct SelectPick_Params *params,
+ const SelectPick_Params *params,
const bool center,
const bool enumerate,
const bool object_only)
@@ -2442,21 +2447,21 @@ static bool ed_object_select_pick(bContext *C,
View3D *v3d = vc.v3d;
/* Menu activation may find a base to make active (if it only finds a single item to select). */
- Base *basact_override = NULL;
+ Base *basact_override = nullptr;
- const bool is_obedit = (vc.obedit != NULL);
+ const bool is_obedit = (vc.obedit != nullptr);
if (object_only) {
/* Signal for #view3d_opengl_select to skip edit-mode objects. */
- vc.obedit = NULL;
+ vc.obedit = nullptr;
}
- /* Set for GPU depth buffer picking, leave NULL when selecting by center. */
- struct {
+ /* Set for GPU depth buffer picking, leave null when selecting by center. */
+ struct GPUData {
GPUSelectResult buffer[MAXPICKELEMS];
int hits;
bool do_nearest;
bool has_bones;
- } *gpu = NULL;
+ } *gpu = nullptr;
/* First handle menu selection, early exit if a menu opens
* since this takes ownership of the selection action.
@@ -2465,7 +2470,7 @@ static bool ed_object_select_pick(bContext *C,
* the item under the cursor. */
if (center == false) {
- gpu = MEM_mallocN(sizeof(*gpu), __func__);
+ gpu = MEM_new<GPUData>(__func__);
gpu->do_nearest = false;
gpu->has_bones = false;
@@ -2492,7 +2497,7 @@ static bool ed_object_select_pick(bContext *C,
if (enumerate) {
bool has_menu = false;
if (center) {
- if (object_mouse_select_menu(C, &vc, NULL, 0, mval, params, &basact_override)) {
+ if (object_mouse_select_menu(C, &vc, nullptr, 0, mval, params, &basact_override)) {
has_menu = true;
}
}
@@ -2510,7 +2515,7 @@ static bool ed_object_select_pick(bContext *C,
/* Let the menu handle any further actions. */
if (has_menu) {
- if (gpu != NULL) {
+ if (gpu != nullptr) {
MEM_freeN(gpu);
}
return false;
@@ -2521,13 +2526,16 @@ static bool ed_object_select_pick(bContext *C,
ViewLayer *view_layer = vc.view_layer;
/* Don't set when the context has no active object (hidden), see: T60807. */
- const Base *oldbasact = vc.obact ? BASACT(view_layer) : NULL;
+ const Base *oldbasact = vc.obact ? view_layer->basact : nullptr;
/* Always start list from `basact` when cycling the selection. */
- Base *startbase = (oldbasact && oldbasact->next) ? oldbasact->next : FIRSTBASE(view_layer);
+ Base *startbase = (oldbasact && oldbasact->next) ?
+ oldbasact->next :
+ static_cast<Base *>(view_layer->object_bases.first);
/* The next object's base to make active. */
- Base *basact = NULL;
- const eObjectMode object_mode = oldbasact ? oldbasact->object->mode : OB_MODE_OBJECT;
+ Base *basact = nullptr;
+ const eObjectMode object_mode = oldbasact ? static_cast<eObjectMode>(oldbasact->object->mode) :
+ OB_MODE_OBJECT;
/* When enabled, don't attempt any further selection. */
bool handled = false;
@@ -2574,8 +2582,8 @@ static bool ed_object_select_pick(bContext *C,
gpu->do_nearest,
gpu->has_bones,
do_bones_get_priotity,
- NULL) :
- NULL;
+ nullptr) :
+ nullptr;
}
/* Select pose-bones or camera-tracks. */
@@ -2585,7 +2593,7 @@ static bool ed_object_select_pick(bContext *C,
if (basact && (gpu->has_bones && (basact->object->type == OB_CAMERA))) {
MovieClip *clip = BKE_object_movieclip_get(scene, basact->object, false);
- if (clip != NULL) {
+ if (clip != nullptr) {
if (ed_object_select_pick_camera_track(
C, scene, basact, clip, gpu->buffer, gpu->hits, params)) {
ED_object_base_select(basact, BA_SELECT);
@@ -2598,7 +2606,7 @@ static bool ed_object_select_pick(bContext *C,
/* Fallback to regular object selection if no new bundles were selected,
* allows to select object parented to reconstruction object. */
basact = mouse_select_eval_buffer(
- &vc, gpu->buffer, gpu->hits, gpu->do_nearest, false, false, NULL);
+ &vc, gpu->buffer, gpu->hits, gpu->do_nearest, false, false, nullptr);
}
}
}
@@ -2615,7 +2623,7 @@ static bool ed_object_select_pick(bContext *C,
/* When there is no `baseact` this will have operated on `oldbasact`,
* allowing #SelectPick_Params.deselect_all work in pose-mode.
* In this case no object operations are needed. */
- if (basact != NULL) {
+ if (basact != nullptr) {
/* By convention the armature-object is selected when in pose-mode.
* While leaving it unselected will work, leaving pose-mode would leave the object
* active + unselected which isn't ideal when performing other actions on the object. */
@@ -2670,11 +2678,11 @@ static bool ed_object_select_pick(bContext *C,
if (is_obedit == false) {
if (basact && !BKE_object_is_mode_compat(basact->object, object_mode)) {
if (object_mode == OB_MODE_OBJECT) {
- struct Main *bmain = vc.bmain;
+ Main *bmain = vc.bmain;
ED_object_mode_generic_exit(bmain, vc.depsgraph, scene, basact->object);
}
if (!BKE_object_is_mode_compat(basact->object, object_mode)) {
- basact = NULL;
+ basact = nullptr;
}
}
@@ -2683,7 +2691,7 @@ static bool ed_object_select_pick(bContext *C,
if (basact && oldbasact) {
if ((oldbasact->object->mode != basact->object->mode) &&
(oldbasact->object->mode & basact->object->mode) == 0) {
- basact = NULL;
+ basact = nullptr;
}
}
}
@@ -2692,10 +2700,10 @@ static bool ed_object_select_pick(bContext *C,
/* Ensure code above doesn't change the active base. This code is already fairly involved,
* it's best if changing the active object is localized to a single place. */
- BLI_assert(oldbasact == (vc.obact ? BASACT(view_layer) : NULL));
+ BLI_assert(oldbasact == (vc.obact ? view_layer->basact : nullptr));
- bool found = (basact != NULL);
- if ((handled == false) && (vc.obedit == NULL)) {
+ bool found = (basact != nullptr);
+ if ((handled == false) && (vc.obedit == nullptr)) {
/* Object-mode (pose mode will have been handled already). */
if (params->sel_op == SEL_OP_SET) {
if ((found && params->select_passthrough) && (basact->flag & BASE_SELECTED)) {
@@ -2703,7 +2711,7 @@ static bool ed_object_select_pick(bContext *C,
}
else if (found || params->deselect_all) {
/* Deselect everything. */
- /* `basact` may be NULL. */
+ /* `basact` may be nullptr. */
if (ED_view3d_object_deselect_all_except(view_layer, basact)) {
changed_object = true;
}
@@ -2763,7 +2771,7 @@ static bool ed_object_select_pick(bContext *C,
/* Perform the activation even when 'handled', since this is used to ensure
* the object from the pose-bone selected is also activated. */
- if (use_activate_selected_base && (basact != NULL)) {
+ if (use_activate_selected_base && (basact != nullptr)) {
changed_object = true;
ED_object_base_activate(C, basact); /* adds notifier */
if ((scene->toolsettings->object_flag & SCE_OBJECT_MODE_LOCK) == 0) {
@@ -2782,7 +2790,7 @@ static bool ed_object_select_pick(bContext *C,
ED_outliner_select_sync_from_pose_bone_tag(C);
}
- if (gpu != NULL) {
+ if (gpu != nullptr) {
MEM_freeN(gpu);
}
@@ -2797,21 +2805,23 @@ static bool ed_object_select_pick(bContext *C,
*/
static bool ed_wpaint_vertex_select_pick(bContext *C,
const int mval[2],
- const struct SelectPick_Params *params,
+ const SelectPick_Params *params,
Object *obact)
{
View3D *v3d = CTX_wm_view3d(C);
const bool use_zbuf = !XRAY_ENABLED(v3d);
- Mesh *me = obact->data; /* already checked for NULL */
+ Mesh *me = static_cast<Mesh *>(obact->data); /* already checked for nullptr */
uint index = 0;
+ MVert *verts = BKE_mesh_verts_for_write(me);
+
MVert *mv;
bool changed = false;
bool found = ED_mesh_pick_vert(C, obact, mval, ED_MESH_PICK_DEFAULT_VERT_DIST, use_zbuf, &index);
if (params->sel_op == SEL_OP_SET) {
- if ((found && params->select_passthrough) && (me->mvert[index].flag & SELECT)) {
+ if ((found && params->select_passthrough) && (verts[index].flag & SELECT)) {
found = false;
}
else if (found || params->deselect_all) {
@@ -2821,7 +2831,7 @@ static bool ed_wpaint_vertex_select_pick(bContext *C,
}
if (found) {
- mv = &me->mvert[index];
+ mv = &verts[index];
switch (params->sel_op) {
case SEL_OP_ADD: {
mv->flag |= SELECT;
@@ -2872,7 +2882,7 @@ static int view3d_select_exec(bContext *C, wmOperator *op)
Object *obedit = CTX_data_edit_object(C);
Object *obact = CTX_data_active_object(C);
- struct SelectPick_Params params = {0};
+ SelectPick_Params params{};
ED_select_pick_params_from_operator(op->ptr, &params);
const bool vert_without_handles = RNA_boolean_get(op->ptr, "vert_without_handles");
@@ -2892,14 +2902,9 @@ static int view3d_select_exec(bContext *C, wmOperator *op)
bool changed = false;
int mval[2];
- RNA_int_get_array(op->ptr, "location", mval);
-
- view3d_operator_needs_opengl(C);
- BKE_object_update_select_id(CTX_data_main(C));
-
if (object_only) {
- obedit = NULL;
- obact = NULL;
+ obedit = nullptr;
+ obact = nullptr;
/* ack, this is incorrect but to do this correctly we would need an
* alternative edit-mode/object-mode keymap, this copies the functionality
@@ -2907,6 +2912,19 @@ static int view3d_select_exec(bContext *C, wmOperator *op)
center = false;
}
+ if (obedit && enumerate) {
+ /* Enumerate makes no sense in edit-mode unless also explicitly picking objects or bones.
+ * Pass the event through so the event may be handled by loop-select for e.g. see: T100204. */
+ if (obedit->type != OB_ARMATURE) {
+ return OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED;
+ }
+ }
+
+ RNA_int_get_array(op->ptr, "location", mval);
+
+ view3d_operator_needs_opengl(C);
+ BKE_object_update_select_id(CTX_data_main(C));
+
if (obedit && object_only == false) {
if (obedit->type == OB_MESH) {
changed = EDBM_select_pick(C, mval, &params);
@@ -2998,21 +3016,25 @@ void VIEW3D_OT_select(wmOperatorType *ot)
prop = RNA_def_boolean(
ot->srna,
"center",
- 0,
+ false,
"Center",
"Use the object center when selecting, in edit mode used to extend object selection");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(
- ot->srna, "enumerate", 0, "Enumerate", "List objects under the mouse (object mode only)");
+ prop = RNA_def_boolean(ot->srna,
+ "enumerate",
+ false,
+ "Enumerate",
+ "List objects under the mouse (object mode only)");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "object", 0, "Object", "Use object selection (edit mode only)");
+ prop = RNA_def_boolean(
+ ot->srna, "object", false, "Object", "Use object selection (edit mode only)");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
/* Needed for select-through to usefully drag handles, see: T98254.
* NOTE: this option may be removed and become default behavior, see design task: T98552. */
prop = RNA_def_boolean(ot->srna,
"vert_without_handles",
- 0,
+ false,
"Control Point Without Handles",
"Only select the curve control point, not it's handles");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
@@ -3020,7 +3042,7 @@ void VIEW3D_OT_select(wmOperatorType *ot)
prop = RNA_def_int_vector(ot->srna,
"location",
2,
- NULL,
+ nullptr,
INT_MIN,
INT_MAX,
"Location",
@@ -3036,7 +3058,7 @@ void VIEW3D_OT_select(wmOperatorType *ot)
/** \name Box Select
* \{ */
-typedef struct BoxSelectUserData {
+struct BoxSelectUserData {
ViewContext *vc;
const rcti *rect;
const rctf *rect_fl;
@@ -3047,7 +3069,7 @@ typedef struct BoxSelectUserData {
/* runtime */
bool is_done;
bool is_changed;
-} BoxSelectUserData;
+};
static void view3d_userdata_boxselect_init(BoxSelectUserData *r_data,
ViewContext *vc,
@@ -3062,7 +3084,7 @@ static void view3d_userdata_boxselect_init(BoxSelectUserData *r_data,
r_data->sel_op = sel_op;
/* SELECT by default, but can be changed if needed (only few cases use and respect this). */
- r_data->select_flag = SELECT;
+ r_data->select_flag = (eBezTriple_Flag)SELECT;
/* runtime */
r_data->is_done = false;
@@ -3083,7 +3105,7 @@ static void do_paintvert_box_select__doSelectVert(void *userData,
const float screen_co[2],
int UNUSED(index))
{
- BoxSelectUserData *data = userData;
+ BoxSelectUserData *data = static_cast<BoxSelectUserData *>(userData);
const bool is_select = mv->flag & SELECT;
const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
@@ -3099,11 +3121,9 @@ static bool do_paintvert_box_select(ViewContext *vc,
{
const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
- Mesh *me;
-
- me = vc->obact->data;
- if ((me == NULL) || (me->totvert == 0)) {
- return OPERATOR_CANCELLED;
+ Mesh *me = static_cast<Mesh *>(vc->obact->data);
+ if ((me == nullptr) || (me->totvert == 0)) {
+ return false;
}
bool changed = false;
@@ -3115,14 +3135,14 @@ static bool do_paintvert_box_select(ViewContext *vc,
/* pass */
}
else if (use_zbuf) {
- struct EditSelectBuf_Cache *esel = wm_userdata->data;
- if (wm_userdata->data == NULL) {
+ EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
+ if (wm_userdata->data == nullptr) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_VERTEX);
- esel = wm_userdata->data;
+ esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
esel->select_bitmap = DRW_select_buffer_bitmap_from_rect(
- vc->depsgraph, vc->region, vc->v3d, rect, NULL);
+ vc->depsgraph, vc->region, vc->v3d, rect, nullptr);
}
- if (esel->select_bitmap != NULL) {
+ if (esel->select_bitmap != nullptr) {
changed |= edbm_backbuf_check_and_select_verts_obmode(me, esel, sel_op);
}
}
@@ -3151,13 +3171,13 @@ static bool do_paintvert_box_select(ViewContext *vc,
static bool do_paintface_box_select(ViewContext *vc,
wmGenericUserData *wm_userdata,
const rcti *rect,
- int sel_op)
+ eSelectOp sel_op)
{
Object *ob = vc->obact;
Mesh *me;
me = BKE_mesh_from_object(ob);
- if ((me == NULL) || (me->totpoly == 0)) {
+ if ((me == nullptr) || (me->totpoly == 0)) {
return false;
}
@@ -3170,20 +3190,20 @@ static bool do_paintface_box_select(ViewContext *vc,
/* pass */
}
else {
- struct EditSelectBuf_Cache *esel = wm_userdata->data;
- if (wm_userdata->data == NULL) {
+ EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
+ if (wm_userdata->data == nullptr) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_FACE);
- esel = wm_userdata->data;
+ esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
esel->select_bitmap = DRW_select_buffer_bitmap_from_rect(
- vc->depsgraph, vc->region, vc->v3d, rect, NULL);
+ vc->depsgraph, vc->region, vc->v3d, rect, nullptr);
}
- if (esel->select_bitmap != NULL) {
+ if (esel->select_bitmap != nullptr) {
changed |= edbm_backbuf_check_and_select_faces_obmode(me, esel, sel_op);
}
}
if (changed) {
- paintface_flush_flags(vc->C, vc->obact, SELECT);
+ paintface_flush_flags(vc->C, vc->obact, true, false);
}
return changed;
}
@@ -3196,7 +3216,7 @@ static void do_nurbs_box_select__doSelect(void *userData,
bool handles_visible,
const float screen_co[2])
{
- BoxSelectUserData *data = userData;
+ BoxSelectUserData *data = static_cast<BoxSelectUserData *>(userData);
const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
if (bp) {
@@ -3253,14 +3273,14 @@ static bool do_nurbs_box_select(ViewContext *vc, rcti *rect, const eSelectOp sel
data.is_changed |= BKE_nurbList_flag_set_from_flag(nurbs, BEZT_FLAG_TEMP_TAG, SELECT);
}
- BKE_curve_nurb_vert_active_validate(vc->obedit->data);
+ BKE_curve_nurb_vert_active_validate(curve);
return data.is_changed;
}
static void do_lattice_box_select__doSelect(void *userData, BPoint *bp, const float screen_co[2])
{
- BoxSelectUserData *data = userData;
+ BoxSelectUserData *data = static_cast<BoxSelectUserData *>(userData);
const bool is_select = bp->f1 & SELECT;
const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
@@ -3291,7 +3311,7 @@ static void do_mesh_box_select__doSelectVert(void *userData,
const float screen_co[2],
int UNUSED(index))
{
- BoxSelectUserData *data = userData;
+ BoxSelectUserData *data = static_cast<BoxSelectUserData *>(userData);
const bool is_select = BM_elem_flag_test(eve, BM_ELEM_SELECT);
const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
@@ -3302,7 +3322,7 @@ static void do_mesh_box_select__doSelectVert(void *userData,
}
struct BoxSelectUserData_ForMeshEdge {
BoxSelectUserData *data;
- struct EditSelectBuf_Cache *esel;
+ EditSelectBuf_Cache *esel;
uint backbuf_offset;
};
/**
@@ -3311,7 +3331,8 @@ struct BoxSelectUserData_ForMeshEdge {
static void do_mesh_box_select__doSelectEdge_pass0(
void *userData, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int index)
{
- struct BoxSelectUserData_ForMeshEdge *data_for_edge = userData;
+ BoxSelectUserData_ForMeshEdge *data_for_edge = static_cast<BoxSelectUserData_ForMeshEdge *>(
+ userData);
BoxSelectUserData *data = data_for_edge->data;
bool is_visible = true;
if (data_for_edge->backbuf_offset) {
@@ -3335,7 +3356,8 @@ static void do_mesh_box_select__doSelectEdge_pass0(
static void do_mesh_box_select__doSelectEdge_pass1(
void *userData, BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2], int index)
{
- struct BoxSelectUserData_ForMeshEdge *data_for_edge = userData;
+ BoxSelectUserData_ForMeshEdge *data_for_edge = static_cast<BoxSelectUserData_ForMeshEdge *>(
+ userData);
BoxSelectUserData *data = data_for_edge->data;
bool is_visible = true;
if (data_for_edge->backbuf_offset) {
@@ -3356,7 +3378,7 @@ static void do_mesh_box_select__doSelectFace(void *userData,
const float screen_co[2],
int UNUSED(index))
{
- BoxSelectUserData *data = userData;
+ BoxSelectUserData *data = static_cast<BoxSelectUserData *>(userData);
const bool is_select = BM_elem_flag_test(efa, BM_ELEM_SELECT);
const bool is_inside = BLI_rctf_isect_pt_v(data->rect_fl, screen_co);
const int sel_op_result = ED_select_op_action_deselected(data->sel_op, is_select, is_inside);
@@ -3389,13 +3411,13 @@ static bool do_mesh_box_select(ViewContext *vc,
const bool use_zbuf = !XRAY_FLAG_ENABLED(vc->v3d);
- struct EditSelectBuf_Cache *esel = wm_userdata->data;
+ EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
if (use_zbuf) {
- if (wm_userdata->data == NULL) {
+ if (wm_userdata->data == nullptr) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, ts->selectmode);
- esel = wm_userdata->data;
+ esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
esel->select_bitmap = DRW_select_buffer_bitmap_from_rect(
- vc->depsgraph, vc->region, vc->v3d, rect, NULL);
+ vc->depsgraph, vc->region, vc->v3d, rect, nullptr);
}
}
@@ -3411,16 +3433,16 @@ static bool do_mesh_box_select(ViewContext *vc,
}
if (ts->selectmode & SCE_SELECT_EDGE) {
/* Does both use_zbuf and non-use_zbuf versions (need screen cos for both) */
- struct BoxSelectUserData_ForMeshEdge cb_data = {
- .data = &data,
- .esel = use_zbuf ? esel : NULL,
- .backbuf_offset = use_zbuf ? DRW_select_buffer_context_offset_for_object_elem(
- vc->depsgraph, vc->obedit, SCE_SELECT_EDGE) :
- 0,
+ struct BoxSelectUserData_ForMeshEdge cb_data {
};
+ cb_data.data = &data;
+ cb_data.esel = use_zbuf ? esel : nullptr;
+ cb_data.backbuf_offset = use_zbuf ? DRW_select_buffer_context_offset_for_object_elem(
+ vc->depsgraph, vc->obedit, SCE_SELECT_EDGE) :
+ 0;
const eV3DProjTest clip_flag = V3D_PROJ_TEST_CLIP_NEAR |
- (use_zbuf ? 0 : V3D_PROJ_TEST_CLIP_BB);
+ (use_zbuf ? (eV3DProjTest)0 : V3D_PROJ_TEST_CLIP_BB);
/* Fully inside. */
mesh_foreachScreenEdge_clip_bb_segment(
vc, do_mesh_box_select__doSelectEdge_pass0, &cb_data, clip_flag);
@@ -3470,7 +3492,8 @@ static bool do_meta_box_select(ViewContext *vc, const rcti *rect, const eSelectO
}
int metaelem_id = 0;
- for (ml = mb->editelems->first; ml; ml = ml->next, metaelem_id += 0x10000) {
+ for (ml = static_cast<MetaElem *>(mb->editelems->first); ml;
+ ml = ml->next, metaelem_id += 0x10000) {
bool is_inside_radius = false;
bool is_inside_stiff = false;
@@ -3544,7 +3567,7 @@ static bool do_armature_box_select(ViewContext *vc, const rcti *rect, const eSel
Object *obedit = bases[base_index]->object;
obedit->id.tag &= ~LIB_TAG_DOIT;
- bArmature *arm = obedit->data;
+ bArmature *arm = static_cast<bArmature *>(obedit->data);
ED_armature_ebone_listbase_temp_clear(arm->edbo);
}
@@ -3568,7 +3591,8 @@ static bool do_armature_box_select(ViewContext *vc, const rcti *rect, const eSel
Object *obedit = bases[base_index]->object;
if (obedit->id.tag & LIB_TAG_DOIT) {
obedit->id.tag &= ~LIB_TAG_DOIT;
- changed |= ED_armature_edit_select_op_from_tagged(obedit->data, sel_op);
+ changed |= ED_armature_edit_select_op_from_tagged(static_cast<bArmature *>(obedit->data),
+ sel_op);
}
}
@@ -3606,8 +3630,8 @@ static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const
int totobj = MAXPICKELEMS; /* XXX solve later */
/* Selection buffer has bones potentially too, so we add #MAXPICKELEMS. */
- GPUSelectResult *buffer = MEM_mallocN((totobj + MAXPICKELEMS) * sizeof(GPUSelectResult),
- "selection buffer");
+ GPUSelectResult *buffer = static_cast<GPUSelectResult *>(
+ MEM_mallocN((totobj + MAXPICKELEMS) * sizeof(GPUSelectResult), __func__));
const eV3DSelectObjectFilter select_filter = ED_view3d_select_filter_from_mode(vc->scene,
vc->obact);
const int hits = view3d_opengl_select(
@@ -3617,8 +3641,7 @@ static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const
base->object->id.tag &= ~LIB_TAG_DOIT;
}
- Base **bases = NULL;
- BLI_array_declare(bases);
+ blender::Vector<Base *> bases;
bool changed = false;
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
@@ -3632,7 +3655,7 @@ static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const
LISTBASE_FOREACH (Base *, base, &vc->view_layer->object_bases) {
if (BASE_SELECTABLE(v3d, base)) {
if ((base->object->runtime.select_id & 0x0000FFFF) != 0) {
- BLI_array_append(bases, base);
+ bases.append(base);
}
}
}
@@ -3644,13 +3667,14 @@ static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const
buf_iter++) {
bPoseChannel *pchan_dummy;
Base *base = ED_armature_base_and_pchan_from_select_buffer(
- bases, BLI_array_len(bases), buf_iter->id, &pchan_dummy);
- if (base != NULL) {
+ bases.data(), bases.size(), buf_iter->id, &pchan_dummy);
+ if (base != nullptr) {
base->object->id.tag |= LIB_TAG_DOIT;
}
}
- for (Base *base = vc->view_layer->object_bases.first; base && hits; base = base->next) {
+ for (Base *base = static_cast<Base *>(vc->view_layer->object_bases.first); base && hits;
+ base = base->next) {
if (BASE_SELECTABLE(v3d, base)) {
const bool is_select = base->flag & BASE_SELECTED;
const bool is_inside = base->object->id.tag & LIB_TAG_DOIT;
@@ -3663,9 +3687,6 @@ static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const
}
finally:
- if (bases != NULL) {
- MEM_freeN(bases);
- }
MEM_freeN(buffer);
@@ -3678,14 +3699,13 @@ finally:
static bool do_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, const eSelectOp sel_op)
{
- uint bases_len;
- Base **bases = do_pose_tag_select_op_prepare(vc, &bases_len);
+ blender::Vector<Base *> bases = do_pose_tag_select_op_prepare(vc);
int totobj = MAXPICKELEMS; /* XXX solve later */
/* Selection buffer has bones potentially too, so add #MAXPICKELEMS. */
- GPUSelectResult *buffer = MEM_mallocN((totobj + MAXPICKELEMS) * sizeof(GPUSelectResult),
- "selection buffer");
+ GPUSelectResult *buffer = static_cast<GPUSelectResult *>(
+ MEM_mallocN((totobj + MAXPICKELEMS) * sizeof(GPUSelectResult), __func__));
const eV3DSelectObjectFilter select_filter = ED_view3d_select_filter_from_mode(vc->scene,
vc->obact);
const int hits = view3d_opengl_select(
@@ -3709,16 +3729,16 @@ static bool do_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, const e
buf_iter++) {
Bone *bone;
Base *base = ED_armature_base_and_bone_from_select_buffer(
- bases, bases_len, buf_iter->id, &bone);
+ bases.data(), bases.size(), buf_iter->id, &bone);
- if (base == NULL) {
+ if (base == nullptr) {
continue;
}
/* Loop over contiguous bone hits for 'base'. */
for (; buf_iter != buf_end; buf_iter++) {
/* should never fail */
- if (bone != NULL) {
+ if (bone != nullptr) {
base->object->id.tag |= LIB_TAG_DOIT;
bone->flag |= BONE_DONE;
}
@@ -3729,28 +3749,26 @@ static bool do_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, const e
if ((base->object->runtime.select_id & 0x0000FFFF) != (col_next->id & 0x0000FFFF)) {
break;
}
- if (base->object->pose != NULL) {
+ if (base->object->pose != nullptr) {
const uint hit_bone = (col_next->id & ~BONESEL_ANY) >> 16;
- bPoseChannel *pchan = BLI_findlink(&base->object->pose->chanbase, hit_bone);
- bone = pchan ? pchan->bone : NULL;
+ bPoseChannel *pchan = static_cast<bPoseChannel *>(
+ BLI_findlink(&base->object->pose->chanbase, hit_bone));
+ bone = pchan ? pchan->bone : nullptr;
}
else {
- bone = NULL;
+ bone = nullptr;
}
}
}
}
}
- const bool changed_multi = do_pose_tag_select_op_exec(bases, bases_len, sel_op);
+ const bool changed_multi = do_pose_tag_select_op_exec(bases, sel_op);
if (changed_multi) {
DEG_id_tag_update(&vc->scene->id, ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, vc->scene);
}
- if (bases != NULL) {
- MEM_freeN(bases);
- }
MEM_freeN(buffer);
return changed_multi;
@@ -3763,7 +3781,7 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op)
rcti rect;
bool changed_multi = false;
- wmGenericUserData wm_userdata_buf = {0};
+ wmGenericUserData wm_userdata_buf = {nullptr, nullptr, false};
wmGenericUserData *wm_userdata = &wm_userdata_buf;
view3d_operator_needs_opengl(C);
@@ -3772,7 +3790,7 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op)
/* setup view context for argument to callbacks */
ED_view3d_viewcontext_init(C, &vc, depsgraph);
- eSelectOp sel_op = RNA_enum_get(op->ptr, "mode");
+ eSelectOp sel_op = static_cast<eSelectOp>(RNA_enum_get(op->ptr, "mode"));
WM_operator_properties_border_to_rcti(op, &rect);
if (vc.obedit) {
@@ -3786,7 +3804,7 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op)
vc.em = BKE_editmesh_from_object(vc.obedit);
changed = do_mesh_box_select(&vc, wm_userdata, &rect, sel_op);
if (changed) {
- DEG_id_tag_update(vc.obedit->data, ID_RECALC_SELECT);
+ DEG_id_tag_update(static_cast<ID *>(vc.obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
}
break;
@@ -3794,14 +3812,14 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op)
case OB_SURF:
changed = do_nurbs_box_select(&vc, &rect, sel_op);
if (changed) {
- DEG_id_tag_update(vc.obedit->data, ID_RECALC_SELECT);
+ DEG_id_tag_update(static_cast<ID *>(vc.obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
}
break;
case OB_MBALL:
changed = do_meta_box_select(&vc, &rect, sel_op);
if (changed) {
- DEG_id_tag_update(vc.obedit->data, ID_RECALC_SELECT);
+ DEG_id_tag_update(static_cast<ID *>(vc.obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
}
break;
@@ -3816,7 +3834,7 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op)
case OB_LATTICE:
changed = do_lattice_box_select(&vc, &rect, sel_op);
if (changed) {
- DEG_id_tag_update(vc.obedit->data, ID_RECALC_SELECT);
+ DEG_id_tag_update(static_cast<ID *>(vc.obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
}
break;
@@ -3888,7 +3906,7 @@ void VIEW3D_OT_select_box(wmOperatorType *ot)
/** \name Circle Select
* \{ */
-typedef struct CircleSelectUserData {
+struct CircleSelectUserData {
ViewContext *vc;
bool select;
int mval[2];
@@ -3899,7 +3917,7 @@ typedef struct CircleSelectUserData {
/* runtime */
bool is_changed;
-} CircleSelectUserData;
+};
static void view3d_userdata_circleselect_init(CircleSelectUserData *r_data,
ViewContext *vc,
@@ -3917,7 +3935,7 @@ static void view3d_userdata_circleselect_init(CircleSelectUserData *r_data,
r_data->radius_squared = rad * rad;
/* SELECT by default, but can be changed if needed (only few cases use and respect this). */
- r_data->select_flag = SELECT;
+ r_data->select_flag = (eBezTriple_Flag)SELECT;
/* runtime */
r_data->is_changed = false;
@@ -3928,7 +3946,7 @@ static void mesh_circle_doSelectVert(void *userData,
const float screen_co[2],
int UNUSED(index))
{
- CircleSelectUserData *data = userData;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
BM_vert_select_set(data->vc->em->bm, eve, data->select);
@@ -3941,7 +3959,7 @@ static void mesh_circle_doSelectEdge(void *userData,
const float screen_co_b[2],
int UNUSED(index))
{
- CircleSelectUserData *data = userData;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
if (edge_inside_circle(data->mval_fl, data->radius, screen_co_a, screen_co_b)) {
BM_edge_select_set(data->vc->em->bm, eed, data->select);
@@ -3953,7 +3971,7 @@ static void mesh_circle_doSelectFace(void *userData,
const float screen_co[2],
int UNUSED(index))
{
- CircleSelectUserData *data = userData;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
BM_face_select_set(data->vc->em->bm, efa, data->select);
@@ -3990,22 +4008,22 @@ static bool mesh_circle_select(ViewContext *vc,
const bool use_zbuf = !XRAY_FLAG_ENABLED(vc->v3d);
if (use_zbuf) {
- if (wm_userdata->data == NULL) {
+ if (wm_userdata->data == nullptr) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, ts->selectmode);
}
}
- struct EditSelectBuf_Cache *esel = wm_userdata->data;
+ EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
if (use_zbuf) {
- if (esel->select_bitmap == NULL) {
+ if (esel->select_bitmap == nullptr) {
esel->select_bitmap = DRW_select_buffer_bitmap_from_circle(
- vc->depsgraph, vc->region, vc->v3d, mval, (int)(rad + 1.0f), NULL);
+ vc->depsgraph, vc->region, vc->v3d, mval, (int)(rad + 1.0f), nullptr);
}
}
if (ts->selectmode & SCE_SELECT_VERTEX) {
if (use_zbuf) {
- if (esel->select_bitmap != NULL) {
+ if (esel->select_bitmap != nullptr) {
changed |= edbm_backbuf_check_and_select_verts(
esel, vc->depsgraph, vc->obedit, vc->em, select ? SEL_OP_ADD : SEL_OP_SUB);
}
@@ -4017,7 +4035,7 @@ static bool mesh_circle_select(ViewContext *vc,
if (ts->selectmode & SCE_SELECT_EDGE) {
if (use_zbuf) {
- if (esel->select_bitmap != NULL) {
+ if (esel->select_bitmap != nullptr) {
changed |= edbm_backbuf_check_and_select_edges(
esel, vc->depsgraph, vc->obedit, vc->em, select ? SEL_OP_ADD : SEL_OP_SUB);
}
@@ -4033,7 +4051,7 @@ static bool mesh_circle_select(ViewContext *vc,
if (ts->selectmode & SCE_SELECT_FACE) {
if (use_zbuf) {
- if (esel->select_bitmap != NULL) {
+ if (esel->select_bitmap != nullptr) {
changed |= edbm_backbuf_check_and_select_faces(
esel, vc->depsgraph, vc->obedit, vc->em, select ? SEL_OP_ADD : SEL_OP_SUB);
}
@@ -4060,7 +4078,7 @@ static bool paint_facesel_circle_select(ViewContext *vc,
{
BLI_assert(ELEM(sel_op, SEL_OP_SET, SEL_OP_ADD, SEL_OP_SUB));
Object *ob = vc->obact;
- Mesh *me = ob->data;
+ Mesh *me = static_cast<Mesh *>(ob->data);
bool changed = false;
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
@@ -4068,23 +4086,23 @@ static bool paint_facesel_circle_select(ViewContext *vc,
changed |= paintface_deselect_all_visible(vc->C, ob, SEL_DESELECT, false);
}
- if (wm_userdata->data == NULL) {
+ if (wm_userdata->data == nullptr) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_FACE);
}
{
- struct EditSelectBuf_Cache *esel = wm_userdata->data;
+ EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
esel->select_bitmap = DRW_select_buffer_bitmap_from_circle(
- vc->depsgraph, vc->region, vc->v3d, mval, (int)(rad + 1.0f), NULL);
- if (esel->select_bitmap != NULL) {
+ vc->depsgraph, vc->region, vc->v3d, mval, (int)(rad + 1.0f), nullptr);
+ if (esel->select_bitmap != nullptr) {
changed |= edbm_backbuf_check_and_select_faces_obmode(me, esel, sel_op);
MEM_freeN(esel->select_bitmap);
- esel->select_bitmap = NULL;
+ esel->select_bitmap = nullptr;
}
}
if (changed) {
- paintface_flush_flags(vc->C, ob, SELECT);
+ paintface_flush_flags(vc->C, ob, true, false);
}
return changed;
}
@@ -4094,7 +4112,7 @@ static void paint_vertsel_circle_select_doSelectVert(void *userData,
const float screen_co[2],
int UNUSED(index))
{
- CircleSelectUserData *data = userData;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
SET_FLAG_FROM_TEST(mv->flag, data->select, SELECT);
@@ -4110,8 +4128,8 @@ static bool paint_vertsel_circle_select(ViewContext *vc,
BLI_assert(ELEM(sel_op, SEL_OP_SET, SEL_OP_ADD, SEL_OP_SUB));
const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
Object *ob = vc->obact;
- Mesh *me = ob->data;
- /* CircleSelectUserData data = {NULL}; */ /* UNUSED */
+ Mesh *me = static_cast<Mesh *>(ob->data);
+ /* CircleSelectUserData data = {nullptr}; */ /* UNUSED */
bool changed = false;
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
@@ -4122,19 +4140,19 @@ static bool paint_vertsel_circle_select(ViewContext *vc,
const bool select = (sel_op != SEL_OP_SUB);
if (use_zbuf) {
- if (wm_userdata->data == NULL) {
+ if (wm_userdata->data == nullptr) {
editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc, SCE_SELECT_VERTEX);
}
}
if (use_zbuf) {
- struct EditSelectBuf_Cache *esel = wm_userdata->data;
+ EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
esel->select_bitmap = DRW_select_buffer_bitmap_from_circle(
- vc->depsgraph, vc->region, vc->v3d, mval, (int)(rad + 1.0f), NULL);
- if (esel->select_bitmap != NULL) {
+ vc->depsgraph, vc->region, vc->v3d, mval, (int)(rad + 1.0f), nullptr);
+ if (esel->select_bitmap != nullptr) {
changed |= edbm_backbuf_check_and_select_verts_obmode(me, esel, sel_op);
MEM_freeN(esel->select_bitmap);
- esel->select_bitmap = NULL;
+ esel->select_bitmap = nullptr;
}
}
else {
@@ -4166,7 +4184,7 @@ static void nurbscurve_circle_doSelect(void *userData,
bool UNUSED(handles_visible),
const float screen_co[2])
{
- CircleSelectUserData *data = userData;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
if (bp) {
@@ -4214,14 +4232,14 @@ static bool nurbscurve_circle_select(ViewContext *vc,
data.is_changed |= BKE_nurbList_flag_set_from_flag(nurbs, BEZT_FLAG_TEMP_TAG, SELECT);
}
- BKE_curve_nurb_vert_active_validate(vc->obedit->data);
+ BKE_curve_nurb_vert_active_validate(static_cast<Curve *>(vc->obedit->data));
return data.is_changed;
}
static void latticecurve_circle_doSelect(void *userData, BPoint *bp, const float screen_co[2])
{
- CircleSelectUserData *data = userData;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
bp->f1 = data->select ? (bp->f1 | SELECT) : (bp->f1 & ~SELECT);
@@ -4255,7 +4273,7 @@ static bool pchan_circle_doSelectJoint(void *userData,
bPoseChannel *pchan,
const float screen_co[2])
{
- CircleSelectUserData *data = userData;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
if (data->select) {
@@ -4264,17 +4282,17 @@ static bool pchan_circle_doSelectJoint(void *userData,
else {
pchan->bone->flag &= ~BONE_SELECTED;
}
- return 1;
+ return true;
}
- return 0;
+ return false;
}
static void do_circle_select_pose__doSelectBone(void *userData,
- struct bPoseChannel *pchan,
+ bPoseChannel *pchan,
const float screen_co_a[2],
const float screen_co_b[2])
{
- CircleSelectUserData *data = userData;
- bArmature *arm = data->vc->obact->data;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
+ bArmature *arm = static_cast<bArmature *>(data->vc->obact->data);
if (!PBONE_SELECTABLE(arm, pchan->bone)) {
return;
}
@@ -4355,7 +4373,7 @@ static bool armature_circle_doSelectJoint(void *userData,
const float screen_co[2],
bool head)
{
- CircleSelectUserData *data = userData;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
if (head) {
@@ -4374,17 +4392,17 @@ static bool armature_circle_doSelectJoint(void *userData,
ebone->flag &= ~BONE_TIPSEL;
}
}
- return 1;
+ return true;
}
- return 0;
+ return false;
}
static void do_circle_select_armature__doSelectBone(void *userData,
- struct EditBone *ebone,
+ EditBone *ebone,
const float screen_co_a[2],
const float screen_co_b[2])
{
- CircleSelectUserData *data = userData;
- const bArmature *arm = data->vc->obedit->data;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
+ const bArmature *arm = static_cast<const bArmature *>(data->vc->obedit->data);
if (!(data->select ? EBONE_SELECTABLE(arm, ebone) : EBONE_VISIBLE(arm, ebone))) {
return;
}
@@ -4433,19 +4451,19 @@ static void do_circle_select_armature__doSelectBone(void *userData,
data->is_changed |= is_point_done;
}
static void do_circle_select_armature__doSelectBone_clip_content(void *userData,
- struct EditBone *ebone,
+ EditBone *ebone,
const float screen_co_a[2],
const float screen_co_b[2])
{
- CircleSelectUserData *data = userData;
- bArmature *arm = data->vc->obedit->data;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
+ bArmature *arm = static_cast<bArmature *>(data->vc->obedit->data);
if (!(data->select ? EBONE_SELECTABLE(arm, ebone) : EBONE_VISIBLE(arm, ebone))) {
return;
}
/* Set in the first pass, needed so circle select prioritizes joints. */
- if (ebone->temp.i == true) {
+ if (ebone->temp.i != 0) {
return;
}
@@ -4460,7 +4478,7 @@ static bool armature_circle_select(ViewContext *vc,
float rad)
{
CircleSelectUserData data;
- bArmature *arm = vc->obedit->data;
+ bArmature *arm = static_cast<bArmature *>(vc->obedit->data);
const bool select = (sel_op != SEL_OP_SUB);
@@ -4493,10 +4511,10 @@ static bool armature_circle_select(ViewContext *vc,
}
static void do_circle_select_mball__doSelectElem(void *userData,
- struct MetaElem *ml,
+ MetaElem *ml,
const float screen_co[2])
{
- CircleSelectUserData *data = userData;
+ CircleSelectUserData *data = static_cast<CircleSelectUserData *>(userData);
if (len_squared_v2v2(data->mval_fl, screen_co) <= data->radius_squared) {
if (data->select) {
@@ -4520,7 +4538,7 @@ static bool mball_circle_select(ViewContext *vc,
view3d_userdata_circleselect_init(&data, vc, select, mval, rad);
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
- data.is_changed |= BKE_mball_deselect_all(vc->obedit->data);
+ data.is_changed |= BKE_mball_deselect_all(static_cast<MetaBall *>(vc->obedit->data));
}
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
@@ -4568,7 +4586,7 @@ static bool obedit_circle_select(bContext *C,
}
if (changed) {
- DEG_id_tag_update(vc->obact->data, ID_RECALC_SELECT);
+ DEG_id_tag_update(static_cast<ID *>(vc->obact->data), ID_RECALC_SELECT);
WM_main_add_notifier(NC_GEOM | ND_SELECT, vc->obact->data);
}
return changed;
@@ -4584,7 +4602,7 @@ static bool object_circle_select(ViewContext *vc,
View3D *v3d = vc->v3d;
const float radius_squared = rad * rad;
- const float mval_fl[2] = {mval[0], mval[1]};
+ const float mval_fl[2] = {static_cast<float>(mval[0]), static_cast<float>(mval[1])};
bool changed = false;
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
@@ -4593,8 +4611,7 @@ static bool object_circle_select(ViewContext *vc,
const bool select = (sel_op != SEL_OP_SUB);
const int select_flag = select ? BASE_SELECTED : 0;
- Base *base;
- for (base = FIRSTBASE(view_layer); base; base = base->next) {
+ LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
if (BASE_SELECTABLE(v3d, base) && ((base->flag & BASE_SELECTED) != select_flag)) {
float screen_co[2];
if (ED_view3d_project_float_global(
@@ -4614,7 +4631,7 @@ static bool object_circle_select(ViewContext *vc,
/* not a real operator, only for circle test */
static void view3d_circle_select_recalc(void *user_data)
{
- bContext *C = user_data;
+ bContext *C = static_cast<bContext *>(user_data);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc;
ED_view3d_viewcontext_init(C, &vc, depsgraph);
@@ -4662,12 +4679,12 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
const int mval[2] = {RNA_int_get(op->ptr, "x"), RNA_int_get(op->ptr, "y")};
/* Allow each selection type to allocate their own data that's used between executions. */
- wmGesture *gesture = op->customdata; /* NULL when non-modal. */
- wmGenericUserData wm_userdata_buf = {0};
+ wmGesture *gesture = static_cast<wmGesture *>(op->customdata); /* nullptr when non-modal. */
+ wmGenericUserData wm_userdata_buf = {nullptr, nullptr, false};
wmGenericUserData *wm_userdata = gesture ? &gesture->user_data : &wm_userdata_buf;
- const eSelectOp sel_op = ED_select_op_modal(RNA_enum_get(op->ptr, "mode"),
- WM_gesture_is_modal_first(gesture));
+ const eSelectOp sel_op = ED_select_op_modal(
+ static_cast<eSelectOp>(RNA_enum_get(op->ptr, "mode")), WM_gesture_is_modal_first(gesture));
ED_view3d_viewcontext_init(C, &vc, depsgraph);
@@ -4676,7 +4693,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
if (obedit || BKE_paint_select_elem_test(obact) || (obact && (obact->mode & OB_MODE_POSE))) {
view3d_operator_needs_opengl(C);
- if (obedit == NULL) {
+ if (obedit == nullptr) {
BKE_object_update_select_id(CTX_data_main(C));
}
@@ -4728,10 +4745,10 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
WM_generic_user_data_free(wm_userdata);
}
else {
- struct EditSelectBuf_Cache *esel = wm_userdata->data;
+ EditSelectBuf_Cache *esel = static_cast<EditSelectBuf_Cache *>(wm_userdata->data);
if (esel && esel->select_bitmap) {
MEM_freeN(esel->select_bitmap);
- esel->select_bitmap = NULL;
+ esel->select_bitmap = nullptr;
}
}
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index 306394ce53d..cb716391fb2 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -44,6 +44,7 @@
#include "ED_keyframing.h"
#include "ED_screen.h"
+#include "ED_undo.h"
#include "ED_view3d.h"
#include "UI_resources.h"
@@ -633,7 +634,7 @@ bool ED_view3d_camera_autokey(const Scene *scene,
const bool do_translate)
{
if (autokeyframe_cfra_can_key(scene, id_key)) {
- const float cfra = (float)CFRA;
+ const float cfra = (float)scene->r.cfra;
ListBase dsources = {NULL, NULL};
/* add data-source override for the camera object */
@@ -688,6 +689,60 @@ bool ED_view3d_camera_lock_autokey(View3D *v3d,
return false;
}
+bool ED_view3d_camera_lock_undo_test(const View3D *v3d,
+ const RegionView3D *rv3d,
+ struct bContext *C)
+{
+ if (ED_view3d_camera_lock_check(v3d, rv3d)) {
+ if (ED_undo_is_memfile_compatible(C)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * Create a MEMFILE undo-step for locked camera movement when transforming the view.
+ * Edit and texture paint mode don't use MEMFILE undo so undo push is skipped for them.
+ * NDOF and track-pad navigation would create an undo step on every gesture and we may end up with
+ * unnecessary undo steps so undo push for them is not supported for now.
+ * Operators that use smooth view for navigation are supported via an optional parameter field,
+ * see: #V3D_SmoothParams.undo_str.
+ */
+static bool view3d_camera_lock_undo_ex(const char *str,
+ const View3D *v3d,
+ const RegionView3D *rv3d,
+ struct bContext *C,
+ const bool undo_group)
+{
+ if (ED_view3d_camera_lock_undo_test(v3d, rv3d, C)) {
+ if (undo_group) {
+ ED_undo_grouped_push(C, str);
+ }
+ else {
+ ED_undo_push(C, str);
+ }
+ return true;
+ }
+ return false;
+}
+
+bool ED_view3d_camera_lock_undo_push(const char *str,
+ const View3D *v3d,
+ const RegionView3D *rv3d,
+ bContext *C)
+{
+ return view3d_camera_lock_undo_ex(str, v3d, rv3d, C, false);
+}
+
+bool ED_view3d_camera_lock_undo_grouped_push(const char *str,
+ const View3D *v3d,
+ const RegionView3D *rv3d,
+ bContext *C)
+{
+ return view3d_camera_lock_undo_ex(str, v3d, rv3d, C, true);
+}
+
/** \} */
/* -------------------------------------------------------------------- */
@@ -1492,10 +1547,12 @@ static bool view3d_camera_to_view_selected_impl(struct Main *bmain,
depsgraph, scene, camera_ob_eval, co, &scale, r_clip_start, r_clip_end)) {
ObjectTfmProtectedChannels obtfm;
float obmat_new[4][4];
+ bool is_ortho_camera = false;
if ((camera_ob_eval->type == OB_CAMERA) &&
(((Camera *)camera_ob_eval->data)->type == CAM_ORTHO)) {
((Camera *)camera_ob->data)->ortho_scale = scale;
+ is_ortho_camera = true;
}
copy_m4_m4(obmat_new, camera_ob_eval->obmat);
@@ -1508,6 +1565,9 @@ static bool view3d_camera_to_view_selected_impl(struct Main *bmain,
/* notifiers */
DEG_id_tag_update_ex(bmain, &camera_ob->id, ID_RECALC_TRANSFORM);
+ if (is_ortho_camera) {
+ DEG_id_tag_update_ex(bmain, camera_ob->data, ID_RECALC_PARAMETERS);
+ }
return true;
}
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index fc88737ca70..124527822a5 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -202,6 +202,8 @@ static void sync_viewport_camera_smoothview(bContext *C,
.quat = other_rv3d->viewquat,
.dist = &other_rv3d->dist,
.lens = &other_v3d->lens,
+ /* No undo because this switches cameras. */
+ .undo_str = NULL,
});
}
else {
@@ -256,6 +258,8 @@ static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op)
.quat = rv3d->viewquat,
.dist = &rv3d->dist,
.lens = &v3d->lens,
+ /* No undo because this switches cameras. */
+ .undo_str = NULL,
});
}
@@ -549,7 +553,7 @@ int view3d_opengl_select_ex(ViewContext *vc,
ARegion *region = vc->region;
rcti rect;
int hits = 0;
- const bool use_obedit_skip = (OBEDIT_FROM_VIEW_LAYER(vc->view_layer) != NULL) &&
+ const bool use_obedit_skip = (BKE_view_layer_edit_object_get(vc->view_layer) != NULL) &&
(vc->obedit == NULL);
const bool is_pick_select = (U.gpu_flag & USER_GPU_FLAG_NO_DEPT_PICK) == 0;
const bool do_passes = ((is_pick_select == false) &&
@@ -597,7 +601,7 @@ int view3d_opengl_select_ex(ViewContext *vc,
goto finally;
}
- /* Important to use 'vc->obact', not 'OBACT(vc->view_layer)' below,
+ /* Important to use 'vc->obact', not 'BKE_view_layer_active_object_get(vc->view_layer)' below,
* so it will be NULL when hidden. */
struct {
DRW_ObjectFilterFn fn;
@@ -827,7 +831,6 @@ static bool view3d_localview_init(const Depsgraph *depsgraph,
ReportList *reports)
{
View3D *v3d = area->spacedata.first;
- Base *base;
float min[3], max[3], box[3];
float size = 0.0f;
uint local_view_bit;
@@ -848,9 +851,9 @@ static bool view3d_localview_init(const Depsgraph *depsgraph,
ok = false;
}
else {
- Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
+ Object *obedit = BKE_view_layer_edit_object_get(view_layer);
if (obedit) {
- for (base = FIRSTBASE(view_layer); base; base = base->next) {
+ LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
base->local_view_bits &= ~local_view_bit;
}
FOREACH_BASE_IN_EDIT_MODE_BEGIN (view_layer, v3d, base_iter) {
@@ -861,7 +864,7 @@ static bool view3d_localview_init(const Depsgraph *depsgraph,
FOREACH_BASE_IN_EDIT_MODE_END;
}
else {
- for (base = FIRSTBASE(view_layer); base; base = base->next) {
+ LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
if (BASE_SELECTED(v3d, base)) {
BKE_object_minmax(base->object, min, max, false);
base->local_view_bits |= local_view_bit;
@@ -939,6 +942,8 @@ static bool view3d_localview_init(const Depsgraph *depsgraph,
.quat = rv3d->viewquat,
.dist = ok_dist ? &dist_new : NULL,
.lens = &v3d->lens,
+ /* No undo because this doesn't move the camera. */
+ .undo_str = NULL,
});
}
}
@@ -961,7 +966,7 @@ static void view3d_localview_exit(const Depsgraph *depsgraph,
return;
}
- for (Base *base = FIRSTBASE(view_layer); base; base = base->next) {
+ LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
if (base->local_view_bits & v3d->local_view_uuid) {
base->local_view_bits &= ~v3d->local_view_uuid;
}
@@ -1008,6 +1013,8 @@ static void view3d_localview_exit(const Depsgraph *depsgraph,
.ofs = rv3d->localvd->ofs,
.quat = rv3d->localvd->viewquat,
.dist = &rv3d->localvd->dist,
+ /* No undo because this doesn't move the camera. */
+ .undo_str = NULL,
});
}
@@ -1086,12 +1093,12 @@ static int localview_remove_from_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
bool changed = false;
- for (Base *base = FIRSTBASE(view_layer); base; base = base->next) {
+ LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
if (BASE_SELECTED(v3d, base)) {
base->local_view_bits &= ~v3d->local_view_uuid;
ED_object_base_select(base, BA_DESELECT);
- if (base == BASACT(view_layer)) {
+ if (base == view_layer->basact) {
view_layer->basact = NULL;
}
changed = true;