Merged changes in the trunk up to revision 46045.
[blender-staging.git] / source / blender / editors / space_view3d / drawobject.c
index 7ccf4b6c81aaf8543f4f1df273410e84367b458b..4c714b936183772511bb104399507dc59961c3ec 100644 (file)
@@ -152,7 +152,7 @@ typedef struct drawDMEdgesSel_userData {
 } drawDMEdgesSel_userData;
 
 typedef struct drawDMFacesSel_userData {
-       unsigned char *cols[3];
+       unsigned char *cols[4];
 
        DerivedMesh *dm; /* BMESH BRANCH ONLY */
        BMEditMesh *em;  /* BMESH BRANCH ONLY */
@@ -2213,7 +2213,7 @@ void nurbs_foreachScreenVert(
        short s[2] = {IS_CLIPPED, 0};
        Nurb *nu;
        int i;
-       ListBase *nurbs = curve_editnurbs(cu);
+       ListBase *nurbs = BKE_curve_editNurbs_get(cu);
 
        ED_view3d_clipping_local(vc->rv3d, vc->obedit->obmat); /* for local clipping lookups */
 
@@ -2504,6 +2504,21 @@ static void draw_dm_edges_sharp(BMEditMesh *em, DerivedMesh *dm)
        dm->drawMappedEdges(dm, draw_dm_edges_sharp__setDrawOptions, em);
 }
 
+/* Draw only Freestyle feature edges */
+static DMDrawOption draw_dm_edges_freestyle__setDrawOptions(void *userData, int index)
+{
+       BMEdge *eed = EDBM_edge_at_index(userData, index);
+
+       if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BM_elem_flag_test(eed, BM_ELEM_FREESTYLE))
+               return DM_DRAW_OPTION_NORMAL;
+       else
+               return DM_DRAW_OPTION_SKIP;
+}
+
+static void draw_dm_edges_freestyle(BMEditMesh *em, DerivedMesh *dm)
+{
+       dm->drawMappedEdges(dm, draw_dm_edges_freestyle__setDrawOptions, em);
+}
 
 /* Draw faces with color set based on selection
  * return 2 for the active face so it renders with stipple enabled */
@@ -2518,11 +2533,11 @@ static DMDrawOption draw_dm_faces_sel__setDrawOptions(void *userData, int index)
        
        if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
                if (efa == data->efa_act) {
-                       glColor4ubv(data->cols[2]);
+                       glColor4ubv(data->cols[3]);
                        return DM_DRAW_OPTION_STIPPLE;
                }
                else {
-                       col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
+                       col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : BM_elem_flag_test(efa, BM_ELEM_FREESTYLE) ? 2 : 0];
                        if (col[3] == 0)
                                return DM_DRAW_OPTION_SKIP;
                        glColor4ubv(col);
@@ -2553,8 +2568,8 @@ static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int
        if (efa == data->efa_act || next_efa == data->efa_act)
                return 0;
 
-       col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
-       next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : 0];
+       col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : BM_elem_flag_test(efa, BM_ELEM_FREESTYLE) ? 2 : 0];
+       next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : BM_elem_flag_test(next_efa, BM_ELEM_FREESTYLE) ? 2 : 0];
 
        if (col[3] == 0 || next_col[3] == 0)
                return 0;
@@ -2564,14 +2579,15 @@ static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int
 
 /* also draws the active face */
 static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol, 
-                              unsigned char *selCol, unsigned char *actCol, BMFace *efa_act)
+                              unsigned char *selCol, unsigned char *markCol, unsigned char *actCol, BMFace *efa_act)
 {
        drawDMFacesSel_userData data;
        data.dm = dm;
        data.cols[0] = baseCol;
        data.em = em;
        data.cols[1] = selCol;
-       data.cols[2] = actCol;
+       data.cols[2] = markCol;
+       data.cols[3] = actCol;
        data.efa_act = efa_act;
        data.orig_index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
 
@@ -2845,7 +2861,7 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, BMEditMesh *em, UnitS
        }
 
        if (me->drawflag & ME_DRAWEXTRA_FACEAREA) {
-               /* would be nice to use BM_face_area_calc, but that is for 2d faces
+               /* would be nice to use BM_face_calc_area, but that is for 2d faces
                 * so instead add up tessellation triangle areas */
                BMFace *f;
                int n;
@@ -2910,7 +2926,7 @@ static void draw_em_measure_stats(View3D *v3d, Object *ob, BMEditMesh *em, UnitS
                        BMIter liter;
                        BMLoop *loop;
 
-                       BM_face_center_bounds_calc(efa, vmid);
+                       BM_face_calc_center_bounds(efa, vmid);
 
                        for (loop = BM_iter_new(&liter, em->bm, BM_LOOPS_OF_FACE, efa);
                             loop; loop = BM_iter_step(&liter))
@@ -2984,7 +3000,7 @@ static void draw_em_indices(BMEditMesh *em)
                UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col);
                BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
                        if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
-                               BM_face_center_mean_calc(f, pos);
+                               BM_face_calc_center_mean(f, pos);
                                sprintf(numstr, "%d", i);
                                view3d_cached_text_draw_add(pos, numstr, 0, txt_flag, col);
                        }
