replace most uses of ED_view3d_project_float_noclip() with ED_view3d_project_float_gl...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 5 Oct 2012 03:57:56 +0000 (03:57 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 5 Oct 2012 03:57:56 +0000 (03:57 +0000)
source/blender/editors/include/ED_mesh.h
source/blender/editors/mesh/editmesh_slide.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/transform/transform.c

index 02c7d52f08d5b8cd44871f67fbc8e2c28aefd5c2..6281861250962d2de3c13eeee6ceb6aa3efc3d24 100644 (file)
@@ -174,7 +174,7 @@ void        ED_spacetypes_init(void);
 
 
 /* editmesh_tools.c (could be moved) */
 
 
 /* editmesh_tools.c (could be moved) */
-void EMBM_project_snap_verts(struct bContext *C, struct ARegion *ar, struct Object *obedit, struct BMEditMesh *em);
+void EMBM_project_snap_verts(struct bContext *C, struct ARegion *ar, struct BMEditMesh *em);
 
 
 /* editface.c */
 
 
 /* editface.c */
index bd1d13f3528a4eca9f1e54fab55258e7c52b067d..e42b95c6013ec812d212dcbdc9b31edae3f7ae07 100644 (file)
@@ -381,22 +381,23 @@ static BMEdge *vtx_slide_nrst_in_frame(VertexSlideOp *vso, const float mval[2])
                BMEdge *edge = NULL;
                
                float v1_proj[3], v2_proj[3];
                BMEdge *edge = NULL;
                
                float v1_proj[3], v2_proj[3];
-               float dist = 0;
                float min_dist = FLT_MAX;
 
                for (i = 0; i < vso->disk_edges; i++) {
                        edge = vso->edge_frame[i];
 
                        mul_v3_m4v3(v1_proj, vso->obj->obmat, edge->v1->co);
                float min_dist = FLT_MAX;
 
                for (i = 0; i < vso->disk_edges; i++) {
                        edge = vso->edge_frame[i];
 
                        mul_v3_m4v3(v1_proj, vso->obj->obmat, edge->v1->co);
-                       ED_view3d_project_float_noclip(vso->active_region, v1_proj, v1_proj);
-
                        mul_v3_m4v3(v2_proj, vso->obj->obmat, edge->v2->co);
                        mul_v3_m4v3(v2_proj, vso->obj->obmat, edge->v2->co);
-                       ED_view3d_project_float_noclip(vso->active_region, v2_proj, v2_proj);
 
 
-                       dist = dist_to_line_segment_v2(mval, v1_proj, v2_proj);
-                       if (dist < min_dist) {
-                               min_dist = dist;
-                               cl_edge = edge;
+                       /* we could use ED_view3d_project_float_object here, but for now dont since we dont have the context */
+                       if ((ED_view3d_project_float_global(vso->active_region, v1_proj, v1_proj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) &&
+                           (ED_view3d_project_float_global(vso->active_region, v2_proj, v2_proj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS))
+                       {
+                               const float dist = dist_to_line_segment_v2(mval, v1_proj, v2_proj);
+                               if (dist < min_dist) {
+                                       min_dist = dist;
+                                       cl_edge = edge;
+                               }
                        }
                }
        }
                        }
                }
        }
@@ -448,17 +449,21 @@ static void vtx_slide_update(VertexSlideOp *vso, wmEvent *event)
                /* Calculate interpolation value for preview */
                float t_val;
 
                /* Calculate interpolation value for preview */
                float t_val;
 
-               float mval_float[] = { (float)event->mval[0], (float)event->mval[1]};
+               float mval_float[2] = { (float)event->mval[0], (float)event->mval[1]};
                float closest_2d[2];
 
                other = BM_edge_other_vert(edge, vso->start_vtx);
 
                /* Project points onto screen and do interpolation in 2D */
                mul_v3_m4v3(start_vtx_proj, vso->obj->obmat, vso->start_vtx->co);
                float closest_2d[2];
 
                other = BM_edge_other_vert(edge, vso->start_vtx);
 
                /* Project points onto screen and do interpolation in 2D */
                mul_v3_m4v3(start_vtx_proj, vso->obj->obmat, vso->start_vtx->co);
-               ED_view3d_project_float_noclip(vso->active_region, start_vtx_proj, start_vtx_proj);
-
                mul_v3_m4v3(edge_other_proj, vso->obj->obmat, other->co);
                mul_v3_m4v3(edge_other_proj, vso->obj->obmat, other->co);
-               ED_view3d_project_float_noclip(vso->active_region, edge_other_proj, edge_other_proj);
+
+               if ((ED_view3d_project_float_global(vso->active_region, edge_other_proj, edge_other_proj, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_SUCCESS) ||
+                   (ED_view3d_project_float_global(vso->active_region, start_vtx_proj, start_vtx_proj, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_SUCCESS))
+               {
+                       /* not much we can do here */
+                       return;
+               }
 
                closest_to_line_v2(closest_2d, mval_float, start_vtx_proj, edge_other_proj);
 
 
                closest_to_line_v2(closest_2d, mval_float, start_vtx_proj, edge_other_proj);
 
@@ -470,7 +475,7 @@ static void vtx_slide_update(VertexSlideOp *vso, wmEvent *event)
                if (edge_len <= 0.0f)
                        edge_len = VTX_SLIDE_SNAP_THRSH;
 
                if (edge_len <= 0.0f)
                        edge_len = VTX_SLIDE_SNAP_THRSH;
 
-               edge_len =  (len_v3v3(edge->v1->co, edge->v2->co) * VTX_SLIDE_SNAP_THRSH) / edge_len;
+               edge_len =  (BM_edge_calc_length(edge) * VTX_SLIDE_SNAP_THRSH) / edge_len;
 
                vso->snap_threshold =  edge_len;
 
 
                vso->snap_threshold =  edge_len;
 
index 23348eed2b42a2231dae8da230840b76901a57d2..879e20fcf8ba5f5e79d3683d327e229c28a59d70 100644 (file)
@@ -153,19 +153,22 @@ void MESH_OT_subdivide(wmOperatorType *ot)
 }
 
 
 }
 
 
-void EMBM_project_snap_verts(bContext *C, ARegion *ar, Object *obedit, BMEditMesh *em)
+void EMBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em)
 {
 {
+       Object *obedit = em->ob;
        BMIter iter;
        BMVert *eve;
 
        BMIter iter;
        BMVert *eve;
 
+       ED_view3d_init_mats_rv3d(obedit, ar->regiondata);
+
        BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
                if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
        BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
                if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
-                       float mval[2], vec[3], no_dummy[3];
+                       float mval[2], co_proj[3], no_dummy[3];
                        int dist_dummy;
                        int dist_dummy;
-                       mul_v3_m4v3(vec, obedit->obmat, eve->co);
-                       ED_view3d_project_float_noclip(ar, vec, mval);
-                       if (snapObjectsContext(C, mval, &dist_dummy, vec, no_dummy, SNAP_NOT_OBEDIT)) {
-                               mul_v3_m4v3(eve->co, obedit->imat, vec);
+                       if (ED_view3d_project_float_object(ar, eve->co, mval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
+                               if (snapObjectsContext(C, mval, &dist_dummy, co_proj, no_dummy, SNAP_NOT_OBEDIT)) {
+                                       mul_v3_m4v3(eve->co, obedit->imat, co_proj);
+                               }
                        }
                }
        }
                        }
                }
        }
