diff options
author | Daniel Dunbar <daniel@zuster.org> | 2005-03-28 10:46:21 +0400 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2005-03-28 10:46:21 +0400 |
commit | 8acfd730cff7f338386b0c99b660bb6412792803 (patch) | |
tree | f1690e25c40f6efd87b1f0c70168f0df27fbd858 /source | |
parent | 09596b04a56632f5a63ede5e2a9feb5a4f2288b2 (diff) |
- added drawMapped{Verts,Edges,Faces}EMSelect calls to DerivedMesh with
implementations
- updated drawobject selection code to use DerivedMesh (last DispListMesh
usage in drawobject.c that needs to be replaced! Woot!)
- interface could still be a lot cleaner, mostly calculating indices for
the various things to pass to selection color routine is hacky.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 16 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 130 | ||||
-rw-r--r-- | source/blender/src/drawobject.c | 178 | ||||
-rw-r--r-- | source/blender/src/editmesh_mods.c | 10 |
4 files changed, 168 insertions, 166 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 8146cdea349..e66b36d9518 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -105,6 +105,14 @@ struct DerivedMesh { */ void (*drawFacesEM)(DerivedMesh *dm, int useColor, unsigned char *baseCol, unsigned char *selCol); + /* Draw mapped verts as bgl points + * o Call setColor(offset+index) for each vert, where index is the + * vert's index in the EditMesh. Return offset+count where count + * is the total number of mapped verts. + * o Only if mapped EditVert->h==0 + */ + int (*drawMappedVertsEMSelect)(DerivedMesh *dm, void (*setColor)(int index), int offset); + /* Draw mapped edges as lines * o Call setColor(offset+index) for each edge, where index is the * edge's index in the EditMesh. Return offset+count where count @@ -113,6 +121,14 @@ struct DerivedMesh { */ int (*drawMappedEdgesEMSelect)(DerivedMesh *dm, void (*setColor)(int index), int offset); + /* Draw mapped faces + * o Call setColor(offset+index) for each face, where index is the + * face's index in the EditMesh. Return offset+count where count + * is the total number of mapped faces. + * o Only if mapped EditFace->h==0 + */ + int (*drawMappedFacesEMSelect)(DerivedMesh *dm, void (*setColor)(int index), int offset); + void (*release)(DerivedMesh *dm); }; diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 802c718145c..1245d1bec3b 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -393,12 +393,15 @@ static DerivedMesh *getMeshDerivedMesh(Object *ob, float *extverts, float *nors) mdm->dm.drawVerts = meshDM_drawVerts; mdm->dm.drawMappedVertsEM = NULL; + mdm->dm.drawMappedVertsEMSelect = NULL; mdm->dm.drawEdges = meshDM_drawEdges; mdm->dm.drawMappedEdges = meshDM_drawEdges; mdm->dm.drawLooseEdges = meshDM_drawLooseEdges; mdm->dm.drawMappedEdgeEM = NULL; mdm->dm.drawMappedEdgesEM = NULL; + mdm->dm.drawMappedEdgesEMSelect = NULL; + mdm->dm.drawMappedFacesEMSelect = NULL; mdm->dm.drawFacesSolid = meshDM_drawFacesSolid; mdm->dm.drawFacesColored = meshDM_drawFacesColored; @@ -433,6 +436,23 @@ static void emDM_drawMappedVertsEM(DerivedMesh *dm, int sel) } bglEnd(); } +static int emDM_drawMappedVertsEMSelect(DerivedMesh *dm, void (*setColor)(int index), int offset) +{ + EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm; + EditVert *eve; + int i = offset; + + bglBegin(GL_POINTS); + for(eve= emdm->em->verts.first; eve; eve= eve->next, i++) { + if(eve->h==0) { + setColor(i); + bglVertex3fv(eve->co); + } + } + bglEnd(); + + return i; +} static void emDM_drawMappedEdgeEM(DerivedMesh *dm, void *edge) { EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm; @@ -465,6 +485,25 @@ static void emDM_drawMappedEdgesEM(DerivedMesh *dm, int useColor, char *baseCol, } glEnd(); } +static int emDM_drawMappedEdgesEMSelect(DerivedMesh *dm, void (*setColor)(int index), int offset) +{ + EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm; + EditEdge *eed; + int i; + + i = offset; + glBegin(GL_LINES); + for(eed= emdm->em->edges.first; eed; eed= eed->next, i++) { + if (eed->h==0) { + setColor(i); + glVertex3fv(eed->v1->co); + glVertex3fv(eed->v2->co); + } + } + glEnd(); + + return i; +} static void emDM_drawFacesEM(DerivedMesh *dm, int useColor, unsigned char *baseCol, unsigned char *selCol) { EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm; @@ -485,35 +524,35 @@ static void emDM_drawFacesEM(DerivedMesh *dm, int useColor, unsigned char *baseC } } } -static int emDM_drawMappedEdgesEMSelect(DerivedMesh *dm, void (*setColor)(int index), int offset) +static void emDM_drawFacesSolid(DerivedMesh *dm, void (*setMaterial)(int)) { EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm; - EditEdge *eed; - int i; + EditFace *efa; - i = offset; - glBegin(GL_LINES); - for(eed= emdm->em->edges.first; eed; eed= eed->next, i++) { - if (eed->h==0) { - setColor(i); - glVertex3fv(eed->v1->co); - glVertex3fv(eed->v2->co); + for (efa= emdm->em->faces.first; efa; efa= efa->next) { + if(efa->h==0) { + setMaterial(efa->mat_nr+1); + + glNormal3fv(efa->n); + glBegin(efa->v4?GL_QUADS:GL_TRIANGLES); + glVertex3fv(efa->v1->co); + glVertex3fv(efa->v2->co); + glVertex3fv(efa->v3->co); + if(efa->v4) glVertex3fv(efa->v4->co); + glEnd(); } } - glEnd(); - - return i; } -static void emDM_drawFacesSolid(DerivedMesh *dm, void (*setMaterial)(int)) +static int emDM_drawMappedFacesEMSelect(DerivedMesh *dm, void (*setColor)(int index), int offset) { EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm; EditFace *efa; + int i = offset; - for (efa= emdm->em->faces.first; efa; efa= efa->next) { - if(efa->h==0) { - setMaterial(efa->mat_nr+1); + for (efa= emdm->em->faces.first; efa; efa= efa->next, i++) { + if (efa->h==0) { + setColor(i); - glNormal3fv(efa->n); glBegin(efa->v4?GL_QUADS:GL_TRIANGLES); glVertex3fv(efa->v1->co); glVertex3fv(efa->v2->co); @@ -522,6 +561,8 @@ static void emDM_drawFacesSolid(DerivedMesh *dm, void (*setMaterial)(int)) glEnd(); } } + + return i; } static int emDM_getNumVerts(DerivedMesh *dm) @@ -554,6 +595,7 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em) emdm->dm.drawVerts = NULL; emdm->dm.drawMappedVertsEM = emDM_drawMappedVertsEM; + emdm->dm.drawMappedVertsEMSelect = emDM_drawMappedVertsEMSelect; emdm->dm.drawEdges = NULL; emdm->dm.drawMappedEdges = NULL; @@ -561,6 +603,7 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em) emdm->dm.drawMappedEdgeEM = emDM_drawMappedEdgeEM; emdm->dm.drawMappedEdgesEM = emDM_drawMappedEdgesEM; emdm->dm.drawMappedEdgesEMSelect = emDM_drawMappedEdgesEMSelect; + emdm->dm.drawMappedFacesEMSelect = emDM_drawMappedFacesEMSelect; emdm->dm.drawFacesSolid = emDM_drawFacesSolid; emdm->dm.drawFacesColored = NULL; @@ -595,6 +638,23 @@ static void ssDM_drawMappedVertsEM(DerivedMesh *dm, int sel) } bglEnd(); } +static int ssDM_drawMappedVertsEMSelect(DerivedMesh *dm, void (*setColor)(int index), int offset) +{ + SSDerivedMesh *ssdm = (SSDerivedMesh*) dm; + EditVert *eve; + int i = offset; + + bglBegin(GL_POINTS); + for(eve= ssdm->em->verts.first; eve; eve= eve->next, i++) { + if(eve->h==0 && eve->ssco) { + setColor(i); + bglVertex3fv(eve->ssco); + } + } + bglEnd(); + + return i; +} static void ssDM_drawMappedEdges(DerivedMesh *dm) { @@ -868,6 +928,36 @@ static void ssDM_drawFacesEM(DerivedMesh *dm, int useColor, unsigned char *baseC } } } +static int ssDM_drawMappedFacesEMSelect(DerivedMesh *dm, void (*setColor)(int index), int offset) +{ + SSDerivedMesh *ssdm = (SSDerivedMesh*) dm; + DispListMesh *dlm = ssdm->dlm; + MFace *mface= dlm->mface; + int i, endOffset; + EditFace *prevefa, *efa; + + for (i=offset, efa=ssdm->em->faces.first; efa; efa= efa->next, i++) + efa->prev = (EditFace*) i; + endOffset = i; + + for(i=0; i<dlm->totface; i++, mface++) { + if(mface->v3 && dlm->editface[i]->h==0) { + setColor((int) dlm->editface[i]->prev); + + glBegin(mface->v4?GL_QUADS:GL_TRIANGLES); + glVertex3fv(dlm->mvert[mface->v1].co); + glVertex3fv(dlm->mvert[mface->v2].co); + glVertex3fv(dlm->mvert[mface->v3].co); + if (mface->v4) glVertex3fv(dlm->mvert[mface->v4].co); + glEnd(); + } + } + + for (prevefa= NULL, efa= ssdm->em->faces.first; efa; prevefa= efa, efa= efa->next) + efa->prev= prevefa; + + return endOffset; +} static int ssDM_getNumVerts(DerivedMesh *dm) { @@ -899,6 +989,7 @@ static DerivedMesh *getSSDerivedMesh(EditMesh *em, DispListMesh *dlm, float *nor ssdm->dm.drawVerts = ssDM_drawVerts; ssdm->dm.drawMappedVertsEM = ssDM_drawMappedVertsEM; + ssdm->dm.drawMappedVertsEMSelect = ssDM_drawMappedVertsEMSelect; ssdm->dm.drawEdges = ssDM_drawEdges; ssdm->dm.drawMappedEdges = ssDM_drawMappedEdges; @@ -906,6 +997,7 @@ static DerivedMesh *getSSDerivedMesh(EditMesh *em, DispListMesh *dlm, float *nor ssdm->dm.drawMappedEdgeEM = ssDM_drawMappedEdgeEM; ssdm->dm.drawMappedEdgesEM = ssDM_drawMappedEdgesEM; ssdm->dm.drawMappedEdgesEMSelect = ssDM_drawMappedEdgesEMSelect; + ssdm->dm.drawMappedFacesEMSelect = ssDM_drawMappedFacesEMSelect; ssdm->dm.drawFacesSolid = ssDM_drawFacesSolid; ssdm->dm.drawFacesColored = ssDM_drawFacesColored; @@ -984,7 +1076,7 @@ DerivedMesh *mesh_get_base_derived(Object *ob) DerivedMesh *mesh_get_cage_derived(struct Object *ob) { Mesh *me= ob->data; - DerivedMesh *dm; + DerivedMesh *dm = NULL; if (me->flag&ME_OPT_EDGES) { dm = mesh_get_derived(ob); diff --git a/source/blender/src/drawobject.c b/source/blender/src/drawobject.c index ef12f3a84e2..846ba6be5bd 100644 --- a/source/blender/src/drawobject.c +++ b/source/blender/src/drawobject.c @@ -3646,162 +3646,61 @@ void draw_object_ext(Base *base) /* ***************** BACKBUF SEL (BBS) ********* */ -static int bbs_mesh_verts(Object *ob, int offset) +static int bbs_mesh_verts(DerivedMesh *dm, int offset) { - EditVert *eve; - int a= offset, optimal= subsurf_optimal(ob); + int retval; glPointSize( BIF_GetThemeValuef(TH_VERTEX_SIZE) ); - - bglBegin(GL_POINTS); - for(eve= G.editMesh->verts.first; eve; eve= eve->next, a++) { - if(eve->h==0) { - set_framebuffer_index_color(a); - if(optimal && eve->ssco) bglVertex3fv(eve->ssco); - else bglVertex3fv(eve->co); - } - } - bglEnd(); - + retval = dm->drawMappedVertsEMSelect(dm, set_framebuffer_index_color, offset); glPointSize(1.0); - return a; + + return retval; } -/* two options, edgecolors or black */ -static int bbs_mesh_wire(Object *ob, int offset) +static int bbs_mesh_wire(DerivedMesh *dm, int offset) { - EditEdge *eed; - Mesh *me= ob->data; - DispList *dl= find_displist(&me->disp, DL_MESH); - DispListMesh *dlm= NULL; // DISPLISTKILL - int index, b, retval, optimal=0; - - if(dl) dlm= dl->mesh; - optimal= subsurf_optimal(ob); - - if(dlm && optimal) { - MEdge *medge= dlm->medge; - MVert *mvert= dlm->mvert; - - // tuck original indices in vn - for(b=0, eed= G.editMesh->edges.first; eed; eed= eed->next, b++) eed->vn= (EditVert *)(b+offset); - retval= b+offset; - glBegin(GL_LINES); - for (b=0; b<dlm->totedge; b++, medge++) { - if(medge->flag & ME_EDGEDRAW) { - eed= dlm->editedge[b]; - if(eed && eed->h==0) { - set_framebuffer_index_color((int)eed->vn); - - glVertex3fv(mvert[medge->v1].co); - glVertex3fv(mvert[medge->v2].co); - } - } - } - glEnd(); - } - else { - index= offset; - cpack(0); - glBegin(GL_LINES); - for(eed= G.editMesh->edges.first; eed; eed= eed->next, index++) { - if(eed->h==0) { - - set_framebuffer_index_color(index); - - glVertex3fv(eed->v1->co); - glVertex3fv(eed->v2->co); - } - } - glEnd(); - retval= index; - } - return retval; + return dm->drawMappedEdgesEMSelect(dm, set_framebuffer_index_color, offset); } /* two options, facecolors or black */ -static int bbs_mesh_solid(Object *ob, int facecol) +static int bbs_mesh_solid(Object *ob, DerivedMesh *dm, int facecol) { int glmode, a; cpack(0); if(ob==G.obedit) { - Mesh *me= ob->data; - EditFace *efa; - DispList *dl= find_displist(&me->disp, DL_MESH); - DispListMesh *dlm= NULL; // DISPLISTKILL - int b; - - if(dl) dlm= dl->mesh; - a= 0; - - if(dlm && dlm->editface) { - EditFace *prevefa; - MFace *mface; - efa= NULL; - - // tuck original indices in efa->prev - for(b=1, efa= G.editMesh->faces.first; efa; efa= efa->next, b++) efa->prev= (EditFace *)(b); - a= b+1; // correct return value, next loop excludes hidden faces - - for(b=0, mface= dlm->mface; b<dlm->totface; b++, mface++) { - if(mface->v3) { - if(facecol) { - efa= dlm->editface[b]; - set_framebuffer_index_color((int)efa->prev); - } - - glBegin(mface->v4?GL_QUADS:GL_TRIANGLES); - glVertex3fv(dlm->mvert[mface->v1].co); - glVertex3fv(dlm->mvert[mface->v2].co); - glVertex3fv(dlm->mvert[mface->v3].co); - if (mface->v4) glVertex3fv(dlm->mvert[mface->v4].co); - glEnd(); - } - } - - if(facecol && (G.scene->selectmode & SCE_SELECT_FACE)) { + if (facecol) { + EditFace *efa, *prevefa; + int b; + + dm->drawMappedFacesEMSelect(dm, set_framebuffer_index_color, 1); + + // tuck original indices in efa->prev + for(b=1, efa= G.editMesh->faces.first; efa; efa= efa->next, b++) + efa->prev= (EditFace *)(b); + a = b; + + if(G.scene->selectmode & SCE_SELECT_FACE) { glPointSize(BIF_GetThemeValuef(TH_FACEDOT_SIZE)); bglBegin(GL_POINTS); for(efa= G.editMesh->faces.first; efa; efa= efa->next) { - if(efa->h==0) { - if(efa->fgonf==EM_FGON); - else { - set_framebuffer_index_color((int)efa->prev); - bglVertex3fv(efa->cent); - } + if(efa->h==0 && efa->fgonf!=EM_FGON) { + set_framebuffer_index_color((int)efa->prev); + bglVertex3fv(efa->cent); } } bglEnd(); } - + for (prevefa= NULL, efa= G.editMesh->faces.first; efa; prevefa= efa, efa= efa->next) efa->prev= prevefa; - - } - else { - a= 1; - glBegin(GL_QUADS); - glmode= GL_QUADS; - for(efa= G.editMesh->faces.first; efa; efa= efa->next, a++) { - if(efa->h==0) { - if(efa->v4) {if(glmode==GL_TRIANGLES) {glmode= GL_QUADS; glEnd(); glBegin(GL_QUADS);}} - else {if(glmode==GL_QUADS) {glmode= GL_TRIANGLES; glEnd(); glBegin(GL_TRIANGLES);}} - - if(facecol) { - set_framebuffer_index_color(a); - } - glVertex3fv(efa->v1->co); - glVertex3fv(efa->v2->co); - glVertex3fv(efa->v3->co); - if(efa->v4) glVertex3fv(efa->v4->co); - } - } - glEnd(); + return a; + } else { + dm->drawFacesEM(dm, 0, NULL, NULL); + return 1; } - if(facecol) return a; } else { Mesh *me= ob->data; @@ -3810,7 +3709,7 @@ static int bbs_mesh_solid(Object *ob, int facecol) TFace *tface; DispList *dl; float *extverts=NULL; - int a, totface, hastface, i; + int a, totface, hastface; mvert= me->mvert; mface= me->mface; @@ -3849,14 +3748,15 @@ static int bbs_mesh_solid(Object *ob, int facecol) } } glEnd(); + return 1; } - return 1; } void draw_object_backbufsel(Object *ob) { extern int em_solidoffs, em_wireoffs, em_vertoffs; // let linker solve it... from editmesh_mods.c - + DerivedMesh *dm; + mymultmatrix(ob->obmat); glClearDepth(1.0); glClear(GL_DEPTH_BUFFER_BIT); @@ -3864,23 +3764,25 @@ void draw_object_backbufsel(Object *ob) switch( ob->type) { case OB_MESH: - if(G.obedit) { + dm = mesh_get_cage_derived(ob); - em_solidoffs= bbs_mesh_solid(ob, G.scene->selectmode & SCE_SELECT_FACE); + if(G.obedit) { + em_solidoffs= bbs_mesh_solid(ob, dm, G.scene->selectmode & SCE_SELECT_FACE); bglPolygonOffset(1.0); // we draw edges always, for loop (select) tools - em_wireoffs= bbs_mesh_wire(ob, em_solidoffs); + em_wireoffs= bbs_mesh_wire(dm, em_solidoffs); if(G.scene->selectmode & SCE_SELECT_VERTEX) - em_vertoffs= bbs_mesh_verts(ob, em_wireoffs); + em_vertoffs= bbs_mesh_verts(dm, em_wireoffs); else em_vertoffs= em_wireoffs; bglPolygonOffset(0.0); } - else bbs_mesh_solid(ob, 1); // 1= facecol, faceselect - + else bbs_mesh_solid(ob, dm, 1); // 1= facecol, faceselect + + dm->release(dm); break; case OB_CURVE: case OB_SURF: diff --git a/source/blender/src/editmesh_mods.c b/source/blender/src/editmesh_mods.c index fc9bdaade65..f883be68293 100644 --- a/source/blender/src/editmesh_mods.c +++ b/source/blender/src/editmesh_mods.c @@ -629,15 +629,7 @@ static EditFace *findnearestface(short *dist) static void unified_select_draw(EditVert *eve, EditEdge *eed, EditFace *efa) { int optimal= subsurf_optimal(G.obedit); - DerivedMesh *dm = NULL; - Mesh *me = G.obedit->data; - - if (me->flag&ME_OPT_EDGES) { - dm = mesh_get_derived(G.obedit); - } - if (!dm) { - dm = mesh_get_base_derived(G.obedit); - } + DerivedMesh *dm = mesh_get_cage_derived(G.obedit); glDrawBuffer(GL_FRONT); |