@@ -3087,11 +3103,12 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d,
        }
        
        if (me->drawflag & ME_DRAWFACES) {  /* transp faces */
-               unsigned char col1[4], col2[4], col3[4];
+               unsigned char col1[4], col2[4], col3[4], col4[4];
 
                UI_GetThemeColor4ubv(TH_FACE, col1);
                UI_GetThemeColor4ubv(TH_FACE_SELECT, col2);
-               UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
+               UI_GetThemeColor4ubv(TH_FREESTYLE_FACE_MARK, col3);
+               UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col4);
                
                glEnable(GL_BLEND);
                glDepthMask(0);     // disable write in zbuffer, needed for nice transp
@@ -3100,7 +3117,10 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d,
                if (check_object_draw_texture(scene, v3d, dt))
                        col1[3] = 0;
                
-               draw_dm_faces_sel(em, cageDM, col1, col2, col3, efa_act);
+               if (!(me->drawflag & ME_DRAW_FREESTYLE_FACE))
+                       col3[3] = 0;
+
+               draw_dm_faces_sel(em, cageDM, col1, col2, col3, col4, efa_act);
 
                glDisable(GL_BLEND);
                glDepthMask(1);     // restore write in zbuffer
@@ -3109,14 +3129,14 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d,
                /* even if draw faces is off it would be nice to draw the stipple face
                 * Make all other faces zero alpha except for the active
                 * */
-               unsigned char col1[4], col2[4], col3[4];
-               col1[3] = col2[3] = 0; /* don't draw */
-               UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
+               unsigned char col1[4], col2[4], col3[4], col4[4];
+               col1[3] = col2[3] = col3[3] = 0; /* don't draw */
+               UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col4);
                
                glEnable(GL_BLEND);
                glDepthMask(0);     // disable write in zbuffer, needed for nice transp
                
-               draw_dm_faces_sel(em, cageDM, col1, col2, col3, efa_act);
+               draw_dm_faces_sel(em, cageDM, col1, col2, col3, col4, efa_act);
 
                glDisable(GL_BLEND);
                glDepthMask(1);     // restore write in zbuffer
@@ -3152,6 +3172,16 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d,
                        glLineWidth(1);
                }
 
+               if(me->drawflag & ME_DRAW_FREESTYLE_EDGE) {
+                       UI_ThemeColor(TH_FREESTYLE_EDGE_MARK);
+                       glLineWidth(2);
+       
+                       draw_dm_edges_freestyle(em, cageDM);
+       
+                       glColor3ub(0,0,0);
+                       glLineWidth(1);
+               }
+       
                if (me->drawflag & ME_DRAWCREASES && CustomData_has_layer(&em->bm->edata, CD_CREASE)) {
                        draw_dm_creases(em, cageDM);
                }
@@ -3306,7 +3336,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                }
        }
        else if (dt == OB_SOLID) {
-               if (is_obact && ob->mode & OB_MODE_WEIGHT_PAINT) {
+               if (is_obact && ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) {
                        /* weight paint in solid mode, special case. focus on making the weights clear
                         * rather than the shading, this is also forced in wire view */
                        GPU_enable_material(0, NULL);
@@ -3963,7 +3993,7 @@ static int drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *bas
                        break;
                case OB_MBALL:
 
-                       if (is_basis_mball(ob)) {
+                       if (BKE_metaball_is_basis(ob)) {
                                lb = &ob->disp;
                                if (lb->first == NULL) makeDispListMBall(scene, ob);
                                if (lb->first == NULL) return 1;
@@ -4341,8 +4371,8 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
                normalize_v3(imat[1]);
        }
 
-       if (ELEM3(draw_as, PART_DRAW_DOT, PART_DRAW_CROSS, PART_DRAW_LINE)
-           && part->draw_col > PART_DRAW_COL_MAT)
+       if (ELEM3(draw_as, PART_DRAW_DOT, PART_DRAW_CROSS, PART_DRAW_LINE) &&
+           (part->draw_col > PART_DRAW_COL_MAT))
        {
                create_cdata = 1;
        }
@@ -6140,7 +6170,7 @@ static void draw_bounding_volume(Scene *scene, Object *ob, char type)
                bb = ob->bb ? ob->bb : ( (Curve *)ob->data)->bb;
        }
        else if (ob->type == OB_MBALL) {
-               if (is_basis_mball(ob)) {
+               if (BKE_metaball_is_basis(ob)) {
                        bb = ob->bb;
                        if (bb == NULL) {
                                makeDispListMBall(scene, ob);
@@ -6231,7 +6261,7 @@ static void drawObjectSelect(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
                }
        }
        else if (ob->type == OB_MBALL) {
-               if (is_basis_mball(ob)) {
+               if (BKE_metaball_is_basis(ob)) {
                        if ((base->flag & OB_FROMDUPLI) == 0)
                                drawDispListwire(&ob->disp);
                }
@@ -6291,7 +6321,7 @@ static void drawWireExtra(Scene *scene, RegionView3D *rv3d, Object *ob)
                }
        }
        else if (ob->type == OB_MBALL) {
-               if (is_basis_mball(ob)) {
+               if (BKE_metaball_is_basis(ob)) {
                        drawDispListwire(&ob->disp);
                }
        }
@@ -6670,7 +6700,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        cu = ob->data;
 
                        if (cu->editnurb) {
-                               ListBase *nurbs = curve_editnurbs(cu);
+                               ListBase *nurbs = BKE_curve_editNurbs_get(cu);
                                drawnurb(scene, v3d, rv3d, base, nurbs->first, dt);
                        }
                        else if (dt == OB_BOUNDBOX) {