@@ -731,7 +734,10 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
        short use_proj;
        
        em_setup_viewcontext(C, &vc);
        short use_proj;
        
        em_setup_viewcontext(C, &vc);
-       
+
+       ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d);
+
+
        use_proj = ((vc.scene->toolsettings->snap_flag & SCE_SNAP) &&
                    (vc.scene->toolsettings->snap_mode == SCE_SNAP_MODE_FACE));
 
        use_proj = ((vc.scene->toolsettings->snap_flag & SCE_SNAP) &&
                    (vc.scene->toolsettings->snap_mode == SCE_SNAP_MODE_FACE));
 
@@ -760,26 +766,26 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
                BM_ITER_MESH (eed, &iter, vc.em->bm, BM_EDGES_OF_MESH) {
                        if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
                                float co1[3], co2[3];
                BM_ITER_MESH (eed, &iter, vc.em->bm, BM_EDGES_OF_MESH) {
                        if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
                                float co1[3], co2[3];
-                               mul_v3_m4v3(co1, vc.obedit->obmat, eed->v1->co);
-                               mul_v3_m4v3(co2, vc.obedit->obmat, eed->v2->co);
-                               ED_view3d_project_float_noclip(vc.ar, co1, co1);
-                               ED_view3d_project_float_noclip(vc.ar, co2, co2);
-
-                               /* 2D rotate by 90d while adding.
-                                *  (x, y) = (y, -x)
-                                *
-                                * accumulate the screenspace normal in 2D,
-                                * with screenspace edge length weighting the result. */
-                               if (line_point_side_v2(co1, co2, mval_f) >= 0.0f) {
-                                       nor[0] +=  (co1[1] - co2[1]);
-                                       nor[1] += -(co1[0] - co2[0]);
-                               }
-                               else {
-                                       nor[0] +=  (co2[1] - co1[1]);
-                                       nor[1] += -(co2[0] - co1[0]);
+
+                               if ((ED_view3d_project_float_object(vc.ar, eed->v1->co, co1, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) &&
+                                   (ED_view3d_project_float_object(vc.ar, eed->v2->co, co2, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS))
+                               {
+                                       /* 2D rotate by 90d while adding.
+                                        *  (x, y) = (y, -x)
+                                        *
+                                        * accumulate the screenspace normal in 2D,
+                                        * with screenspace edge length weighting the result. */
+                                       if (line_point_side_v2(co1, co2, mval_f) >= 0.0f) {
+                                               nor[0] +=  (co1[1] - co2[1]);
+                                               nor[1] += -(co1[0] - co2[0]);
+                                       }
+                                       else {
+                                               nor[0] +=  (co2[1] - co1[1]);
+                                               nor[1] += -(co2[0] - co1[0]);
+                                       }
+                                       done = TRUE;
                                }
                        }
                                }
                        }
-                       done = TRUE;
                }
 
                if (done) {
                }
 
                if (done) {
@@ -836,7 +842,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
 
                        /* also project the source, for retopo workflow */
                        if (use_proj)
 
                        /* also project the source, for retopo workflow */
                        if (use_proj)
-                               EMBM_project_snap_verts(C, vc.ar, vc.obedit, vc.em);
+                               EMBM_project_snap_verts(C, vc.ar, vc.em);
                }
 
                edbm_extrude_edge(vc.obedit, vc.em, BM_ELEM_SELECT, nor);
                }
 
                edbm_extrude_edge(vc.obedit, vc.em, BM_ELEM_SELECT, nor);
@@ -869,7 +875,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, wmEvent
        }
 
        if (use_proj)
        }
 
        if (use_proj)
-               EMBM_project_snap_verts(C, vc.ar, vc.obedit, vc.em);
+               EMBM_project_snap_verts(C, vc.ar, vc.em);
 
        /* This normally happens when pushing undo but modal operators
         * like this one don't push undo data until after modal mode is
 
        /* This normally happens when pushing undo but modal operators
         * like this one don't push undo data until after modal mode is
index ef826c07cc149a87feba62022a466b0f9557d2c2..42d82fff38e1a12ebdd21d7d0b808ba3093563a5 100644 (file)
@@ -1237,11 +1237,12 @@ int ED_mesh_pick_face_vert(bContext *C, Mesh *me, Object *ob, const int mval[2],
                                const int v_idx = me->mloop[mp->loopstart + fidx].v;
                                dm->getVertCo(dm, v_idx, co);
                                mul_m4_v3(ob->obmat, co);
                                const int v_idx = me->mloop[mp->loopstart + fidx].v;
                                dm->getVertCo(dm, v_idx, co);
                                mul_m4_v3(ob->obmat, co);
-                               ED_view3d_project_float_noclip(ar, co, sco);
-                               len = len_squared_v2v2(mval_f, sco);
-                               if (len < len_best) {
-                                       len_best = len;
-                                       v_idx_best = v_idx;
+                               if (ED_view3d_project_float_global(ar, co, sco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
+                                       len = len_squared_v2v2(mval_f, sco);
+                                       if (len < len_best) {
+                                               len_best = len;
+                                               v_idx_best = v_idx;
+                                       }
                                }
                        } while (fidx--);
                }
                                }
                        } while (fidx--);
                }
index 8aed92df3af6da118544863409a771618d0b257a..f1ee8f522d9787838b052439ae442207157e52dd 100644 (file)
@@ -846,20 +846,22 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x
 static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float vert_nor[3],
                                  const float mval[2], const float brush_size_pressure)
 {
 static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float vert_nor[3],
                                  const float mval[2], const float brush_size_pressure)
 {
-       Brush *brush = paint_brush(&vp->paint);
-       float dist_squared;
-       float vertco[2], delta[2];
+       float vertco[2];
 
 
-       ED_view3d_project_float_noclip(vc->ar, vert_nor, vertco);
-       sub_v2_v2v2(delta, mval, vertco);
-       dist_squared = dot_v2v2(delta, delta); /* len squared */
-       if (dist_squared > brush_size_pressure * brush_size_pressure) {
-               return 0.0f;
-       }
-       else {
-               const float dist = sqrtf(dist_squared);
-               return BKE_brush_curve_strength_clamp(brush, dist, brush_size_pressure);
+       if (ED_view3d_project_float_global(vc->ar, vert_nor, vertco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
+               float delta[2];
+               float dist_squared;
+
+               sub_v2_v2v2(delta, mval, vertco);
+               dist_squared = dot_v2v2(delta, delta); /* len squared */
+               if (dist_squared <= brush_size_pressure * brush_size_pressure) {
+                       Brush *brush = paint_brush(&vp->paint);
+                       const float dist = sqrtf(dist_squared);
+                       return BKE_brush_curve_strength_clamp(brush, dist, brush_size_pressure);
+               }
        }
        }
+
+       return 0.0f;
 }
 
 static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc,
 }
 
 static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc,
