svn merge -r40197:40311 ^/trunk/blender
[blender.git] / source / blender / editors / space_view3d / drawobject.c
index 0e8e6cd..5bbc6a2 100644 (file)
@@ -77,6 +77,7 @@
 #include "BKE_pointcache.h"
 #include "BKE_unit.h"
 
+
 #include "smoke_API.h"
 
 #include "IMB_imbuf.h"
@@ -85,6 +86,7 @@
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
+#include "GPU_buffers.h"// Jason
 #include "GPU_draw.h"
 #include "GPU_extensions.h"
 
@@ -1739,7 +1741,71 @@ void mesh_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, EditVe
 
        dm->release(dm);
 }
+/*Jason */
+static void mesh_obmode_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s))
+{
+       struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData;
+       Mesh *me = data->vc.obact->data;
+       MVert *mv = me->mvert+index;
+       //MVert *dmv = CDDM_get_verts(data->vc.obact->derivedFinal)+index;
+       //MVert *mv = CDDM_get_verts(data->vc.obact->derivedFinal)+index;
+       if ((mv->flag & ME_HIDE)==0) {
+               short s[2]= {IS_CLIPPED, 0};
+
+               if (data->clipVerts) {
+                       view3d_project_short_clip(data->vc.ar, co, s, 1);
+               } else {
+                       view3d_project_short_noclip(data->vc.ar, co, s);
+               }
+
+               if (s[0]!=IS_CLIPPED)
+                       data->func(data->userData, mv, s[0], s[1], index);
+       }
+}
+/*Jason*/
+void mesh_obmode_foreachScreenVert(ViewContext *vc, void (*func)(void *userData, MVert *mv, int x, int y, int index), void *userData, int clipVerts)
+{
+       struct { void (*func)(void *userData, MVert *mv, int x, int y, int index); void *userData; ViewContext vc; int clipVerts; } data;
+       DerivedMesh *dm = mesh_get_derived_final(vc->scene, vc->obact, CD_MASK_BAREMESH);
 
+       data.vc= *vc;
+       data.func = func;
+       data.userData = userData;
+       data.clipVerts = clipVerts;
+       
+       if(clipVerts)
+               ED_view3d_local_clipping(vc->rv3d, vc->obact->obmat); /* for local clipping lookups */
+
+       dm->foreachMappedVert(dm, mesh_obmode_foreachScreenVert__mapFunc, &data);
+
+       dm->release(dm);
+}
+
+/* Jason draw callback */
+static void drawSelectedVertices__mapFunc(void *userData, int index, float *co, float *no_f, short *no_s)
+{
+       MVert *mv = userData;
+       mv+=index;
+       //printf("%d\n", index);
+       if(!(mv->flag & ME_HIDE)) {
+               const char sel= mv->flag & 1;
+
+               // TODO define selected color
+               if(sel) {
+                       glColor3f(1.0f, 1.0f, 0.0f);
+               }else {
+                       glColor3f(0.0f, 0.0f, 0.0f);
+               }
+
+               glVertex3fv(co);
+       }
+}
+/* Jason */
+static void drawSelectedVertices(DerivedMesh *dm, Mesh *me) {
+       glBegin(GL_POINTS);
+       dm->foreachMappedVert(dm, drawSelectedVertices__mapFunc, me->mvert);
+       glEnd();
+}
 static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0co, float *v1co)
 {
        struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; ViewContext vc; int clipVerts; } *data = userData;
@@ -2924,7 +2990,16 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
                        bglPolygonOffset(rv3d->dist, 0.0);
                }
        }
-
+       // Jason
+       if(paint_vertsel_test(ob)) {
+               
+               glColor3f(0.0f, 0.0f, 0.0f);
+               glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
+               
+               drawSelectedVertices(dm, ob->data);
+               
+               glPointSize(1.0f);
+       }
        dm->release(dm);
 }
 
@@ -6515,6 +6590,32 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
 }
 
 /* ***************** BACKBUF SEL (BBS) ********* */
+/* Jason */
+static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s))
+{
+       struct {void* offset; MVert *mvert;} *data = userData;
+       MVert *mv = data->mvert+index;
+       int offset = (intptr_t) data->offset;
+
+       if (!(mv->flag & ME_HIDE)) {
+               WM_set_framebuffer_index_color(offset+index);
+               bglVertex3fv(co);
+       }
+}
+/* Jason */
+static void bbs_obmode_mesh_verts(Object *ob, DerivedMesh *dm, int offset)
+{
+       struct {void* offset; struct MVert *mvert;} data;
+       Mesh *me = ob->data;
+       MVert *mvert = me->mvert;
+       data.mvert = mvert;
+       data.offset = (void*)(intptr_t) offset;
+       glPointSize( UI_GetThemeValuef(TH_VERTEX_SIZE) );
+       bglBegin(GL_POINTS);
+       dm->foreachMappedVert(dm, bbs_obmode_mesh_verts__mapFunc, &data);
+       bglEnd();
+       glPointSize(1.0);
+}
 
 static void bbs_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s))
 {
@@ -6613,7 +6714,18 @@ static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index, int *UNUS
                return 0;
        }
 }
+/* Jason */
+// must have called WM_set_framebuffer_index_color beforehand
+static int bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index, int *UNUSED(drawSmooth_r))
+{
+       Mesh *me = userData;
 
+       if (!(me->mface[index].flag&ME_HIDE)) {
+               return 1;
+       } else {
+               return 0;
+       }
+}
 static void bbs_mesh_solid(Scene *scene, Object *ob)
 {
        DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
@@ -6672,7 +6784,21 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
                        EM_free_index_arrays();
                }
                else {
-                       bbs_mesh_solid(scene, ob);
+                       Mesh *me= ob->data;
+                       if(me->editflag & ME_EDIT_VERT_SEL) {
+                               DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
+                               glColor3ub(0, 0, 0);
+
+                               dm->drawMappedFaces(dm, bbs_mesh_solid_hide2__setDrawOpts, me, 0, GPU_enable_material, NULL);
+
+                               
+                               bbs_obmode_mesh_verts(ob, dm, 1);
+                               em_vertoffs = me->totvert+1;
+                               dm->release(dm);
+                       }
+                       else {
+                               bbs_mesh_solid(scene, ob);
+                       }
                }
                break;
        case OB_CURVE: