add function for getting a polygon map: dm->getPolyMap(ob, dm).
polygon version of dm->getFaceMap(ob, dm) sculpt uses this for checking connectivity.
This commit is contained in:
@@ -267,6 +267,10 @@ struct DerivedMesh {
|
||||
/* Get smooth vertex normal, undefined if index is not valid */
|
||||
void (*getVertNo)(DerivedMesh *dm, int index, float no_r[3]);
|
||||
|
||||
/* 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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -74,7 +74,7 @@ typedef struct SculptSession {
|
||||
struct KeyBlock *kb;
|
||||
|
||||
/* Mesh connectivity */
|
||||
struct ListBase *fmap;
|
||||
struct ListBase *pmap;
|
||||
|
||||
/* PBVH acceleration structure */
|
||||
struct PBVH *pbvh;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -2101,6 +2101,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. */
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user