diff options
Diffstat (limited to 'source/blender/blenkernel/intern/subsurf_ccg.c')
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 164 |
1 files changed, 64 insertions, 100 deletions
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index d6486c3ee4d..a2d3016099d 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -41,6 +41,13 @@ #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "BLI_blenlib.h" +#include "BLI_edgehash.h" +#include "BLI_math.h" +#include "BLI_memarena.h" +#include "BLI_pbvh.h" +#include "BLI_utildefines.h" + #include "BKE_cdderivedmesh.h" #include "BKE_global.h" #include "BKE_mesh.h" @@ -48,13 +55,7 @@ #include "BKE_paint.h" #include "BKE_scene.h" #include "BKE_subsurf.h" -#include "BKE_utildefines.h" -#include "BLI_blenlib.h" -#include "BLI_edgehash.h" -#include "BLI_math.h" -#include "BLI_memarena.h" -#include "BLI_pbvh.h" #include "BIF_gl.h" #include "BIF_glutil.h" @@ -69,8 +70,6 @@ static int ccgDM_getVertMapIndex(CCGSubSurf *ss, CCGVert *v); static int ccgDM_getEdgeMapIndex(CCGSubSurf *ss, CCGEdge *e); static int ccgDM_getFaceMapIndex(CCGSubSurf *ss, CCGFace *f); -static int ccgDM_use_grid_pbvh(CCGDerivedMesh *ccgdm); - /// static void *arena_alloc(CCGAllocatorHDL a, int numBytes) { @@ -83,13 +82,13 @@ static void *arena_realloc(CCGAllocatorHDL a, void *ptr, int newSize, int oldSiz } return p2; } -static void arena_free(CCGAllocatorHDL a, void *ptr) { +static void arena_free(CCGAllocatorHDL UNUSED(a), void *UNUSED(ptr)) { } static void arena_release(CCGAllocatorHDL a) { BLI_memarena_free(a); } -static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAging, int useArena, int useFlatSubdiv) { +static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAging, int useArena, int UNUSED(useFlatSubdiv)) { CCGMeshIFC ifc; CCGSubSurf *ccgSS; @@ -313,7 +312,7 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result, CCGFace **faceMap; MTFace *tf; CCGFaceIterator *fi; - int index, gridSize, gridFaces, edgeSize, totface, x, y, S; + int index, gridSize, gridFaces, /*edgeSize,*/ totface, x, y, S; MTFace *dmtface = CustomData_get_layer_n(&dm->faceData, CD_MTFACE, n); MTFace *tface = CustomData_get_layer_n(&result->faceData, CD_MTFACE, n); @@ -330,7 +329,7 @@ static void set_subsurf_uv(CCGSubSurf *ss, DerivedMesh *dm, DerivedMesh *result, /* get some info from CCGSubSurf */ totface = ccgSubSurf_getNumFaces(uvss); - edgeSize = ccgSubSurf_getEdgeSize(uvss); + /* edgeSize = ccgSubSurf_getEdgeSize(uvss); */ /*UNUSED*/ gridSize = ccgSubSurf_getGridSize(uvss); gridFaces = gridSize - 1; @@ -688,7 +687,7 @@ static void ccgDM_getFinalEdge(DerivedMesh *dm, int edgeNum, MEdge *med) /* this edge comes from face data */ int lastface = ccgSubSurf_getNumFaces(ss) - 1; CCGFace *f; - int x, y, grid, numVerts; + int x, y, grid /*, numVerts*/; int offset; int gridSize = ccgSubSurf_getGridSize(ss); int edgeSize = ccgSubSurf_getEdgeSize(ss); @@ -700,7 +699,7 @@ static void ccgDM_getFinalEdge(DerivedMesh *dm, int edgeNum, MEdge *med) ++i; f = ccgdm->faceMap[i].face; - numVerts = ccgSubSurf_getFaceNumVerts(f); + /* numVerts = ccgSubSurf_getFaceNumVerts(f); */ /*UNUSED*/ gridSideEdges = gridSize - 1; gridInternalEdges = (gridSideEdges - 1) * gridSideEdges * 2; @@ -765,7 +764,7 @@ static void ccgDM_getFinalFace(DerivedMesh *dm, int faceNum, MFace *mf) int gridFaces = gridSideEdges * gridSideEdges; int i; CCGFace *f; - int numVerts; + /*int numVerts;*/ int offset; int grid; int x, y; @@ -779,7 +778,7 @@ static void ccgDM_getFinalFace(DerivedMesh *dm, int faceNum, MFace *mf) ++i; f = ccgdm->faceMap[i].face; - numVerts = ccgSubSurf_getFaceNumVerts(f); + /*numVerts = ccgSubSurf_getFaceNumVerts(f);*/ /*UNUSED*/ offset = faceNum - ccgdm->faceMap[i].startFace; grid = offset / gridFaces; @@ -1146,7 +1145,23 @@ static void ccgDM_drawVerts(DerivedMesh *dm) { ccgFaceIterator_free(fi); glEnd(); } -static void ccgDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges) { + +static void ccgdm_pbvh_update(CCGDerivedMesh *ccgdm) +{ + if(ccgdm->pbvh) { + CCGFace **faces; + int totface; + + BLI_pbvh_get_grid_updates(ccgdm->pbvh, 1, (void***)&faces, &totface); + if(totface) { + ccgSubSurf_updateFromFaces(ccgdm->ss, 0, faces, totface); + ccgSubSurf_updateNormals(ccgdm->ss, faces, totface); + MEM_freeN(faces); + } + } +} + +static void ccgDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int UNUSED(drawAllEdges)) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm; CCGSubSurf *ss = ccgdm->ss; CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss); @@ -1155,6 +1170,8 @@ static void ccgDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdge int gridSize = ccgSubSurf_getGridSize(ss); int useAging; + ccgdm_pbvh_update(ccgdm); + ccgSubSurf_getUseAgeCounts(ss, &useAging, NULL, NULL, NULL); for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) { @@ -1245,25 +1262,10 @@ static void ccgDM_glNormalFast(float *a, float *b, float *c, float *d) no[1] = b_dZ*a_cX - b_dX*a_cZ; no[2] = b_dX*a_cY - b_dY*a_cX; - /* don't normalize, GL_NORMALIZE is be enabled */ + /* don't normalize, GL_NORMALIZE is enabled */ glNormal3fv(no); } -static void ccgdm_pbvh_update(CCGDerivedMesh *ccgdm) -{ - if(ccgdm->pbvh && ccgDM_use_grid_pbvh(ccgdm)) { - CCGFace **faces; - int totface; - - BLI_pbvh_get_grid_updates(ccgdm->pbvh, 1, (void***)&faces, &totface); - if(totface) { - ccgSubSurf_updateFromFaces(ccgdm->ss, 0, faces, totface); - ccgSubSurf_updateNormals(ccgdm->ss, faces, totface); - MEM_freeN(faces); - } - } -} - /* Only used by non-editmesh types */ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)[4], int fast, int (*setMaterial)(int, void *attribs)) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm; @@ -1357,7 +1359,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, v CCGSubSurf *ss = ccgdm->ss; CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss); GPUVertexAttribs gattribs; - DMVertexAttribs attribs; + DMVertexAttribs attribs= {{{0}}}; MTFace *tf = dm->getFaceDataArray(dm, CD_MTFACE); int gridSize = ccgSubSurf_getGridSize(ss); int gridFaces = gridSize - 1; @@ -1369,13 +1371,10 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, v ccgdm_pbvh_update(ccgdm); doDraw = 0; - numVerts = 0; matnr = -1; transp = GPU_get_material_blend_mode(); orig_transp = transp; - memset(&attribs, 0, sizeof(attribs)); - #define PASSATTRIB(dx, dy, vert) { \ if(attribs.totorco) { \ index = getFaceIndex(ss, f, S, x+dx, y+dy, edgeSize, gridSize); \ @@ -1514,7 +1513,7 @@ static void ccgDM_drawFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *a dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL); } -static void ccgDM_drawFacesColored(DerivedMesh *dm, int useTwoSided, unsigned char *col1, unsigned char *col2) { +static void ccgDM_drawFacesColored(DerivedMesh *dm, int UNUSED(useTwoSided), unsigned char *col1, unsigned char *col2) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm; CCGSubSurf *ss = ccgdm->ss; CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss); @@ -1619,9 +1618,12 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, if(drawParams) flag = drawParams(tf, mcol, mat_nr); - else + else if (index != ORIGINDEX_NONE) flag= (drawParamsMapped)? drawParamsMapped(userData, index): 1; - + else + flag= GPU_enable_material(mat_nr, NULL) ? 1:0; + + if (flag == 0) { /* flag 0 == the face is hidden or invisible */ if(tf) tf += gridFaces*gridFaces*numVerts; if(mcol) mcol += gridFaces*gridFaces*numVerts*4; @@ -1761,7 +1763,7 @@ static void ccgDM_drawUVEdges(DerivedMesh *dm) } } -static void ccgDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors) { +static void ccgDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors, int (*setMaterial)(int, void *attribs)) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm; CCGSubSurf *ss = ccgdm->ss; MCol *mcol= NULL; @@ -1793,10 +1795,14 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *u mcol += gridFaces*gridFaces*numVerts*4; } - if (index!=-1) { - int draw; - draw = setDrawOptions==NULL ? 1 : setDrawOptions(userData, index, &drawSmooth); - + { + int draw= 1; + + if(index == ORIGINDEX_NONE) + draw= setMaterial(faceFlags ? faceFlags[origIndex*2 + 1] + 1: 1, NULL); /* XXX, no faceFlags no material */ + else if (setDrawOptions) + draw= setDrawOptions(userData, index, &drawSmooth); + if (draw) { if (draw==2) { glEnable(GL_POLYGON_STIPPLE); @@ -2139,14 +2145,14 @@ static void ccgdm_create_grids(DerivedMesh *dm) DMGridAdjacency *gridAdjacency, *adj; CCGFace **gridFaces; int *gridOffset; - int index, numFaces, numGrids, S, gIndex, gridSize; + int index, numFaces, numGrids, S, gIndex /*, gridSize*/; if(ccgdm->gridData) return; numGrids = ccgDM_getNumGrids(dm); numFaces = ccgSubSurf_getNumFaces(ss); - gridSize = ccgDM_getGridSize(dm); + /*gridSize = ccgDM_getGridSize(dm);*/ /*UNUSED*/ /* compute offset into grid array for each face */ gridOffset = MEM_mallocN(sizeof(int)*numFaces, "ccgdm.gridOffset"); @@ -2232,28 +2238,10 @@ static ListBase *ccgDM_getFaceMap(Object *ob, DerivedMesh *dm) return ccgdm->fmap; } -static int ccgDM_use_grid_pbvh(CCGDerivedMesh *ccgdm) -{ - ModifierData *md; - MultiresModifierData *mmd= ccgdm->multires.mmd; - - /* in sync with sculpt mode, only use multires grid pbvh if we are - the last enabled modifier in the stack, otherwise we use the base - mesh */ - if(!mmd) - return 0; - - for(md=mmd->modifier.next; md; md= md->next) - if(modifier_isEnabled(mmd->modifier.scene, md, eModifierMode_Realtime)) - return 0; - - return 1; -} - static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) { CCGDerivedMesh *ccgdm= (CCGDerivedMesh*)dm; - int gridSize, numGrids, grid_pbvh; + int gridSize, numGrids; if(!ob) { ccgdm->pbvh= NULL; @@ -2263,21 +2251,8 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) if(!ob->sculpt) return NULL; - grid_pbvh = ccgDM_use_grid_pbvh(ccgdm); - - if(ob->sculpt->pbvh) { - if(grid_pbvh) { - /* pbvh's grids, gridadj and gridfaces points to data inside ccgdm - but this can be freed on ccgdm release, this updates the pointers - when the ccgdm gets remade, the assumption is that the topology - does not change. */ - ccgdm_create_grids(dm); - BLI_pbvh_grids_update(ob->sculpt->pbvh, ccgdm->gridData, ccgdm->gridAdjacency, (void**)ccgdm->gridFaces); - } - + if(ob->sculpt->pbvh) ccgdm->pbvh = ob->sculpt->pbvh; - ccgdm->pbvh_draw = grid_pbvh; - } if(ccgdm->pbvh) return ccgdm->pbvh; @@ -2285,25 +2260,14 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) /* no pbvh exists yet, we need to create one. only in case of multires we build a pbvh over the modified mesh, in other cases the base mesh is being sculpted, so we build a pbvh from that. */ - if(grid_pbvh) { - ccgdm_create_grids(dm); - - gridSize = ccgDM_getGridSize(dm); - numGrids = ccgDM_getNumGrids(dm); + ccgdm_create_grids(dm); - ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new(); - BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, ccgdm->gridAdjacency, - numGrids, gridSize, (void**)ccgdm->gridFaces); - ccgdm->pbvh_draw = 1; - } - else if(ob->type == OB_MESH) { - Mesh *me= ob->data; + gridSize = ccgDM_getGridSize(dm); + numGrids = ccgDM_getNumGrids(dm); - ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new(); - BLI_pbvh_build_mesh(ccgdm->pbvh, me->mface, me->mvert, - me->totface, me->totvert); - ccgdm->pbvh_draw = 0; - } + ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new(); + BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, ccgdm->gridAdjacency, + numGrids, gridSize, (void**)ccgdm->gridFaces); return ccgdm->pbvh; } @@ -2325,7 +2289,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, int edgeSize; int gridSize; int gridFaces; - int gridSideVerts; + /*int gridSideVerts;*/ int gridSideEdges; int gridInternalEdges; MEdge *medge = NULL; @@ -2423,8 +2387,8 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, edgeSize = ccgSubSurf_getEdgeSize(ss); gridSize = ccgSubSurf_getGridSize(ss); gridFaces = gridSize - 1; - gridSideVerts = gridSize - 2; - /*gridInternalVerts = gridSideVerts * gridSideVerts; - as yet, unused */ + /*gridSideVerts = gridSize - 2;*/ /*UNUSED*/ + /*gridInternalVerts = gridSideVerts * gridSideVerts; */ /*UNUSED*/ gridSideEdges = gridSize - 1; gridInternalEdges = (gridSideEdges - 1) * gridSideEdges * 2; |