diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-02-05 10:20:51 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-02-05 10:20:51 +0400 |
commit | 776ec0ec61cee0be4eb60511900f7fe8f01dbae5 (patch) | |
tree | 52a690b779119bb4d96f16e51aa68ec3038a78f5 | |
parent | 2277241ea66ed7672cb81616b1ef3369586aa18c (diff) |
add function for getting a polygon map: dm->getPolyMap(ob, dm).
polygon version of dm->getFaceMap(ob, dm)
sculpt uses this for checking connectivity.
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_mesh.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_paint.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_subsurf.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 22 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 26 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 18 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 12 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_intern.h | 2 |
9 files changed, 84 insertions, 8 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 69abfe3c34d..9041add3c66 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -269,6 +269,10 @@ struct DerivedMesh { /* Get a map of vertices to faces */ + struct ListBase *(*getPolyMap)(struct Object *ob, DerivedMesh *dm); + + /* Get a map of vertices to faces + */ struct ListBase *(*getFaceMap)(struct Object *ob, DerivedMesh *dm); /* Get the BVH used for paint modes diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 91f9e5a92f7..70d2773c6c4 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -225,6 +225,9 @@ typedef struct IndexNode { struct IndexNode *next, *prev; int index; } IndexNode; +void create_vert_poly_map(struct ListBase **map, IndexNode **mem, + struct MPoly *mface, struct MLoop *mloop, + const int totvert, const int totface, const int totloop); void create_vert_face_map(struct ListBase **map, IndexNode **mem, const struct MFace *mface, const int totvert, const int totface); void create_vert_edge_map(struct ListBase **map, IndexNode **mem, const struct MEdge *medge, diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 93b33ccd630..b1ac0a5b7d4 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -74,7 +74,7 @@ typedef struct SculptSession { struct KeyBlock *kb; /* Mesh connectivity */ - struct ListBase *fmap; + struct ListBase *pmap; /* PBVH acceleration structure */ struct PBVH *pbvh; diff --git a/source/blender/blenkernel/BKE_subsurf.h b/source/blender/blenkernel/BKE_subsurf.h index 5c878102bc2..47aee714bf7 100644 --- a/source/blender/blenkernel/BKE_subsurf.h +++ b/source/blender/blenkernel/BKE_subsurf.h @@ -84,6 +84,9 @@ typedef struct CCGDerivedMesh { struct ListBase *fmap; struct IndexNode *fmap_mem; + struct ListBase *pmap; + struct IndexNode *pmap_mem; + struct DMGridData **gridData; struct DMGridAdjacency *gridAdjacency; int *gridOffset; diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index d3868ceca13..35d578b9d5e 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -94,6 +94,9 @@ typedef struct { /* Mesh connectivity */ struct ListBase *fmap; struct IndexNode *fmap_mem; + + struct ListBase *pmap; + struct IndexNode *pmap_mem; } CDDerivedMesh; /**************** DerivedMesh interface functions ****************/ @@ -206,6 +209,21 @@ static void cdDM_getVertNo(DerivedMesh *dm, int index, float no_r[3]) normal_short_to_float_v3(no_r, cddm->mvert[index].no); } +static ListBase *cdDM_getPolyMap(Object *ob, DerivedMesh *dm) +{ + CDDerivedMesh *cddm = (CDDerivedMesh*) dm; + + if(!cddm->pmap && ob->type == OB_MESH) { + Mesh *me= ob->data; + + create_vert_poly_map(&cddm->pmap, &cddm->pmap_mem, + me->mpoly, me->mloop, + me->totvert, me->totface, me->totloop); + } + + return cddm->pmap; +} + static ListBase *cdDM_getFaceMap(Object *ob, DerivedMesh *dm) { CDDerivedMesh *cddm = (CDDerivedMesh*) dm; @@ -1608,6 +1626,9 @@ static void cdDM_free_internal(CDDerivedMesh *cddm) { if(cddm->fmap) MEM_freeN(cddm->fmap); if(cddm->fmap_mem) MEM_freeN(cddm->fmap_mem); + + if(cddm->pmap) MEM_freeN(cddm->pmap); + if(cddm->pmap_mem) MEM_freeN(cddm->pmap_mem); } static void cdDM_release(DerivedMesh *dm) @@ -1667,6 +1688,7 @@ static CDDerivedMesh *cdDM_create(const char *desc) dm->getVertNo = cdDM_getVertNo; dm->getPBVH = cdDM_getPBVH; + dm->getPolyMap = cdDM_getPolyMap; dm->getFaceMap = cdDM_getFaceMap; dm->drawVerts = cdDM_drawVerts; diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 6bdc80f7b0b..d10bda38d25 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -2102,6 +2102,32 @@ void free_uv_vert_map(UvVertMap *vmap) } /* Generates a map where the key is the vertex and the value is a list + of polys that use that vertex as a corner. The lists are allocated + from one memory pool. */ +void create_vert_poly_map(ListBase **map, IndexNode **mem, + MPoly *mpoly, MLoop *mloop, + const int totvert, const int totpoly, const int totloop) +{ + int i,j; + IndexNode *node = NULL; + MPoly *mp; + MLoop *ml; + + (*map) = MEM_callocN(sizeof(ListBase) * totvert, "vert face map"); + (*mem) = MEM_callocN(sizeof(IndexNode) * totloop, "vert poly map mem"); + node = *mem; + + /* Find the users */ + for(i = 0, mp = mpoly; i < totpoly; ++i, ++mp){ + ml = &mloop[mp->loopstart]; + for(j = 0; j < mp->totloop; ++j, ++node, ++ml) { + node->index = i; + BLI_addtail(&(*map)[ml->v], node); + } + } +} + +/* Generates a map where the key is the vertex and the value is a list of faces that use that vertex as a corner. The lists are allocated from one memory pool. */ void create_vert_face_map(ListBase **map, IndexNode **mem, const MFace *mface, const int totvert, const int totface) diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index f8fec9911fb..a32d19addf9 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -2387,6 +2387,8 @@ static void cgdm_release(DerivedMesh *dm) { if(ccgdm->freeSS) ccgSubSurf_free(ccgdm->ss); if(ccgdm->fmap) MEM_freeN(ccgdm->fmap); if(ccgdm->fmap_mem) MEM_freeN(ccgdm->fmap_mem); + if(ccgdm->pmap) MEM_freeN(ccgdm->pmap); + if(ccgdm->pmap_mem) MEM_freeN(ccgdm->pmap_mem); MEM_freeN(ccgdm->edgeFlags); MEM_freeN(ccgdm->faceFlags); MEM_freeN(ccgdm->vertMap); @@ -2736,6 +2738,21 @@ static int *ccgDM_getGridOffset(DerivedMesh *dm) return cgdm->gridOffset; } +static ListBase *ccgDM_getPolyMap(Object *ob, DerivedMesh *dm) +{ + CCGDerivedMesh *ccgdm= (CCGDerivedMesh*)dm; + + if(!ccgdm->multires.mmd && !ccgdm->pmap && ob->type == OB_MESH) { + Mesh *me= ob->data; + + create_vert_poly_map(&ccgdm->pmap, &ccgdm->pmap_mem, + me->mpoly, me->mloop, + me->totvert, me->totface, me->totloop); + } + + return ccgdm->pmap; +} + static ListBase *ccgDM_getFaceMap(Object *ob, DerivedMesh *dm) { CCGDerivedMesh *ccgdm= (CCGDerivedMesh*)dm; @@ -2906,6 +2923,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, ccgdm->dm.getGridData = ccgDM_getGridData; ccgdm->dm.getGridAdjacency = ccgDM_getGridAdjacency; ccgdm->dm.getGridOffset = ccgDM_getGridOffset; + ccgdm->dm.getPolyMap = ccgDM_getPolyMap; ccgdm->dm.getFaceMap = ccgDM_getFaceMap; ccgdm->dm.getPBVH = ccgDM_getPBVH; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 682f0fad53a..d14e7da5537 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -905,8 +905,8 @@ static void calc_sculpt_normal(Sculpt *sd, Object *ob, float an[3], PBVHNode **n static void neighbor_average(SculptSession *ss, float avg[3], const unsigned vert) { int i, j, ok, total=0; - IndexNode *node= ss->fmap[vert].first; - char ncount= BLI_countlist(&ss->fmap[vert]); + IndexNode *node= ss->pmap[vert].first; + char ncount= BLI_countlist(&ss->pmap[vert]); MPoly *f; MLoop *ml; @@ -942,7 +942,7 @@ static void neighbor_average(SculptSession *ss, float avg[3], const unsigned ver for (i=0; i<3; ++i) { - if (ncount!=2 || BLI_countlist(&ss->fmap[f_adj_v[i]]) <= 2) { + if (ncount!=2 || BLI_countlist(&ss->pmap[f_adj_v[i]]) <= 2) { if(ss->deform_cos) add_v3_v3(avg, ss->deform_cos[f_adj_v[i]]); else add_v3_v3(avg, ss->mvert[f_adj_v[i]].co); ++total; @@ -1122,7 +1122,7 @@ static void smooth(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, float if(ss->multires) { do_multires_smooth_brush(sd, ss, nodes[n], iteration != count ? 1.0f : last); } - else if(ss->fmap) + else if(ss->pmap) do_mesh_smooth_brush(sd, ss, nodes[n], iteration != count ? 1.0f : last); } @@ -2692,7 +2692,7 @@ static void sculpt_update_tex(const Scene *scene, Sculpt *sd, SculptSession *ss) } } -void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, int need_fmap) +void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, int need_pmap) { DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); SculptSession *ss = ob->sculpt; @@ -2724,7 +2724,7 @@ void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, int need_ } ss->pbvh = dm->getPBVH(ob, dm); - ss->fmap = (need_fmap && dm->getFaceMap)? dm->getFaceMap(ob, dm): NULL; + ss->pmap = (need_pmap && dm->getPolyMap)? dm->getPolyMap(ob, dm): NULL; if(ss->modifiers_active) { if(!ss->orig_cos) { diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index 275d1d52355..5c739f043fe 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -62,7 +62,7 @@ struct Brush *sculptmode_brush(void); void sculpt(Sculpt *sd); int sculpt_poll(struct bContext *C); -void sculpt_update_mesh_elements(struct Scene *scene, struct Sculpt *sd, struct Object *ob, int need_fmap); +void sculpt_update_mesh_elements(struct Scene *scene, struct Sculpt *sd, struct Object *ob, int need_pmap); /* Deformed mesh sculpt */ void free_sculptsession_deformMats(struct SculptSession *ss); |