diff options
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_edit.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 177 |
1 files changed, 52 insertions, 125 deletions
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index f712c790663..42e8759c6dc 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -60,9 +60,7 @@ #include "BKE_action.h" #include "BKE_depsgraph.h" /* for ED_view3d_camera_lock_sync */ - #include "BIF_gl.h" -#include "BIF_glutil.h" #include "WM_api.h" #include "WM_types.h" @@ -621,7 +619,8 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) bool is_set = false; Scene *scene = CTX_data_scene(C); - Object *ob_act = OBACT; + SceneLayer *sl = CTX_data_scene_layer(C); + Object *ob_act = OBACT_NEW; if (ob_act && (ob_act->mode & OB_MODE_ALL_PAINT) && /* with weight-paint + pose-mode, fall through to using calculateTransformCenter */ @@ -658,14 +657,13 @@ static 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 */ - View3D *v3d = CTX_wm_view3d(C); Base *base; unsigned int tot = 0; float select_center[3]; zero_v3(select_center); - for (base = FIRSTBASE; base; base = base->next) { - if (TESTBASE(v3d, base)) { + for (base = FIRSTBASE_NEW; base; base = base->next) { + if (TESTBASE_NEW(base)) { /* use the boundbox if we can */ Object *ob = base->object; @@ -737,6 +735,7 @@ static void viewops_data_create_ex( /* we need the depth info before changing any viewport options */ if (orbit_mode == VIEWOPS_ORBIT_DEPTH) { + struct Depsgraph *graph = CTX_data_depsgraph(C); float fallback_depth_pt[3]; view3d_operator_needs_opengl(C); /* needed for zbuf drawing */ @@ -744,7 +743,7 @@ static void viewops_data_create_ex( negate_v3_v3(fallback_depth_pt, rv3d->ofs); vod->use_dyn_ofs = ED_view3d_autodist( - vod->scene, vod->ar, vod->v3d, + graph, vod->scene, vod->ar, vod->v3d, event->mval, vod->dyn_ofs, true, fallback_depth_pt); } else { @@ -862,8 +861,9 @@ static void viewops_data_create(bContext *C, wmOperator *op, const wmEvent *even static void viewops_data_free(bContext *C, wmOperator *op) { ARegion *ar; +#if 0 Paint *p = BKE_paint_get_active_from_context(C); - +#endif if (op->customdata) { ViewOpsData *vod = op->customdata; ar = vod->ar; @@ -879,7 +879,9 @@ static void viewops_data_free(bContext *C, wmOperator *op) ar = CTX_wm_region(C); } +#if 0 if (p && (p->flags & PAINT_FAST_NAVIGATE)) +#endif ED_region_tag_redraw(ar); } /** \} */ @@ -2976,6 +2978,7 @@ static int view3d_all_exec(bContext *C, wmOperator *op) /* was view3d_home() in ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); Base *base; float *curs; const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions"); @@ -2999,8 +3002,8 @@ static int view3d_all_exec(bContext *C, wmOperator *op) /* was view3d_home() in INIT_MINMAX(min, max); } - for (base = scene->base.first; base; base = base->next) { - if (BASE_VISIBLE(v3d, base)) { + for (base = sl->object_bases.first; base; base = base->next) { + if (BASE_VISIBLE_NEW(base)) { changed = true; if (skip_camera && base->object == v3d->camera) { @@ -3060,9 +3063,10 @@ static int viewselected_exec(bContext *C, wmOperator *op) ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); bGPdata *gpd = CTX_data_gpencil_data(C); const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE)); - Object *ob = OBACT; + Object *ob = OBACT_NEW; Object *obedit = CTX_data_edit_object(C); float min[3], max[3]; bool ok = false, ok_dist = true; @@ -3082,8 +3086,8 @@ static int viewselected_exec(bContext *C, wmOperator *op) /* hard-coded exception, we look for the one selected armature */ /* this is weak code this way, we should make a generic active/selection callback interface once... */ Base *base; - for (base = scene->base.first; base; base = base->next) { - if (TESTBASELIB(v3d, base)) { + for (base = sl->object_bases.first; base; base = base->next) { + if (TESTBASELIB_NEW(base)) { if (base->object->type == OB_ARMATURE) if (base->object->mode & OB_MODE_POSE) break; @@ -3116,7 +3120,7 @@ static int viewselected_exec(bContext *C, wmOperator *op) ok = paintface_minmax(ob, min, max); } else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT)) { - ok = PE_minmax(scene, min, max); + ok = PE_minmax(scene, sl, min, max); } else if (ob && (ob->mode & (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))) @@ -3128,8 +3132,8 @@ static int viewselected_exec(bContext *C, wmOperator *op) } else { Base *base; - for (base = FIRSTBASE; base; base = base->next) { - if (TESTBASE(v3d, base)) { + for (base = FIRSTBASE_NEW; base; base = base->next) { + if (TESTBASE_NEW(base)) { if (skip_camera && base->object == v3d->camera) { continue; @@ -3310,6 +3314,7 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev ARegion *ar = CTX_wm_region(C); if (rv3d) { + struct Depsgraph *graph = CTX_data_depsgraph(C); float new_ofs[3]; const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); @@ -3317,7 +3322,7 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(scene, ar, v3d, event->mval, new_ofs, false, NULL)) { + if (ED_view3d_autodist(graph, scene, ar, v3d, event->mval, new_ofs, false, NULL)) { /* pass */ } else { @@ -3589,9 +3594,8 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) float new_ofs[3]; /* ZBuffer depth vars */ - bglMats mats; float depth_close = FLT_MAX; - double cent[2], p[3]; + float p[3]; /* note; otherwise opengl won't work */ view3d_operator_needs_opengl(C); @@ -3605,8 +3609,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) ED_view3d_dist_range_get(v3d, dist_range); /* Get Z Depths, needed for perspective, nice for ortho */ - bgl_get_mats(&mats); - ED_view3d_draw_depth(scene, ar, v3d, true); + ED_view3d_draw_depth(CTX_data_depsgraph(C), scene, ar, v3d, true); { /* avoid allocating the whole depth buffer */ @@ -3621,11 +3624,11 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) MEM_SAFE_FREE(depth_temp.depths); } - cent[0] = (((double)rect.xmin) + ((double)rect.xmax)) / 2; - cent[1] = (((double)rect.ymin) + ((double)rect.ymax)) / 2; + float centx = (((float)rect.xmin) + ((float)rect.xmax)) / 2; + float centy = (((float)rect.ymin) + ((float)rect.ymax)) / 2; if (rv3d->is_persp) { - double p_corner[3]; + float p_corner[3]; /* no depths to use, we cant do anything! */ if (depth_close == FLT_MAX) { @@ -3633,23 +3636,14 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } /* convert border to 3d coordinates */ - if ((!gluUnProject(cent[0], cent[1], depth_close, - mats.modelview, mats.projection, (GLint *)mats.viewport, - &p[0], &p[1], &p[2])) || - (!gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close, - mats.modelview, mats.projection, (GLint *)mats.viewport, - &p_corner[0], &p_corner[1], &p_corner[2]))) + if ((!ED_view3d_unproject(ar, centx, centy, depth_close, p)) || + (!ED_view3d_unproject(ar, rect.xmin, rect.ymin, depth_close, p_corner))) { return OPERATOR_CANCELLED; } - dvec[0] = p[0] - p_corner[0]; - dvec[1] = p[1] - p_corner[1]; - dvec[2] = p[2] - p_corner[2]; - - new_ofs[0] = -p[0]; - new_ofs[1] = -p[1]; - new_ofs[2] = -p[2]; + sub_v3_v3v3(dvec, p, p_corner); + negate_v3_v3(new_ofs, p); new_dist = len_v3(dvec); @@ -3664,13 +3658,9 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) new_dist = rv3d->dist; /* convert the drawn rectangle into 3d space */ - if (depth_close != FLT_MAX && gluUnProject(cent[0], cent[1], depth_close, - mats.modelview, mats.projection, (GLint *)mats.viewport, - &p[0], &p[1], &p[2])) + if (depth_close != FLT_MAX && ED_view3d_unproject(ar, centx, centy, depth_close, p)) { - new_ofs[0] = -p[0]; - new_ofs[1] = -p[1]; - new_ofs[2] = -p[2]; + negate_v3_v3(new_ofs, p); } else { float mval_f[2]; @@ -3907,6 +3897,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op) ARegion *ar; RegionView3D *rv3d; Scene *scene = CTX_data_scene(C); + SceneLayer *sl = CTX_data_scene_layer(C); static int perspo = RV3D_PERSP; int viewnum, nextperspo; bool align_active; @@ -3941,7 +3932,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op) /* lastview - */ if (rv3d->persp != RV3D_CAMOB) { - Object *ob = OBACT; + Object *ob = OBACT_NEW; if (!rv3d->smooth_timer) { /* store settings of current view before allowing overwriting with camera view @@ -4635,9 +4626,8 @@ void ED_view3d_clipping_local(RegionView3D *rv3d, float mat[4][4]) static int view3d_clipping_exec(bContext *C, wmOperator *op) { + ARegion *ar = CTX_wm_region(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); - ViewContext vc; - bglMats mats; rcti rect; WM_operator_properties_border_to_rcti(op, &rect); @@ -4645,12 +4635,8 @@ static int view3d_clipping_exec(bContext *C, wmOperator *op) rv3d->rflag |= RV3D_CLIPPING; rv3d->clipbb = MEM_callocN(sizeof(BoundBox), "clipbb"); - /* note; otherwise opengl won't work */ - view3d_operator_needs_opengl(C); - - view3d_set_viewcontext(C, &vc); - view3d_get_transformation(vc.ar, vc.rv3d, NULL, &mats); /* NULL because we don't want it in object space */ - ED_view3d_clipping_calc(rv3d->clipbb, rv3d->clip, &mats, &rect); + /* NULL object because we don't want it in object space */ + ED_view3d_clipping_calc(rv3d->clipbb, rv3d->clip, ar, NULL, &rect); return OPERATOR_FINISHED; } @@ -4724,8 +4710,9 @@ void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2]) } if (U.uiflag & USER_ZBUF_CURSOR) { /* maybe this should be accessed some other way */ + struct Depsgraph *graph = CTX_data_depsgraph(C); view3d_operator_needs_opengl(C); - if (ED_view3d_autodist(scene, ar, v3d, mval, fp, true, NULL)) + if (ED_view3d_autodist(graph, scene, ar, v3d, mval, fp, true, NULL)) depth_used = true; } @@ -4798,45 +4785,6 @@ void VIEW3D_OT_cursor3d(wmOperatorType *ot) /* ***************** manipulator op ******************* */ - -static int manipulator_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - View3D *v3d = CTX_wm_view3d(C); - - if (!(v3d->twflag & V3D_USE_MANIPULATOR)) return OPERATOR_PASS_THROUGH; - if (!(v3d->twflag & V3D_DRAW_MANIPULATOR)) return OPERATOR_PASS_THROUGH; - - /* note; otherwise opengl won't work */ - view3d_operator_needs_opengl(C); - - if (BIF_do_manipulator(C, event, op) == 0) - return OPERATOR_PASS_THROUGH; - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_manipulator(wmOperatorType *ot) -{ - PropertyRNA *prop; - - /* identifiers */ - ot->name = "3D Manipulator"; - ot->description = "Manipulate selected item by axis"; - ot->idname = "VIEW3D_OT_manipulator"; - - /* api callbacks */ - ot->invoke = manipulator_invoke; - - ot->poll = ED_operator_view3d_active; - - /* properties to pass to transform */ - Transform_Properties(ot, P_CONSTRAINT); - - prop = RNA_def_boolean(ot->srna, "use_planar_constraint", false, "Planar Constraint", "Limit the transformation to the " - "two axes that have not been clicked (translate/scale only)"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN); -} - static int enable_manipulator_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { View3D *v3d = CTX_wm_view3d(C); @@ -4940,22 +4888,17 @@ static float view_autodist_depth_margin(ARegion *ar, const int mval[2], int marg * \param fallback_depth_pt: Use this points depth when no depth can be found. */ bool ED_view3d_autodist( - Scene *scene, ARegion *ar, View3D *v3d, + struct Depsgraph *graph, Scene *scene, ARegion *ar, View3D *v3d, const int mval[2], float mouse_worldloc[3], const bool alphaoverride, const float fallback_depth_pt[3]) { - bglMats mats; /* ZBuffer depth vars */ float depth_close; - double cent[2], p[3]; int margin_arr[] = {0, 2, 4}; int i; bool depth_ok = false; /* Get Z Depths, needed for perspective, nice for ortho */ - ED_view3d_draw_depth(scene, ar, v3d, alphaoverride); - - /* call after in case settings have been modified since last drawing, see: T47089 */ - bgl_get_mats(&mats); + ED_view3d_draw_depth(graph, scene, ar, v3d, alphaoverride); /* Attempt with low margin's first */ i = 0; @@ -4965,15 +4908,11 @@ bool ED_view3d_autodist( } while ((depth_ok == false) && (i < ARRAY_SIZE(margin_arr))); if (depth_ok) { - cent[0] = (double)mval[0] + 0.5; - cent[1] = (double)mval[1] + 0.5; + float centx = (float)mval[0] + 0.5f; + float centy = (float)mval[1] + 0.5f; - if (gluUnProject(cent[0], cent[1], depth_close, - mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2])) + if (ED_view3d_unproject(ar, centx, centy, depth_close, mouse_worldloc)) { - mouse_worldloc[0] = (float)p[0]; - mouse_worldloc[1] = (float)p[1]; - mouse_worldloc[2] = (float)p[2]; return true; } } @@ -4987,12 +4926,14 @@ bool ED_view3d_autodist( } } -void ED_view3d_autodist_init(Scene *scene, ARegion *ar, View3D *v3d, int mode) +void ED_view3d_autodist_init( + struct Depsgraph *graph, + Scene *scene, ARegion *ar, View3D *v3d, int mode) { /* Get Z Depths, needed for perspective, nice for ortho */ switch (mode) { case 0: - ED_view3d_draw_depth(scene, ar, v3d, true); + ED_view3d_draw_depth(graph, scene, ar, v3d, true); break; case 1: ED_view3d_draw_depth_gpencil(scene, ar, v3d); @@ -5004,9 +4945,7 @@ void ED_view3d_autodist_init(Scene *scene, ARegion *ar, View3D *v3d, int mode) bool ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldloc[3], int margin, float *force_depth) { - bglMats mats; /* ZBuffer depth vars, could cache? */ float depth; - double cent[2], p[3]; /* Get Z Depths, needed for perspective, nice for ortho */ if (force_depth) @@ -5017,21 +4956,9 @@ bool ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_world if (depth == FLT_MAX) return false; - cent[0] = (double)mval[0] + 0.5; - cent[1] = (double)mval[1] + 0.5; - - bgl_get_mats(&mats); - - if (!gluUnProject(cent[0], cent[1], depth, - mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2])) - { - return false; - } - - mouse_worldloc[0] = (float)p[0]; - mouse_worldloc[1] = (float)p[1]; - mouse_worldloc[2] = (float)p[2]; - return true; + float centx = (float)mval[0] + 0.5f; + float centy = (float)mval[1] + 0.5f; + return ED_view3d_unproject(ar, centx, centy, depth, mouse_worldloc); } bool ED_view3d_autodist_depth(ARegion *ar, const int mval[2], int margin, float *depth) |