Merged changes in the trunk up to revision 41768.
[blender-staging.git] / source / blender / editors / space_view3d / drawobject.c
index e5797e1a14a46ec7f48ab5e10d317ef25dbb8a0f..70cdefddc7265500c2f1d8a2165ef914766be8b7 100644 (file)
@@ -36,6 +36,7 @@
 #include "DNA_camera_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_constraint_types.h" // for drawing constraint
+#include "DNA_dynamicpaint_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_material_types.h"
 
 /* this condition has been made more complex since editmode can draw textures */
 #define CHECK_OB_DRAWTEXTURE(vd, dt)                                          \
-       ((vd->drawtype==OB_TEXTURE && dt>OB_SOLID) ||                             \
+       ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt>OB_SOLID) ||          \
        (vd->drawtype==OB_SOLID && vd->flag2 & V3D_SOLID_TEX))
 
 static void draw_bounding_volume(Scene *scene, Object *ob, char type);
@@ -252,6 +253,8 @@ int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt)
                return 0;
        if(ob==OBACT && (ob && ob->mode & OB_MODE_WEIGHT_PAINT))
                return 0;
+       if(scene_use_new_shading_nodes(scene))
+               return 0;
        
        return (scene->gm.matmode == GAME_MAT_GLSL) && (dt > OB_SOLID);
 }
