diff options
Diffstat (limited to 'source/blender/editors/space_view3d')
17 files changed, 436 insertions, 355 deletions
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 5959052b0ab..f17d7ccd136 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -126,7 +126,7 @@ void ED_draw_object_facemap(Depsgraph *depsgraph, } } - glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW); + GPU_front_facing(ob->transflag & OB_NEG_SCALE); /* Just to create the data to pass to immediate mode, grr! */ const int *facemap_data = CustomData_get_layer(&me->pdata, CD_FACEMAP); diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 4fc98789c18..e5ba27cef07 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -120,11 +120,10 @@ bool ED_view3d_context_user_region(bContext *C, View3D **r_v3d, ARegion **r_regi *r_region = region; return true; } - else { - if (ED_view3d_area_user_region(area, v3d, r_region)) { - *r_v3d = v3d; - return true; - } + + if (ED_view3d_area_user_region(area, v3d, r_region)) { + *r_v3d = v3d; + return true; } } } @@ -261,7 +260,7 @@ void ED_view3d_shade_update(Main *bmain, View3D *v3d, ScrArea *area) /* ******************** default callbacks for view3d space ***************** */ -static SpaceLink *view3d_new(const ScrArea *UNUSED(area), const Scene *scene) +static SpaceLink *view3d_create(const ScrArea *UNUSED(area), const Scene *scene) { ARegion *region; View3D *v3d; @@ -508,9 +507,8 @@ static bool view3d_ima_drop_poll(bContext *C, /* rule might not work? */ return (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE)); } - else { - return WM_drag_ID(drag, ID_IM) != NULL; - } + + return WM_drag_ID(drag, ID_IM) != NULL; } static bool view3d_ima_bg_is_camera_view(bContext *C) @@ -618,11 +616,12 @@ static void view3d_lightcache_update(bContext *C) return; } - WM_operator_properties_create(&op_ptr, "SCENE_OT_light_cache_bake"); + wmOperatorType *ot = WM_operatortype_find("SCENE_OT_light_cache_bake", true); + WM_operator_properties_create_ptr(&op_ptr, ot); RNA_int_set(&op_ptr, "delay", 200); RNA_enum_set_identifier(C, &op_ptr, "subset", "DIRTY"); - WM_operator_name_call(C, "SCENE_OT_light_cache_bake", WM_OP_INVOKE_DEFAULT, &op_ptr); + WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &op_ptr); WM_operator_properties_free(&op_ptr); } @@ -827,6 +826,7 @@ static void view3d_main_region_listener( case ND_POSE: case ND_DRAW: case ND_MODIFIER: + case ND_SHADERFX: case ND_CONSTRAINT: case ND_KEYS: case ND_PARTICLE: @@ -1383,6 +1383,7 @@ static void view3d_buttons_region_listener(wmWindow *UNUSED(win), case ND_DRAW: case ND_KEYS: case ND_MODIFIER: + case ND_SHADERFX: ED_region_tag_redraw(region); break; } @@ -1610,7 +1611,7 @@ void ED_spacetype_view3d(void) st->spaceid = SPACE_VIEW3D; strncpy(st->name, "View3D", BKE_ST_MAXNAME); - st->new = view3d_new; + st->create = view3d_create; st->free = view3d_free; st->init = view3d_init; st->listener = space_view3d_listener; diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c index cb87ddafea1..d78c58c0c64 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.c +++ b/source/blender/editors/space_view3d/view3d_buttons.c @@ -126,27 +126,25 @@ static float compute_scale_factor(const float ve_median, const float median) if (ve_median <= 0.0f) { return 0.0f; } - else if (ve_median >= 1.0f) { + if (ve_median >= 1.0f) { return 1.0f; } - else { - /* Scale value to target median. */ - float median_new = ve_median; - float median_orig = ve_median - median; /* Previous median value. */ - /* In case of floating point error. */ - CLAMP(median_orig, 0.0f, 1.0f); - CLAMP(median_new, 0.0f, 1.0f); + /* Scale value to target median. */ + float median_new = ve_median; + float median_orig = ve_median - median; /* Previous median value. */ - if (median_new <= median_orig) { - /* Scale down. */ - return median_new / median_orig; - } - else { - /* Scale up, negative to indicate it... */ - return -(1.0f - median_new) / (1.0f - median_orig); - } + /* In case of floating point error. */ + CLAMP(median_orig, 0.0f, 1.0f); + CLAMP(median_new, 0.0f, 1.0f); + + if (median_new <= median_orig) { + /* Scale down. */ + return median_new / median_orig; } + + /* Scale up, negative to indicate it... */ + return -(1.0f - median_new) / (1.0f - median_orig); } /** @@ -1117,13 +1115,12 @@ static void do_view3d_vgroup_buttons(bContext *C, void *UNUSED(arg), int event) /* not for me */ return; } - else { - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = view_layer->basact->object; - ED_vgroup_vert_active_mirror(ob, event - B_VGRP_PNL_EDIT_SINGLE); - DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); - WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); - } + + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = view_layer->basact->object; + ED_vgroup_vert_active_mirror(ob, event - B_VGRP_PNL_EDIT_SINGLE); + DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data); } static bool view3d_panel_vgroup_poll(const bContext *C, PanelType *UNUSED(pt)) @@ -1477,6 +1474,7 @@ static void v3d_editmetaball_buts(uiLayout *layout, Object *ob) uiLayout *col; if (!mball || !(mball->lastelem)) { + uiItemL(layout, IFACE_("Nothing selected"), ICON_NONE); return; } @@ -1641,14 +1639,13 @@ static int view3d_object_mode_menu(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_WARNING, "No active object found"); return OPERATOR_CANCELLED; } - else if (((ob->mode & OB_MODE_EDIT) == 0) && (ELEM(ob->type, OB_ARMATURE))) { + if (((ob->mode & OB_MODE_EDIT) == 0) && (ELEM(ob->type, OB_ARMATURE))) { ED_object_mode_set(C, (ob->mode == OB_MODE_OBJECT) ? OB_MODE_POSE : OB_MODE_OBJECT); return OPERATOR_CANCELLED; } - else { - UI_pie_menu_invoke(C, "VIEW3D_MT_object_mode_pie", CTX_wm_window(C)->eventstate); - return OPERATOR_CANCELLED; - } + + UI_pie_menu_invoke(C, "VIEW3D_MT_object_mode_pie", CTX_wm_window(C)->eventstate); + return OPERATOR_CANCELLED; } void VIEW3D_OT_object_mode_pie_or_toggle(wmOperatorType *ot) diff --git a/source/blender/editors/space_view3d/view3d_camera_control.c b/source/blender/editors/space_view3d/view3d_camera_control.c index aeabe68c2d0..1d5b33e7b90 100644 --- a/source/blender/editors/space_view3d/view3d_camera_control.c +++ b/source/blender/editors/space_view3d/view3d_camera_control.c @@ -116,9 +116,8 @@ Object *ED_view3d_cameracontrol_object_get(View3DCameraControl *vctrl) if (rv3d->persp == RV3D_CAMOB) { return view3d_cameracontrol_object(vctrl); } - else { - return NULL; - } + + return NULL; } /** @@ -199,6 +198,56 @@ struct View3DCameraControl *ED_view3d_cameracontrol_acquire(Depsgraph *depsgraph } /** + * A version of #BKE_object_apply_mat4 that respects #Object.protectflag, + * applying the locking back to the view to avoid the view. + * This is needed so the view doesn't get out of sync with the object, + * causing visible jittering when in fly/walk mode for e.g. + * + * \note This could be exposed as an API option, as we might not want the view + * to be constrained by the thing it's controlling. + */ +static bool object_apply_mat4_with_protect(Object *ob, + const float obmat[4][4], + const bool use_parent, + /* Only use when applying lock. */ + RegionView3D *rv3d, + const float view_mat[4][4]) +{ + const bool use_protect = (ob->protectflag != 0); + bool view_changed = false; + + ObjectTfmProtectedChannels obtfm; + if (use_protect) { + BKE_object_tfm_protected_backup(ob, &obtfm); + } + + BKE_object_apply_mat4(ob, obmat, true, use_parent); + + if (use_protect) { + float obmat_noprotect[4][4], obmat_protect[4][4]; + + BKE_object_to_mat4(ob, obmat_noprotect); + BKE_object_tfm_protected_restore(ob, &obtfm, ob->protectflag); + BKE_object_to_mat4(ob, obmat_protect); + + if (!equals_m4m4(obmat_noprotect, obmat_protect)) { + /* Apply the lock protection back to the view, without this the view + * keeps moving, ignoring the object locking, causing jittering in some cases. */ + float diff_mat[4][4]; + float view_mat_protect[4][4]; + float obmat_noprotect_inv[4][4]; + invert_m4_m4(obmat_noprotect_inv, obmat_noprotect); + mul_m4_m4m4(diff_mat, obmat_protect, obmat_noprotect_inv); + + mul_m4_m4m4(view_mat_protect, diff_mat, view_mat); + ED_view3d_from_m4(view_mat_protect, rv3d->ofs, rv3d->viewquat, &rv3d->dist); + view_changed = true; + } + } + return view_changed; +} + +/** * Updates cameras from the ``rv3d`` values, optionally auto-keyframing. */ void ED_view3d_cameracontrol_update(View3DCameraControl *vctrl, @@ -217,21 +266,25 @@ void ED_view3d_cameracontrol_update(View3DCameraControl *vctrl, ID *id_key; + float view_mat[4][4]; + ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist); + /* transform the parent or the camera? */ if (vctrl->root_parent) { Object *ob_update; - float view_mat[4][4]; float prev_view_imat[4][4]; float diff_mat[4][4]; float parent_mat[4][4]; invert_m4_m4(prev_view_imat, vctrl->view_mat_prev); - ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist); mul_m4_m4m4(diff_mat, view_mat, prev_view_imat); mul_m4_m4m4(parent_mat, diff_mat, vctrl->root_parent->obmat); - BKE_object_apply_mat4(vctrl->root_parent, parent_mat, true, false); + if (object_apply_mat4_with_protect(vctrl->root_parent, parent_mat, false, rv3d, view_mat)) { + /* Calculate again since the view locking changes the matrix. */ + ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist); + } ob_update = v3d->camera->parent; while (ob_update) { @@ -244,18 +297,16 @@ void ED_view3d_cameracontrol_update(View3DCameraControl *vctrl, id_key = &vctrl->root_parent->id; } else { - float view_mat[4][4]; float scale_mat[4][4]; float scale_back[3]; /* even though we handle the scale matrix, this still changes over time */ copy_v3_v3(scale_back, v3d->camera->scale); - ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist); size_to_mat4(scale_mat, v3d->camera->scale); mul_m4_m4m4(view_mat, view_mat, scale_mat); - BKE_object_apply_mat4(v3d->camera, view_mat, true, true); + object_apply_mat4_with_protect(v3d->camera, view_mat, true, rv3d, view_mat); DEG_id_tag_update(&v3d->camera->id, ID_RECALC_TRANSFORM); diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 6f7d815c33a..0442a0f35c9 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -36,6 +36,7 @@ #include "BKE_context.h" #include "BKE_customdata.h" #include "BKE_global.h" +#include "BKE_image.h" #include "BKE_key.h" #include "BKE_layer.h" #include "BKE_main.h" @@ -74,7 +75,6 @@ #include "GPU_batch.h" #include "GPU_batch_presets.h" -#include "GPU_draw.h" #include "GPU_framebuffer.h" #include "GPU_immediate.h" #include "GPU_immediate_util.h" @@ -115,8 +115,8 @@ void ED_view3d_update_viewmat(Depsgraph *depsgraph, const Scene *scene, View3D *v3d, ARegion *region, - float viewmat[4][4], - float winmat[4][4], + const float viewmat[4][4], + const float winmat[4][4], const rcti *rect, bool offscreen) { @@ -197,8 +197,8 @@ static void view3d_main_region_setup_view(Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *region, - float viewmat[4][4], - float winmat[4][4], + const float viewmat[4][4], + const float winmat[4][4], const rcti *rect) { RegionView3D *rv3d = region->regiondata; @@ -214,8 +214,8 @@ static void view3d_main_region_setup_offscreen(Depsgraph *depsgraph, const Scene *scene, View3D *v3d, ARegion *region, - float viewmat[4][4], - float winmat[4][4]) + const float viewmat[4][4], + const float winmat[4][4]) { RegionView3D *rv3d = region->regiondata; ED_view3d_update_viewmat(depsgraph, scene, v3d, region, viewmat, winmat, NULL, true); @@ -353,8 +353,8 @@ void ED_view3d_draw_setup_view(const wmWindowManager *wm, Scene *scene, ARegion *region, View3D *v3d, - float viewmat[4][4], - float winmat[4][4], + const float viewmat[4][4], + const float winmat[4][4], const rcti *rect) { RegionView3D *rv3d = region->regiondata; @@ -668,7 +668,8 @@ static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, /* safety border */ if (ca) { - immUniformThemeColorBlend(TH_VIEW_OVERLAY, TH_BACK, 0.25f); + GPU_blend(true); + immUniformThemeColorAlpha(TH_VIEW_OVERLAY, 0.75f); if (ca->dtx & CAM_DTX_CENTER) { float x3, y3; @@ -778,6 +779,8 @@ static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, * 2.0f round corner effect was nearly not visible anyway... */ imm_draw_box_wire_2d(shdr_pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax); } + + GPU_blend(false); } immUnbindProgram(); @@ -844,16 +847,9 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *region, View3D *v3d, bo ED_view3d_draw_setup_view( G_MAIN->wm.first, NULL, depsgraph, scene, region, v3d, NULL, NULL, NULL); - GPU_clear(GPU_DEPTH_BIT); - - if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) { - ED_view3d_clipping_set(rv3d); - } /* get surface depth without bias */ rv3d->rflag |= RV3D_ZOFFSET_DISABLED; - GPU_depth_test(true); - /* Needed in cases the view-port isn't already setup. */ WM_draw_region_viewport_ensure(region, SPACE_VIEW3D); WM_draw_region_viewport_bind(region); @@ -867,14 +863,8 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *region, View3D *v3d, bo WM_draw_region_viewport_unbind(region); - if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) { - ED_view3d_clipping_disable(); - } rv3d->rflag &= ~RV3D_ZOFFSET_DISABLED; - /* Reset default for UI */ - GPU_depth_test(false); - U.glalphaclip = glalphaclip; v3d->flag = flag; @@ -1085,7 +1075,7 @@ static void draw_rotation_guide(const RegionView3D *rv3d) GPU_blend(true); GPU_blend_set_func_separate( GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); - glDepthMask(GL_FALSE); /* don't overwrite zbuf */ + GPU_depth_mask(false); /* don't overwrite zbuf */ GPUVertFormat *format = immVertexFormat(); uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); @@ -1175,7 +1165,7 @@ static void draw_rotation_guide(const RegionView3D *rv3d) immUnbindProgram(); GPU_blend(false); - glDepthMask(GL_TRUE); + GPU_depth_mask(true); } #endif /* WITH_INPUT_NDOF */ @@ -1619,9 +1609,7 @@ RenderEngineType *ED_view3d_engine_type(const Scene *scene, int drawtype) if (drawtype == OB_MATERIAL && (type->flag & RE_USE_EEVEE_VIEWPORT)) { return RE_engines_find(RE_engine_id_BLENDER_EEVEE); } - else { - return type; - } + return type; } void view3d_main_region_draw(const bContext *C, ARegion *region) @@ -1632,7 +1620,7 @@ void view3d_main_region_draw(const bContext *C, ARegion *region) view3d_draw_view(C, region); DRW_cache_free_old_batches(bmain); - GPU_free_images_old(bmain); + BKE_image_free_old_gputextures(bmain); GPU_pass_cache_garbage_collect(); /* XXX This is in order to draw UI batches with the DRW @@ -1655,7 +1643,7 @@ static void view3d_stereo3d_setup_offscreen(Depsgraph *depsgraph, const Scene *scene, View3D *v3d, ARegion *region, - float winmat[4][4], + const float winmat[4][4], const char *viewname) { /* update the viewport matrices with the new camera */ @@ -1682,8 +1670,8 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph, ARegion *region, int winx, int winy, - float viewmat[4][4], - float winmat[4][4], + const float viewmat[4][4], + const float winmat[4][4], bool is_image_render, bool do_sky, bool UNUSED(is_persp), @@ -1714,10 +1702,15 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph, /* set flags */ G.f |= G_FLAG_RENDER_VIEWPORT; + /* There are too many functions inside the draw manager that check the shading type, + * so use a temporary override instead. */ + const eDrawType drawtype_orig = v3d->shading.type; + v3d->shading.type = drawtype; + { /* free images which can have changed on frame-change * warning! can be slow so only free animated images - campbell */ - GPU_free_images_anim(G.main); /* XXX :((( */ + BKE_image_free_anim_gputextures(G.main); /* XXX :((( */ } GPU_matrix_push_projection(); @@ -1754,6 +1747,7 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph, UI_Theme_Restore(&theme_state); + v3d->shading.type = drawtype_orig; G.f &= ~G_FLAG_RENDER_VIEWPORT; } @@ -1768,8 +1762,8 @@ void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph, int winx, int winy, uint draw_flags, - float viewmat[4][4], - float winmat[4][4], + const float viewmat[4][4], + const float winmat[4][4], float clip_start, float clip_end, bool is_image_render, @@ -1963,10 +1957,10 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, NULL); if (ibuf->rect_float) { - GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float); + GPU_offscreen_read_pixels(ofs, GPU_DATA_FLOAT, ibuf->rect_float); } else if (ibuf->rect) { - GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, ibuf->rect); + GPU_offscreen_read_pixels(ofs, GPU_DATA_UNSIGNED_BYTE, ibuf->rect); } /* unbind */ @@ -2116,27 +2110,6 @@ bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip); } -void ED_view3d_clipping_set(RegionView3D *UNUSED(rv3d)) -{ - for (uint a = 0; a < 6; a++) { - glEnable(GL_CLIP_DISTANCE0 + a); - } -} - -/* Use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set. */ -void ED_view3d_clipping_disable(void) -{ - for (uint a = 0; a < 6; a++) { - glDisable(GL_CLIP_DISTANCE0 + a); - } -} -void ED_view3d_clipping_enable(void) -{ - for (uint a = 0; a < 6; a++) { - glEnable(GL_CLIP_DISTANCE0 + a); - } -} - /* *********************** backdraw for selection *************** */ /** @@ -2194,13 +2167,8 @@ static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void GPU_framebuffer_texture_attach(tmp_fb, dtxl->depth, 0, 0); GPU_framebuffer_bind(tmp_fb); - glReadPixels(rect->xmin, - rect->ymin, - BLI_rcti_size_x(rect), - BLI_rcti_size_y(rect), - GL_DEPTH_COMPONENT, - GL_FLOAT, - data); + GPU_framebuffer_read_depth( + tmp_fb, rect->xmin, rect->ymin, BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), data); GPU_framebuffer_restore(); GPU_framebuffer_free(tmp_fb); @@ -2287,7 +2255,9 @@ void view3d_update_depths_rect(ARegion *region, ViewDepths *d, rcti *rect) if (d->damaged) { GPUViewport *viewport = WM_draw_region_get_viewport(region); view3d_opengl_read_Z_pixels(viewport, rect, d->depths); - glGetDoublev(GL_DEPTH_RANGE, d->depth_range); + /* Range is assumed to be this as they are never changed. */ + d->depth_range[0] = 0.0; + d->depth_range[1] = 1.0; d->damaged = false; } } @@ -2322,7 +2292,9 @@ void ED_view3d_depth_update(ARegion *region) .ymax = d->h, }; view3d_opengl_read_Z_pixels(viewport, &r, d->depths); - glGetDoublev(GL_DEPTH_RANGE, d->depth_range); + /* Assumed to be this as they are never changed. */ + d->depth_range[0] = 0.0; + d->depth_range[1] = 1.0; d->damaged = false; } } @@ -2437,7 +2409,7 @@ struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d) copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv); copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac); rv3dmat->pixsize = rv3d->pixsize; - return (void *)rv3dmat; + return rv3dmat; } void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat_pt) diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 3c3dea1509d..19aa9cb203b 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -509,8 +509,8 @@ static void viewops_data_create(bContext *C, negate_v3_v3(my_origin, rv3d->ofs); /* ofs is flipped */ - /* Set the dist value to be the distance from this 3d point this means youll - * always be able to zoom into it and panning wont go bad when dist was zero */ + /* Set the dist value to be the distance from this 3d point this means you'll + * always be able to zoom into it and panning wont go bad when dist was zero. */ /* remove dist value */ upvec[0] = upvec[1] = 0; @@ -1021,12 +1021,11 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_FINISHED; } - else { - /* add temp handler */ - WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; - } + /* add temp handler */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; } static void viewrotate_cancel(bContext *C, wmOperator *op) @@ -1848,12 +1847,11 @@ static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_FINISHED; } - else { - /* add temp handler */ - WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; - } + /* add temp handler */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; } static void viewmove_cancel(bContext *C, wmOperator *op) @@ -2407,18 +2405,17 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) viewops_data_free(C, op); return OPERATOR_FINISHED; } - else { - if (U.viewzoom == USER_ZOOM_CONT) { - /* needs a timer to continue redrawing */ - vod->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); - vod->prev.time = PIL_check_seconds_timer(); - } - /* add temp handler */ - WM_event_add_modal_handler(C, op); - - return OPERATOR_RUNNING_MODAL; + if (U.viewzoom == USER_ZOOM_CONT) { + /* needs a timer to continue redrawing */ + vod->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); + vod->prev.time = PIL_check_seconds_timer(); } + + /* add temp handler */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; } return OPERATOR_FINISHED; } @@ -2500,9 +2497,7 @@ static bool viewdolly_offset_lock_check(bContext *C, wmOperator *op) BKE_report(op->reports, RPT_WARNING, "Cannot dolly when the view offset is locked"); return true; } - else { - return false; - } + return false; } static void view_dolly_to_vector_3d(ARegion *region, float orig_ofs[3], float dvec[3], float dfac) @@ -2726,12 +2721,10 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) viewops_data_free(C, op); return OPERATOR_FINISHED; } - else { - /* add temp handler */ - WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; - } + /* add temp handler */ + WM_event_add_modal_handler(C, op); + return OPERATOR_RUNNING_MODAL; } return OPERATOR_FINISHED; } @@ -2952,6 +2945,9 @@ static int view3d_all_exec(bContext *C, wmOperator *op) } if (center) { + struct wmMsgBus *mbus = CTX_wm_message_bus(C); + WM_msg_publish_rna_prop(mbus, &scene->id, &scene->cursor, View3DCursor, location); + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); } @@ -3170,9 +3166,8 @@ static int view_lock_clear_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + + return OPERATOR_CANCELLED; } void VIEW3D_OT_view_lock_clear(wmOperatorType *ot) @@ -3228,9 +3223,8 @@ static int view_lock_to_active_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + + return OPERATOR_CANCELLED; } void VIEW3D_OT_view_lock_to_active(wmOperatorType *ot) @@ -4500,10 +4494,9 @@ static int viewroll_exec(bContext *C, wmOperator *op) viewops_data_free(C, op); return OPERATOR_FINISHED; } - else { - viewops_data_free(C, op); - return OPERATOR_CANCELLED; - } + + viewops_data_free(C, op); + return OPERATOR_CANCELLED; } static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) @@ -4535,12 +4528,10 @@ static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) viewops_data_free(C, op); return OPERATOR_FINISHED; } - else { - /* add temp handler */ - WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; - } + /* add temp handler */ + WM_event_add_modal_handler(C, op); + return OPERATOR_RUNNING_MODAL; } return OPERATOR_FINISHED; } @@ -4755,9 +4746,8 @@ static Camera *background_image_camera_from_context(bContext *C) } return NULL; } - else { - return CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data; - } + + return CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data; } static int background_image_add_exec(bContext *C, wmOperator *UNUSED(op)) @@ -4848,9 +4838,7 @@ static int background_image_remove_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } void VIEW3D_OT_background_image_remove(wmOperatorType *ot) @@ -4880,7 +4868,9 @@ void VIEW3D_OT_background_image_remove(wmOperatorType *ot) * Draw border or toggle off. * \{ */ -static void calc_local_clipping(float clip_local[6][4], BoundBox *clipbb, float mat[4][4]) +static void calc_local_clipping(float clip_local[6][4], + const BoundBox *clipbb, + const float mat[4][4]) { BoundBox clipbb_local; float imat[4][4]; @@ -4895,7 +4885,7 @@ static void calc_local_clipping(float clip_local[6][4], BoundBox *clipbb, float ED_view3d_clipping_calc_from_boundbox(clip_local, &clipbb_local, is_negative_m4(mat)); } -void ED_view3d_clipping_local(RegionView3D *rv3d, float mat[4][4]) +void ED_view3d_clipping_local(RegionView3D *rv3d, const float mat[4][4]) { if (rv3d->rflag & RV3D_CLIPPING) { calc_local_clipping(rv3d->clip_local, rv3d->clipbb, mat); @@ -4933,9 +4923,7 @@ static int view3d_clipping_invoke(bContext *C, wmOperator *op, const wmEvent *ev rv3d->clipbb = NULL; return OPERATOR_FINISHED; } - else { - return WM_gesture_box_invoke(C, op, event); - } + return WM_gesture_box_invoke(C, op, event); } void VIEW3D_OT_clip_border(wmOperatorType *ot) diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 506969443fd..556b5d51505 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -16,6 +16,10 @@ /** \file * \ingroup spview3d + * + * Interactive fly navigation modal operator (flying around in space). + * + * \note Similar logic to `view3d_walk.c` changes here may apply there too. */ /* defines VIEW3D_OT_fly modal operator */ @@ -200,7 +204,7 @@ typedef struct FlyInfo { float grid; /* compare between last state */ - /** Used to accelerate when using the mousewheel a lot. */ + /** Used to accelerate when using the mouse-wheel a lot. */ double time_lastwheel; /** Time between draws. */ double time_lastdraw; @@ -425,7 +429,7 @@ static int flyEnd(bContext *C, FlyInfo *fly) if (fly->state == FLY_RUNNING) { return OPERATOR_RUNNING_MODAL; } - else if (fly->state == FLY_CONFIRM) { + if (fly->state == FLY_CONFIRM) { /* Needed for auto_keyframe. */ #ifdef WITH_INPUT_NDOF if (fly->ndof) { @@ -614,8 +618,8 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event) fly->axis = -1; } else { - /* flip speed rather than stopping, game like motion, - * else increase like mousewheel if we're already moving in that direction */ + /* Flip speed rather than stopping, game like motion, + * else increase like mouse-wheel if we're already moving in that direction. */ if (fly->speed < 0.0f) { fly->speed = -fly->speed; } @@ -998,19 +1002,6 @@ static int flyApply(bContext *C, FlyInfo *fly, bool is_confirm) interp_v3_v3v3( dvec, dvec_tmp, fly->dvec_prev, (1.0f / (1.0f + (time_redraw * FLY_SMOOTH_FAC)))); - if (rv3d->persp == RV3D_CAMOB) { - Object *lock_ob = ED_view3d_cameracontrol_object_get(fly->v3d_camera_control); - if (lock_ob->protectflag & OB_LOCK_LOCX) { - dvec[0] = 0.0; - } - if (lock_ob->protectflag & OB_LOCK_LOCY) { - dvec[1] = 0.0; - } - if (lock_ob->protectflag & OB_LOCK_LOCZ) { - dvec[2] = 0.0; - } - } - add_v3_v3(rv3d->ofs, dvec); if (rv3d->persp == RV3D_CAMOB) { diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c index f3bc0a8a15b..59b2e378955 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c @@ -397,9 +397,7 @@ static bool view3d_ruler_item_mousemove(struct Depsgraph *depsgraph, } return true; } - else { - return false; - } + return false; } /** \} */ diff --git a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c index 18617b4368f..3f258a0699a 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.c @@ -126,9 +126,8 @@ static void WIDGETGROUP_tool_generic_refresh(const bContext *C, wmGizmoGroup *gz WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); return; } - else { - gzgroup->use_fallback_keymap = true; - } + + gzgroup->use_fallback_keymap = true; /* skip, we don't draw anything anyway */ { diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 50cd71d7edc..83707ca4383 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -21,8 +21,7 @@ * \ingroup spview3d */ -#ifndef __VIEW3D_INTERN_H__ -#define __VIEW3D_INTERN_H__ +#pragma once #include "ED_view3d.h" @@ -284,5 +283,3 @@ void VIEW3D_GGT_placement(struct wmGizmoGroupType *gzgt); extern uchar view3d_camera_border_hack_col[3]; extern bool view3d_camera_border_hack_test; #endif - -#endif /* __VIEW3D_INTERN_H__ */ diff --git a/source/blender/editors/space_view3d/view3d_placement.c b/source/blender/editors/space_view3d/view3d_placement.c index 131fbbc02ee..b7219290654 100644 --- a/source/blender/editors/space_view3d/view3d_placement.c +++ b/source/blender/editors/space_view3d/view3d_placement.c @@ -86,6 +86,11 @@ enum ePlace_Depth { PLACE_DEPTH_CURSOR_VIEW = 3, }; +enum ePlace_Orient { + PLACE_ORIENT_SURFACE = 1, + PLACE_ORIENT_DEFAULT = 2, +}; + struct InteractivePlaceData { /* Window manager variables (set these even when waiting for input). */ Scene *scene; @@ -145,16 +150,96 @@ struct InteractivePlaceData { /* On-screen snap distance. */ #define MVAL_MAX_PX_DIST 12.0f -static bool idp_snap_point_from_gizmo(wmGizmo *gz, float r_location[3]) +static bool idp_snap_point_from_gizmo_ex(wmGizmo *gz, const char *prop_id, float r_location[3]) { if (gz->state & WM_GIZMO_STATE_HIGHLIGHT) { - PropertyRNA *prop_location = RNA_struct_find_property(gz->ptr, "location"); + PropertyRNA *prop_location = RNA_struct_find_property(gz->ptr, prop_id); RNA_property_float_get_array(gz->ptr, prop_location, r_location); return true; } return false; } +static bool idp_snap_point_from_gizmo(wmGizmo *gz, float r_location[3]) +{ + return idp_snap_point_from_gizmo_ex(gz, "location", r_location); +} + +static bool idp_snap_normal_from_gizmo(wmGizmo *gz, float r_normal[3]) +{ + return idp_snap_point_from_gizmo_ex(gz, "normal", r_normal); +} + +/** + * Calculate a 3x3 orientation matrix from the surface under the cursor. + */ +static bool idp_poject_surface_normal(SnapObjectContext *snap_context, + struct Depsgraph *depsgraph, + const float mval_fl[2], + const float mat_fallback[3][3], + const float normal_fallback[3], + float r_mat[3][3]) +{ + bool success = false; + float normal[3] = {0.0f}; + float co_dummy[3]; + /* We could use the index to get the orientation from the face. */ + Object *ob_snap; + float obmat[4][4]; + + if (ED_transform_snap_object_project_view3d_ex(snap_context, + depsgraph, + SCE_SNAP_MODE_FACE, + &(const struct SnapObjectParams){ + .snap_select = SNAP_ALL, + .use_object_edit_cage = true, + }, + mval_fl, + NULL, + NULL, + co_dummy, + normal, + NULL, + &ob_snap, + obmat)) { + /* pass */ + } + else if (normal_fallback != NULL) { + copy_m4_m3(obmat, mat_fallback); + copy_v3_v3(normal, normal_fallback); + } + + if (!is_zero_v3(normal)) { + float mat[3][3]; + copy_m3_m4(mat, obmat); + normalize_m3(mat); + + float dot_best = fabsf(dot_v3v3(mat[0], normal)); + int i_best = 0; + for (int i = 1; i < 3; i++) { + float dot_test = fabsf(dot_v3v3(mat[i], normal)); + if (dot_test > dot_best) { + i_best = i; + dot_best = dot_test; + } + } + if (dot_v3v3(mat[i_best], normal) < 0.0f) { + negate_v3(mat[(i_best + 1) % 3]); + negate_v3(mat[(i_best + 2) % 3]); + } + copy_v3_v3(mat[i_best], normal); + orthogonalize_m3(mat, i_best); + normalize_m3(mat); + + copy_v3_v3(r_mat[0], mat[(i_best + 1) % 3]); + copy_v3_v3(r_mat[1], mat[(i_best + 2) % 3]); + copy_v3_v3(r_mat[2], mat[i_best]); + success = true; + } + + return success; +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -549,30 +634,69 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv const int plane_axis = RNA_enum_get(op->ptr, "plane_axis"); const enum ePlace_Depth plane_depth = RNA_enum_get(op->ptr, "plane_depth"); const enum ePlace_Origin plane_origin = RNA_enum_get(op->ptr, "plane_origin"); + const enum ePlace_Orient plane_orient = RNA_enum_get(op->ptr, "plane_orientation"); + + const float mval_fl[2] = {UNPACK2(event->mval)}; struct InteractivePlaceData *ipd = op->customdata; RegionView3D *rv3d = ipd->region->regiondata; + /* Assign snap gizmo which is may be used as part of the tool. */ + { + wmGizmoMap *gzmap = ipd->region->gizmo_map; + wmGizmoGroup *gzgroup = gzmap ? WM_gizmomap_group_find(gzmap, view3d_gzgt_placement_id) : NULL; + if ((gzgroup != NULL) && gzgroup->gizmos.first) { + ipd->snap_gizmo = gzgroup->gizmos.first; + } + } + ipd->launch_event = WM_userdef_event_type_from_keymap_type(event->type); ED_transform_calc_orientation_from_type(C, ipd->matrix_orient); + /* Set the orientation. */ + if (plane_orient == PLACE_ORIENT_SURFACE) { + bool snap_context_free = false; + SnapObjectContext *snap_context = + (ipd->snap_gizmo ? ED_gizmotypes_snap_3d_context_ensure( + ipd->scene, ipd->region, ipd->v3d, ipd->snap_gizmo) : + NULL); + if (snap_context == NULL) { + snap_context = ED_transform_snap_object_context_create_view3d( + ipd->scene, 0, ipd->region, ipd->v3d); + snap_context_free = true; + } + + float matrix_orient_surface[3][3]; + + /* Use the snap normal as a fallback in case the cursor isn't over a surface + * but snapping is enabled. */ + float normal_fallback[3]; + bool use_normal_fallback = ipd->snap_gizmo ? + idp_snap_normal_from_gizmo(ipd->snap_gizmo, normal_fallback) : + false; + + if (idp_poject_surface_normal(snap_context, + CTX_data_ensure_evaluated_depsgraph(C), + mval_fl, + use_normal_fallback ? ipd->matrix_orient : NULL, + use_normal_fallback ? normal_fallback : NULL, + matrix_orient_surface)) { + copy_m3_m3(ipd->matrix_orient, matrix_orient_surface); + } + + if (snap_context_free) { + ED_transform_snap_object_context_destroy(snap_context); + } + } + ipd->orient_axis = plane_axis; ipd->is_centered_init = (plane_origin == PLACE_ORIGIN_CENTER); ipd->step[0].is_centered = ipd->is_centered_init; ipd->step[1].is_centered = ipd->is_centered_init; ipd->step_index = STEP_BASE; - /* Assign snap gizmo which is may be used as part of the tool. */ - { - wmGizmoMap *gzmap = ipd->region->gizmo_map; - wmGizmoGroup *gzgroup = gzmap ? WM_gizmomap_group_find(gzmap, view3d_gzgt_placement_id) : NULL; - if ((gzgroup != NULL) && gzgroup->gizmos.first) { - ipd->snap_gizmo = gzgroup->gizmos.first; - } - } - { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "primitive_type"); if (RNA_property_is_set(op->ptr, prop)) { @@ -618,8 +742,6 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv plane_from_point_normal_v3( ipd->step[0].plane, ipd->scene->cursor.location, ipd->matrix_orient[ipd->orient_axis]); - const float mval_fl[2] = {UNPACK2(event->mval)}; - const bool is_snap_found = ipd->snap_gizmo ? idp_snap_point_from_gizmo(ipd->snap_gizmo, ipd->co_src) : false; @@ -826,7 +948,7 @@ static int view3d_interactive_add_modal(bContext *C, wmOperator *op, const wmEve view3d_interactive_add_exit(C, op); return OPERATOR_CANCELLED; } - else if (event->type == MOUSEMOVE) { + if (event->type == MOUSEMOVE) { do_cursor_update = true; } @@ -1102,6 +1224,25 @@ void VIEW3D_OT_interactive_add(struct wmOperatorType *ot) RNA_def_property_enum_items(prop, origin_items); RNA_def_property_flag(prop, PROP_SKIP_SAVE); + static const EnumPropertyItem plane_orientation_items[] = { + {PLACE_ORIENT_SURFACE, + "SURFACE", + ICON_SNAP_NORMAL, + "Surface", + "Use the surface normal (the transform orientation as a fallback)"}, + {PLACE_ORIENT_DEFAULT, + "DEFAULT", + ICON_ORIENTATION_GLOBAL, + "Default", + "Use the current transform orientation"}, + {0, NULL, 0, NULL, NULL}, + }; + prop = RNA_def_property(ot->srna, "plane_orientation", PROP_ENUM, PROP_NONE); + RNA_def_property_ui_text(prop, "Orientation", "The initial depth used when placing the cursor"); + RNA_def_property_enum_default(prop, PLACE_ORIENT_SURFACE); + RNA_def_property_enum_items(prop, plane_orientation_items); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + /* When not accessed via a tool. */ prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", ""); RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c index f4ec9a22520..c10a88af146 100644 --- a/source/blender/editors/space_view3d/view3d_project.c +++ b/source/blender/editors/space_view3d/view3d_project.c @@ -303,12 +303,12 @@ eV3DProjStatus ED_view3d_project_float_object(const ARegion *region, float ED_view3d_pixel_size(const RegionView3D *rv3d, const float co[3]) { - return mul_project_m4_v3_zfac((float(*)[4])rv3d->persmat, co) * rv3d->pixsize * U.pixelsize; + return mul_project_m4_v3_zfac(rv3d->persmat, co) * rv3d->pixsize * U.pixelsize; } float ED_view3d_pixel_size_no_ui_scale(const RegionView3D *rv3d, const float co[3]) { - return mul_project_m4_v3_zfac((float(*)[4])rv3d->persmat, co) * rv3d->pixsize; + return mul_project_m4_v3_zfac(rv3d->persmat, co) * rv3d->pixsize; } /** @@ -316,7 +316,7 @@ float ED_view3d_pixel_size_no_ui_scale(const RegionView3D *rv3d, const float co[ */ float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_flip) { - float zfac = mul_project_m4_v3_zfac((float(*)[4])rv3d->persmat, co); + float zfac = mul_project_m4_v3_zfac(rv3d->persmat, co); if (r_flip) { *r_flip = (zfac < 0.0f); @@ -483,11 +483,11 @@ void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3], p1[3] = 1.0f; copy_v3_v3(p2, p1); p2[3] = 1.0f; - mul_m4_v4((float(*)[4])rv3d->viewmat, p2); + mul_m4_v4(rv3d->viewmat, p2); mul_v3_fl(p2, 2.0f); - mul_m4_v4((float(*)[4])rv3d->viewinv, p2); + mul_m4_v4(rv3d->viewinv, p2); sub_v3_v3v3(vec, p1, p2); } @@ -749,25 +749,26 @@ bool ED_view3d_win_to_segment_clipped(struct Depsgraph *depsgraph, return true; } -/* Utility functions for projection - * ******************************** */ +/* -------------------------------------------------------------------- */ +/** \name Utility functions for projection + * \{ */ -void ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, Object *ob, float pmat[4][4]) +void ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, Object *ob, float r_pmat[4][4]) { float vmat[4][4]; - mul_m4_m4m4(vmat, (float(*)[4])rv3d->viewmat, ob->obmat); - mul_m4_m4m4(pmat, (float(*)[4])rv3d->winmat, vmat); + mul_m4_m4m4(vmat, rv3d->viewmat, ob->obmat); + mul_m4_m4m4(r_pmat, rv3d->winmat, vmat); } void ED_view3d_ob_project_mat_get_from_obmat(const RegionView3D *rv3d, - float obmat[4][4], - float pmat[4][4]) + const float obmat[4][4], + float r_pmat[4][4]) { float vmat[4][4]; - mul_m4_m4m4(vmat, (float(*)[4])rv3d->viewmat, obmat); - mul_m4_m4m4(pmat, (float(*)[4])rv3d->winmat, vmat); + mul_m4_m4m4(vmat, rv3d->viewmat, obmat); + mul_m4_m4m4(r_pmat, rv3d->winmat, vmat); } /** @@ -791,3 +792,5 @@ bool ED_view3d_unproject( return GPU_matrix_unproject(region_co, rv3d->viewmat, rv3d->winmat, viewport, world); } + +/** \} */ diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 9e235d72f26..9490c807989 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -97,7 +97,6 @@ #include "UI_interface.h" -#include "GPU_glew.h" #include "GPU_matrix.h" #include "DEG_depsgraph.h" @@ -1398,9 +1397,7 @@ static int view3d_lasso_select_exec(bContext *C, wmOperator *op) if (changed_multi) { return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } return OPERATOR_PASS_THROUGH; } @@ -1542,9 +1539,7 @@ static int object_select_menu_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } void VIEW3D_OT_select_menu(wmOperatorType *ot) @@ -1576,7 +1571,7 @@ void VIEW3D_OT_select_menu(wmOperatorType *ot) static Base *object_mouse_select_menu(bContext *C, ViewContext *vc, - uint *buffer, + const uint *buffer, int hits, const int mval[2], bool extend, @@ -1630,37 +1625,34 @@ static Base *object_mouse_select_menu(bContext *C, BLI_linklist_free(linklist, NULL); return base; } - else { - /* UI, full in static array values that we later use in an enum function */ - LinkNode *node; - int i; - memset(object_mouse_select_menu_data, 0, sizeof(object_mouse_select_menu_data)); + /* UI, full in static array values that we later use in an enum function */ + LinkNode *node; + int i; - for (node = linklist, i = 0; node; node = node->next, i++) { - Base *base = node->link; - Object *ob = base->object; - const char *name = ob->id.name + 2; + memset(object_mouse_select_menu_data, 0, sizeof(object_mouse_select_menu_data)); - BLI_strncpy(object_mouse_select_menu_data[i].idname, name, MAX_ID_NAME - 2); - object_mouse_select_menu_data[i].icon = UI_icon_from_id(&ob->id); - } + for (node = linklist, i = 0; node; node = node->next, i++) { + Base *base = node->link; + Object *ob = base->object; + const char *name = ob->id.name + 2; - { - wmOperatorType *ot = WM_operatortype_find("VIEW3D_OT_select_menu", false); - PointerRNA ptr; + BLI_strncpy(object_mouse_select_menu_data[i].idname, name, MAX_ID_NAME - 2); + object_mouse_select_menu_data[i].icon = UI_icon_from_id(&ob->id); + } - WM_operator_properties_create_ptr(&ptr, ot); - RNA_boolean_set(&ptr, "extend", extend); - RNA_boolean_set(&ptr, "deselect", deselect); - RNA_boolean_set(&ptr, "toggle", toggle); - WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr); - WM_operator_properties_free(&ptr); - } + wmOperatorType *ot = WM_operatortype_find("VIEW3D_OT_select_menu", false); + PointerRNA ptr; - BLI_linklist_free(linklist, NULL); - return NULL; - } + WM_operator_properties_create_ptr(&ptr, ot); + RNA_boolean_set(&ptr, "extend", extend); + RNA_boolean_set(&ptr, "deselect", deselect); + RNA_boolean_set(&ptr, "toggle", toggle); + WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr); + WM_operator_properties_free(&ptr); + + BLI_linklist_free(linklist, NULL); + return NULL; } static bool selectbuffer_has_bones(const uint *buffer, const uint hits) @@ -2120,7 +2112,7 @@ static bool ed_object_select_pick(bContext *C, if (hits > 0) { /* note: bundles are handling in the same way as bones */ - const bool has_bones = selectbuffer_has_bones(buffer, hits); + const bool has_bones = object ? false : selectbuffer_has_bones(buffer, hits); /* note; shift+alt goes to group-flush-selecting */ if (enumerate) { @@ -2504,9 +2496,7 @@ static int view3d_select_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED; } - else { - return OPERATOR_PASS_THROUGH; /* nothing selected, just passthrough */ - } + return OPERATOR_PASS_THROUGH; /* nothing selected, just passthrough */ } static int view3d_select_invoke(bContext *C, wmOperator *op, const wmEvent *event) @@ -3116,12 +3106,10 @@ static int opengl_bone_select_buffer_cmp(const void *sel_a_p, const void *sel_b_ if (sel_a < sel_b) { return -1; } - else if (sel_a > sel_b) { + if (sel_a > sel_b) { return 1; } - else { - return 0; - } + return 0; } static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const eSelectOp sel_op) @@ -3347,12 +3335,7 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op) FOREACH_OBJECT_IN_MODE_END; } else { /* No edit-mode, unified for bones and objects. */ - if (vc.obact && vc.obact->mode & OB_MODE_SCULPT) { - /* XXX, this is not selection, could be it's own operator. */ - changed_multi = ED_sculpt_mask_box_select( - C, &vc, &rect, sel_op == SEL_OP_ADD ? true : false); - } - else if (vc.obact && BKE_paint_select_face_test(vc.obact)) { + if (vc.obact && BKE_paint_select_face_test(vc.obact)) { changed_multi = do_paintface_box_select(&vc, wm_userdata, &rect, sel_op); } else if (vc.obact && BKE_paint_select_vert_test(vc.obact)) { @@ -3380,9 +3363,7 @@ static int view3d_box_select_exec(bContext *C, wmOperator *op) if (changed_multi) { return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } void VIEW3D_OT_select_box(wmOperatorType *ot) diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 91b2971585d..265cb04c7b2 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -869,9 +869,7 @@ static int snap_curs_to_sel_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } void VIEW3D_OT_snap_cursor_to_selected(wmOperatorType *ot) @@ -921,9 +919,7 @@ static int snap_curs_to_active_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } void VIEW3D_OT_snap_cursor_to_active(wmOperatorType *ot) diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c index 15d6a43d105..4e73a2be17e 100644 --- a/source/blender/editors/space_view3d/view3d_utils.c +++ b/source/blender/editors/space_view3d/view3d_utils.c @@ -113,9 +113,7 @@ Camera *ED_view3d_camera_data_get(View3D *v3d, RegionView3D *rv3d) if ((rv3d->persp == RV3D_CAMOB) && v3d->camera && (v3d->camera->type == OB_CAMERA)) { return v3d->camera->data; } - else { - return NULL; - } + return NULL; } void ED_view3d_dist_range_get(const View3D *v3d, float r_dist_range[2]) @@ -222,7 +220,7 @@ void view3d_region_operator_needs_opengl(wmWindow *UNUSED(win), ARegion *region) } /** - * Use instead of: ``bglPolygonOffset(rv3d->dist, ...)`` see bug [#37727] + * Use instead of: ``GPU_polygon_offset(rv3d->dist, ...)`` see bug [#37727] */ void ED_view3d_polygon_offset(const RegionView3D *rv3d, const float dist) { @@ -243,7 +241,7 @@ void ED_view3d_polygon_offset(const RegionView3D *rv3d, const float dist) } } - bglPolygonOffset(viewdist, dist); + GPU_polygon_offset(viewdist, dist); } bool ED_view3d_context_activate(bContext *C) @@ -337,7 +335,7 @@ void ED_view3d_clipping_calc( * * \{ */ -static bool view3d_boundbox_clip_m4(const BoundBox *bb, float persmatob[4][4]) +static bool view3d_boundbox_clip_m4(const BoundBox *bb, const float persmatob[4][4]) { int a, flag = -1, fl; @@ -602,9 +600,7 @@ bool ED_view3d_camera_lock_sync(const Depsgraph *depsgraph, View3D *v3d, RegionV return true; } - else { - return false; - } + return false; } bool ED_view3d_camera_autokey(const Scene *scene, @@ -639,9 +635,7 @@ bool ED_view3d_camera_autokey(const Scene *scene, return true; } - else { - return false; - } + return false; } /** @@ -673,9 +667,7 @@ bool ED_view3d_camera_lock_autokey(View3D *v3d, return ED_view3d_camera_autokey(scene, id_key, C, do_rotate, do_translate); } - else { - return false; - } + return false; } /** \} */ @@ -1017,9 +1009,7 @@ bool ED_view3d_autodist(Depsgraph *depsgraph, ED_view3d_win_to_3d_int(v3d, region, fallback_depth_pt, mval, mouse_worldloc); return true; } - else { - return false; - } + return false; } void ED_view3d_autodist_init(Depsgraph *depsgraph, ARegion *region, View3D *v3d, int mode) @@ -1038,8 +1028,11 @@ void ED_view3d_autodist_init(Depsgraph *depsgraph, ARegion *region, View3D *v3d, } /* no 4x4 sampling, run #ED_view3d_autodist_init first */ -bool ED_view3d_autodist_simple( - ARegion *region, const int mval[2], float mouse_worldloc[3], int margin, float *force_depth) +bool ED_view3d_autodist_simple(ARegion *region, + const int mval[2], + float mouse_worldloc[3], + int margin, + const float *force_depth) { float depth; @@ -1086,9 +1079,7 @@ static bool depth_segment_cb(int x, int y, void *userData) data->depth = depth; return 0; } - else { - return 1; - } + return 1; } bool ED_view3d_autodist_depth_seg( @@ -1252,7 +1243,9 @@ float ED_view3d_radius_to_dist(const View3D *v3d, * \param fallback_dist: The distance to use if the object is too near or in front of \a ofs. * \returns A newly calculated distance or the fallback. */ -float ED_view3d_offset_distance(float mat[4][4], const float ofs[3], const float fallback_dist) +float ED_view3d_offset_distance(const float mat[4][4], + const float ofs[3], + const float fallback_dist) { float pos[4] = {0.0f, 0.0f, 0.0f, 1.0f}; float dir[4] = {0.0f, 0.0f, 1.0f, 0.0f}; @@ -1383,16 +1376,14 @@ static float view3d_quat_axis[6][4][4] = { }; -bool ED_view3d_quat_from_axis_view(const char view, const char view_axis_roll, float quat[4]) +bool ED_view3d_quat_from_axis_view(const char view, const char view_axis_roll, float r_quat[4]) { BLI_assert(view_axis_roll <= RV3D_VIEW_AXIS_ROLL_270); if (RV3D_VIEW_IS_AXIS(view)) { - copy_qt_qt(quat, view3d_quat_axis[view - RV3D_VIEW_FRONT][view_axis_roll]); + copy_qt_qt(r_quat, view3d_quat_axis[view - RV3D_VIEW_FRONT][view_axis_roll]); return true; } - else { - return false; - } + return false; } bool ED_view3d_quat_to_axis_view(const float quat[4], @@ -1472,7 +1463,7 @@ bool ED_view3d_lock(RegionView3D *rv3d) * \param quat: The view rotation, quaternion normally from RegionView3D.viewquat. * \param dist: The view distance from ofs, normally from RegionView3D.dist. */ -void ED_view3d_from_m4(const float mat[4][4], float ofs[3], float quat[4], float *dist) +void ED_view3d_from_m4(const float mat[4][4], float ofs[3], float quat[4], const float *dist) { float nmat[3][3]; @@ -1575,10 +1566,9 @@ float ED_view3d_depth_read_cached(const ViewContext *vc, const int mval[2]) if (vd && vd->depths && x > 0 && y > 0 && x < vd->w && y < vd->h) { return vd->depths[y * vd->w + x]; } - else { - BLI_assert(1.0 <= vd->depth_range[1]); - return 1.0f; - } + + BLI_assert(1.0 <= vd->depth_range[1]); + return 1.0f; } bool ED_view3d_depth_read_cached_normal(const ViewContext *vc, @@ -1633,9 +1623,7 @@ bool ED_view3d_depth_read_cached_normal(const ViewContext *vc, if (normalize_v3(r_normal) != 0.0f) { return true; } - else { - return false; - } + return false; } bool ED_view3d_depth_unproject(const ARegion *region, diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 3fc990160d2..ff9673a4262 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -50,7 +50,6 @@ #include "UI_resources.h" -#include "GPU_glew.h" #include "GPU_matrix.h" #include "GPU_select.h" #include "GPU_state.h" @@ -568,9 +567,7 @@ static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, camera_ob); return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot) @@ -1106,10 +1103,6 @@ int view3d_opengl_select(ViewContext *vc, GPU_depth_test(true); } - if (RV3D_CLIPPING_ENABLED(vc->v3d, vc->rv3d)) { - ED_view3d_clipping_set(vc->rv3d); - } - /* If in xray mode, we select the wires in priority. */ if (XRAY_ACTIVE(v3d) && use_nearest) { /* We need to call "GPU_select_*" API's inside DRW_draw_select_loop @@ -1175,10 +1168,6 @@ int view3d_opengl_select(ViewContext *vc, GPU_depth_test(false); } - if (RV3D_CLIPPING_ENABLED(v3d, vc->rv3d)) { - ED_view3d_clipping_disable(); - } - DRW_opengl_context_disable(); finally: @@ -1486,9 +1475,7 @@ static int localview_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } void VIEW3D_OT_localview(wmOperatorType *ot) @@ -1538,10 +1525,9 @@ static int localview_remove_from_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); return OPERATOR_FINISHED; } - else { - BKE_report(op->reports, RPT_ERROR, "No object selected"); - return OPERATOR_CANCELLED; - } + + BKE_report(op->reports, RPT_ERROR, "No object selected"); + return OPERATOR_CANCELLED; } static bool localview_remove_from_poll(bContext *C) diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c index 50fa573423a..64167b83655 100644 --- a/source/blender/editors/space_view3d/view3d_walk.c +++ b/source/blender/editors/space_view3d/view3d_walk.c @@ -16,6 +16,11 @@ /** \file * \ingroup spview3d + * + * Interactive walk navigation modal operator + * (similar to walking around in a first person game). + * + * \note Similar logic to `view3d_fly.c` changes here may apply there too. */ /* defines VIEW3D_OT_navigate - walk modal operator */ @@ -620,7 +625,7 @@ static int walkEnd(bContext *C, WalkInfo *walk) if (walk->state == WALK_RUNNING) { return OPERATOR_RUNNING_MODAL; } - else if (walk->state == WALK_CONFIRM) { + if (walk->state == WALK_CONFIRM) { /* Needed for auto_keyframe. */ #ifdef WITH_INPUT_NDOF if (walk->ndof) { @@ -1295,19 +1300,6 @@ static int walkApply(bContext *C, WalkInfo *walk, bool is_confirm) sub_v3_v3v3(dvec, cur_loc, new_loc); } - if (rv3d->persp == RV3D_CAMOB) { - Object *lock_ob = ED_view3d_cameracontrol_object_get(walk->v3d_camera_control); - if (lock_ob->protectflag & OB_LOCK_LOCX) { - dvec[0] = 0.0f; - } - if (lock_ob->protectflag & OB_LOCK_LOCY) { - dvec[1] = 0.0f; - } - if (lock_ob->protectflag & OB_LOCK_LOCZ) { - dvec[2] = 0.0f; - } - } - /* scale the movement to the scene size */ mul_v3_v3fl(dvec_tmp, dvec, walk->grid); add_v3_v3(rv3d->ofs, dvec_tmp); |