diff options
author | Daniel Dunbar <daniel@zuster.org> | 2005-03-28 12:17:51 +0400 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2005-03-28 12:17:51 +0400 |
commit | 6a8fb8bf6c691428b089f2c6cc12ad41f1295c93 (patch) | |
tree | 34c2aa3a5c16f6b92ffdcee90877eddb200e01f6 /source/blender | |
parent | 0c05224a15cfcc7ae1fe2cd2010be95b8820ddf0 (diff) |
- added nors to DispListMesh (for face normals)... this is just to
avoid throwing them on later with addnormalsdisplist which is just
silly and burdensome.
- renamed displist_calc_vert_normals to displist_calc_normals
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_displist.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/displist.c | 97 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 2 |
6 files changed, 51 insertions, 67 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 5e210cb3589..02bfe2a44f9 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -1,5 +1,5 @@ /** - * $$ + * $Id$ * * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** * @@ -39,6 +39,8 @@ * determines whether to draw the edge (this predicate can * also set color, etc). This will be slightly more general * and allow some of the functions to be collapsed. + * o Once accessor functions are added then single element draw + * functions can be implemented using primitive accessors. */ struct Object; diff --git a/source/blender/blenkernel/BKE_displist.h b/source/blender/blenkernel/BKE_displist.h index 7ae1ac664e3..0146d1a2341 100644 --- a/source/blender/blenkernel/BKE_displist.h +++ b/source/blender/blenkernel/BKE_displist.h @@ -100,11 +100,12 @@ struct DispListMesh { struct TFace *tface; struct EditEdge **editedge; // added for subsurf, drawobject.c struct EditFace **editface; // added for subsurf, drawobject.c + float *nors; // facenormals int flag; }; void displistmesh_free(DispListMesh *dlm); -void displistmesh_calc_vert_normals(DispListMesh *dlm); +void displistmesh_calc_normals(DispListMesh *dlm); void displistmesh_to_mesh(DispListMesh *dlm, struct Mesh *me); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 9b18a46a32c..175dee4889e 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -642,7 +642,6 @@ typedef struct { DispListMesh *dlm; EditMesh *em; - float *nors; } SSDerivedMesh; static void ssDM_getMappedVertCoEM(DerivedMesh *dm, void *vert, float co_r[3]) @@ -843,7 +842,7 @@ static void ssDM_drawFacesSolid(DerivedMesh *dm, void (*setMaterial)(int)) { SSDerivedMesh *ssdm = (SSDerivedMesh*) dm; DispListMesh *dlm = ssdm->dlm; - float *nors = ssdm->nors; + float *nors = dlm->nors; int glmode=-1, shademodel=-1, matnr=-1; int i; @@ -1014,7 +1013,7 @@ static DispListMesh *ssDM_convertToDispListMesh(DerivedMesh *dm) return displistmesh_copy(ssdm->dlm); } -static DerivedMesh *getSSDerivedMesh(EditMesh *em, DispListMesh *dlm, float *nors) +static DerivedMesh *getSSDerivedMesh(EditMesh *em, DispListMesh *dlm) { SSDerivedMesh *ssdm = MEM_mallocN(sizeof(*ssdm), "dm"); @@ -1044,7 +1043,6 @@ static DerivedMesh *getSSDerivedMesh(EditMesh *em, DispListMesh *dlm, float *nor ssdm->dlm = dlm; ssdm->em = em; - ssdm->nors = nors; return (DerivedMesh*) ssdm; } @@ -1085,9 +1083,9 @@ DerivedMesh *mesh_get_derived(Object *ob) dl= find_displist(&me->disp, DL_MESH); if(G.obedit && me==G.obedit->data) { - return getSSDerivedMesh(G.editMesh, dl->mesh, dl->nors); + return getSSDerivedMesh(G.editMesh, dl->mesh); } else { - return getSSDerivedMesh(NULL, dl->mesh, dl->nors); + return getSSDerivedMesh(NULL, dl->mesh); } } else { return NULL; diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 98bc929d3f8..d348777bd0b 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -169,7 +169,7 @@ DispListMesh *displistmesh_from_editmesh(EditMesh *em) for (evePrev=NULL, eve= em->verts.first; eve; evePrev=eve, eve= eve->next) eve->prev= evePrev; - displistmesh_calc_vert_normals(dlm); + displistmesh_calc_normals(dlm); return dlm; } @@ -217,6 +217,7 @@ void displistmesh_free(DispListMesh *dlm) if (dlm->tface) MEM_freeN(dlm->tface); if (dlm->editedge) MEM_freeN(dlm->editedge); if (dlm->editface) MEM_freeN(dlm->editface); + if (dlm->nors) MEM_freeN(dlm->nors); MEM_freeN(dlm); } @@ -226,24 +227,29 @@ DispListMesh *displistmesh_copy(DispListMesh *odlm) ndlm->mvert= MEM_dupallocN(odlm->mvert); ndlm->medge= MEM_dupallocN(odlm->medge); ndlm->mface= MEM_dupallocN(odlm->mface); + if (odlm->nors) ndlm->nors = MEM_dupallocN(odlm->nors); if (odlm->mcol) ndlm->mcol= MEM_dupallocN(odlm->mcol); if (odlm->tface) ndlm->tface= MEM_dupallocN(odlm->tface); return ndlm; } -void displistmesh_calc_vert_normals(DispListMesh *dlm) +void displistmesh_calc_normals(DispListMesh *dlm) { MVert *mverts= dlm->mvert; - int nmverts= dlm->totvert; MFace *mfaces= dlm->mface; - int nmfaces= dlm->totface; - float (*tnorms)[3]= MEM_callocN(nmverts*sizeof(*tnorms), "tnorms"); + float (*tnorms)[3]= MEM_callocN(dlm->totvert*sizeof(*tnorms), "tnorms"); int i; - for (i=0; i<nmfaces; i++) { + if (dlm->nors) { + MEM_freeN(dlm->nors); + } + + dlm->nors= MEM_mallocN(sizeof(*dlm->nors)*3*dlm->totface, "meshnormals"); + + for (i=0; i<dlm->totface; i++) { MFace *mf= &mfaces[i]; - float f_no[3]; + float *f_no= &dlm->nors[i*3]; if (!mf->v3) continue; @@ -259,7 +265,7 @@ void displistmesh_calc_vert_normals(DispListMesh *dlm) if (mf->v4) VecAddf(tnorms[mf->v4], tnorms[mf->v4], f_no); } - for (i=0; i<nmverts; i++) { + for (i=0; i<dlm->totvert; i++) { MVert *mv= &mverts[i]; float *no= tnorms[i]; @@ -791,57 +797,34 @@ void addnormalsDispList(Object *ob, ListBase *lb) me= get_mesh(ob); - if (mesh_uses_displist(me)) { - DispList *dl= find_displist(&me->disp, DL_MESH); - - if (dl && !dl->nors) { - DispListMesh *dlm= dl->mesh; - int i; - - dl->nors= MEM_mallocN(sizeof(*dl->nors)*3*dlm->totface, "meshnormals"); - - for (i=0; i<dlm->totface; i++) { - MFace *mf= &dlm->mface[i]; - float *no= &dl->nors[i*3]; + if(me->totface==0) return; + + if(me->disp.first==0) { + dl= MEM_callocN(sizeof(DispList), "meshdisp"); + dl->type= DL_NORS; + dl->parts= 1; + dl->nr= me->totface; + BLI_addtail(&me->disp, dl); + } + else return; + + if(dl->nors==0) { + dl->nors= MEM_mallocN(sizeof(float)*3*me->totface, "meshnormals"); + n1= dl->nors; + mface= me->mface; + a= me->totface; + while(a--) { + if(mface->v3) { + ve1= me->mvert+mface->v1; + ve2= me->mvert+mface->v2; + ve3= me->mvert+mface->v3; + ve4= me->mvert+mface->v4; - if (mf->v3) { - if (mf->v4) - CalcNormFloat4(dlm->mvert[mf->v1].co, dlm->mvert[mf->v2].co, dlm->mvert[mf->v3].co, dlm->mvert[mf->v4].co, no); - else - CalcNormFloat(dlm->mvert[mf->v1].co, dlm->mvert[mf->v2].co, dlm->mvert[mf->v3].co, no); - } - } - } - } else { - if(me->totface==0) return; - - if(me->disp.first==0) { - dl= MEM_callocN(sizeof(DispList), "meshdisp"); - dl->type= DL_NORS; - dl->parts= 1; - dl->nr= me->totface; - BLI_addtail(&me->disp, dl); - } - else return; - - if(dl->nors==0) { - dl->nors= MEM_mallocN(sizeof(float)*3*me->totface, "meshnormals"); - n1= dl->nors; - mface= me->mface; - a= me->totface; - while(a--) { - if(mface->v3) { - ve1= me->mvert+mface->v1; - ve2= me->mvert+mface->v2; - ve3= me->mvert+mface->v3; - ve4= me->mvert+mface->v4; - - if(mface->v4) CalcNormFloat4(ve1->co, ve2->co, ve3->co, ve4->co, n1); - else CalcNormFloat(ve1->co, ve2->co, ve3->co, n1); - } - n1+= 3; - mface++; + if(mface->v4) CalcNormFloat4(ve1->co, ve2->co, ve3->co, ve4->co, n1); + else CalcNormFloat(ve1->co, ve2->co, ve3->co, n1); } + n1+= 3; + mface++; } } diff --git a/source/blender/blenkernel/intern/subsurf.c b/source/blender/blenkernel/intern/subsurf.c index aa451928923..84588342f6b 100644 --- a/source/blender/blenkernel/intern/subsurf.c +++ b/source/blender/blenkernel/intern/subsurf.c @@ -1067,7 +1067,7 @@ static DispListMesh *hypermesh_to_displistmesh(HyperMesh *hme, short flag) { mf++; } - displistmesh_calc_vert_normals(dlm); + displistmesh_calc_normals(dlm); return dlm; } diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 94adb68f3a7..e21b38716b7 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -514,7 +514,7 @@ static DispListMesh *subSurf_createDispListMesh(SubSurf *ssm, int doOptEdges) { } ccgFaceIterator_free(fi); - displistmesh_calc_vert_normals(dlm); + displistmesh_calc_normals(dlm); return dlm; } |