index 32392b2fd660101d3e08e14a8d79f7fcd8de81a5..631418598e52bebb0ac65682b0381e8fcc3c0016 100644 (file)
@@ -351,7 +351,11 @@ void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
                case SPACE_VIEW3D:
                {
                        if (t->ar->regiontype == RGN_TYPE_WINDOW) {
                case SPACE_VIEW3D:
                {
                        if (t->ar->regiontype == RGN_TYPE_WINDOW) {
-                               ED_view3d_project_float_noclip(t->ar, vec, adr);
+                               if (ED_view3d_project_float_global(t->ar, vec, adr, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_SUCCESS) {
+                                       /* XXX, 2.64 and prior did this, weak! */
+                                       adr[0] = t->ar->winx / 2.0f;
+                                       adr[1] = t->ar->winy / 2.0f;
+                               }
                                return;
                        }
                        break;
                                return;
                        }
                        break;
@@ -4793,12 +4797,12 @@ static void calcNonProportionalEdgeSlide(TransInfo *t, SlideData *sld, const flo
                        sv->edge_len = len_v3v3(dw_p, up_p);
 
                        mul_v3_m4v3(v_proj, t->obedit->obmat, sv->v->co);
                        sv->edge_len = len_v3v3(dw_p, up_p);
 
                        mul_v3_m4v3(v_proj, t->obedit->obmat, sv->v->co);
-                       ED_view3d_project_float_noclip(t->ar, v_proj, v_proj);
-
-                       dist = len_squared_v2v2(mval, v_proj);
-                       if (dist < min_dist) {
-                               min_dist = dist;
-                               sld->curr_sv_index = i;
+                       if (ED_view3d_project_float_global(t->ar, v_proj, v_proj, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
+                               dist = len_squared_v2v2(mval, v_proj);
+                               if (dist < min_dist) {
+                                       min_dist = dist;
+                                       sld->curr_sv_index = i;
+                               }
                        }
                }
        }
                        }
                }
        }