@@ -1476,7 +1479,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
 
                glPushMatrix();
                        glTranslatef(track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
-                       glScalef(v3d->bundle_size/0.05, v3d->bundle_size/0.05, v3d->bundle_size/0.05);
+                       glScalef(v3d->bundle_size/0.05f, v3d->bundle_size/0.05f, v3d->bundle_size/0.05f);
 
                        if(v3d->drawtype==OB_WIRE) {
                                glDisable(GL_LIGHTING);
@@ -1717,8 +1720,8 @@ static void drawspeaker(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionView3D
 
                glBegin(GL_LINE_LOOP);
                for(i = 0; i < 16; i++) {
-                       vec[0] = cosf(M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
-                       vec[1] = sinf(M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
+                       vec[0] = cosf((float)M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
+                       vec[1] = sinf((float)M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
                        glVertex3fv(vec);
                }
                glEnd();
@@ -2573,7 +2576,7 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
                                copy_v3_v3(v1, eed->v1->co);
                                copy_v3_v3(v2, eed->v2->co);
 
-                               interp_v3_v3v3(vmid, v1, v2, 0.5f);
+                               mid_v3_v3v3(vmid, v1, v2);
 
                                if(do_global) {
                                        mul_mat3_m4_v3(ob->obmat, v1);
@@ -2935,13 +2938,29 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        Mesh *me = ob->data;
        Material *ma= give_current_material(ob, 1);
        const short hasHaloMat = (ma && (ma->material_type == MA_TYPE_HALO));
-       const short is_paint_sel= (ob==OBACT && paint_facesel_test(ob));
        int draw_wire = 0;
        int /* totvert,*/ totedge, totface;
        DerivedMesh *dm= mesh_get_derived_final(scene, ob, scene->customdata_mask);
+       ModifierData *md = NULL;
+       int draw_flags = (ob==OBACT && paint_facesel_test(ob)) ? DRAW_FACE_SELECT : 0;
 
        if(!dm)
                return;
+
+       /* check to draw dynamic paint colors */
+       if ((md = modifiers_findByType(ob, eModifierType_DynamicPaint)))
+       {
+               /* check if target has an active dpaint modifier        */
+               if(md && (md->mode & eModifierMode_Realtime))                                   
+               {
+                       DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
+                       /* if canvas is ready to preview vertex colors */
+                       if (pmd->canvas && pmd->canvas->flags & MOD_DPAINT_PREVIEW_READY &&
+                               DM_get_face_data_layer(dm, CD_WEIGHT_MCOL)) {
+                               draw_flags |= DRAW_DYNAMIC_PAINT_PREVIEW;
+                       }
+               }
+       }
        
        if (ob->dtx&OB_DRAWWIRE) {
                draw_wire = 2; /* draw wire after solid using zoffset and depth buffer adjusment */
@@ -2955,7 +2974,7 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
 
                // Unwanted combination.
-       if (is_paint_sel) draw_wire = 0;
+       if (draw_flags & DRAW_FACE_SELECT) draw_wire = 0;
 
        if(dt==OB_BOUNDBOX) {
                if((v3d->flag2 & V3D_RENDER_OVERRIDE && v3d->drawtype >= OB_WIRE)==0)
@@ -2969,14 +2988,14 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
        else if(dt==OB_WIRE || totface==0) {
                draw_wire = 1; /* draw wire only, no depth buffer stuff  */
        }
-       else if(        (is_paint_sel || (ob==OBACT && ob->mode & OB_MODE_TEXTURE_PAINT)) ||
+       else if(        (draw_flags & DRAW_FACE_SELECT || (ob==OBACT && ob->mode & OB_MODE_TEXTURE_PAINT)) ||
                                CHECK_OB_DRAWTEXTURE(v3d, dt))
        {
-               if ((v3d->flag&V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && (base->flag&SELECT) && !(G.f&G_PICKSEL || is_paint_sel) && !draw_wire) {
+               if ((v3d->flag&V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && (base->flag&SELECT) && !(G.f&G_PICKSEL || (draw_flags & DRAW_FACE_SELECT)) && !draw_wire) {
                        draw_mesh_object_outline(v3d, ob, dm);
                }
 
-               if(draw_glsl_material(scene, ob, v3d, dt)) {
+               if(draw_glsl_material(scene, ob, v3d, dt) && !(draw_flags & DRAW_DYNAMIC_PAINT_PREVIEW)) {
                        glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
 
                        dm->drawFacesGLSL(dm, GPU_enable_material);
@@ -2987,10 +3006,10 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        glFrontFace(GL_CCW);
                }
                else {
-                       draw_mesh_textured(scene, v3d, rv3d, ob, dm, is_paint_sel);
+                       draw_mesh_textured(scene, v3d, rv3d, ob, dm, draw_flags);
                }
 
-               if(!is_paint_sel) {
+               if(!(draw_flags & DRAW_FACE_SELECT)) {
                        if(base->flag & SELECT)
                                UI_ThemeColor((ob==OBACT)?TH_ACTIVE:TH_SELECT);
                        else
@@ -3026,6 +3045,38 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        /* since we already draw wire as wp guide, dont draw over the top */
                        draw_wire= 0;
                }
+               else if (draw_flags & DRAW_DYNAMIC_PAINT_PREVIEW) {
+                       /* for object selection draws no shade */
+                       if (flag & (DRAW_PICKING|DRAW_CONSTCOLOR)) {
+                               dm->drawFacesSolid(dm, NULL, 0, GPU_enable_material);
+                       }
+                       else {
+                               /* draw outline */
+                               if((v3d->flag&V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE)==0) && (base->flag&SELECT) && !draw_wire && !ob->sculpt)
+                                       draw_mesh_object_outline(v3d, ob, dm);
+
+                               /* materials arent compatible with vertex colors */
+                               GPU_end_object_materials();
+
+                               GPU_enable_material(0, NULL);
+                               
+                               /* set default spec */
+                               glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
+                               glEnable(GL_COLOR_MATERIAL);    /* according manpages needed */
+                               glColor3ub(120, 120, 120);
+                               glDisable(GL_COLOR_MATERIAL);
+                               /* diffuse */
+                               glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
+                               glEnable(GL_LIGHTING);
+                               glEnable(GL_COLOR_MATERIAL);
+
+                               dm->drawMappedFaces(dm, NULL, NULL, 1, GPU_enable_material, NULL);
+                               glDisable(GL_COLOR_MATERIAL);
+                               glDisable(GL_LIGHTING);
+
+                               GPU_disable_material();
+                       }
+               }
                else {
                        Paint *p;