diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-12-09 16:37:19 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-12-09 16:37:19 +0300 |
commit | 9ea765e5d316ca6d2b15da2392e9da3643a856bb (patch) | |
tree | 7604b9d1dd06064432b9e56af4a7dedd669fec80 /source/blender/blenkernel | |
parent | abae1e2ccf2bb16d4a436cdcbb17560252df7e8a (diff) |
Sculpt Branch:
* Smooth brush works again for multires.
* Optimal Display option for multires modifier, same as subsurf.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_multires.h | 20 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/CCGSubSurf.c | 27 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/multires.c | 67 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 6 |
4 files changed, 91 insertions, 29 deletions
diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h index 53ead3a5eda..ff320bc7d25 100644 --- a/source/blender/blenkernel/BKE_multires.h +++ b/source/blender/blenkernel/BKE_multires.h @@ -27,24 +27,22 @@ * ***** END GPL LICENSE BLOCK ***** */ +#ifndef BKE_MULTIRES_H +#define BKE_MULTIRES_H + struct DerivedMesh; struct Mesh; struct MFace; +struct Multires; struct MultiresModifierData; struct Object; -typedef struct MultiresSubsurf { - struct MultiresModifierData *mmd; - struct Object *ob; - int local_mmd; -} MultiresSubsurf; - void multires_mark_as_modified(struct Object *ob); void multires_force_update(struct Object *ob); -struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*, int local_mmd, struct DerivedMesh*, - struct Object *, int, int); +struct DerivedMesh *multires_dm_create_from_derived(struct MultiresModifierData*, + int local_mmd, struct DerivedMesh*, struct Object *, int, int); struct MultiresModifierData *find_multires_modifier(struct Object *ob); void multiresModifier_join(struct Object *); @@ -53,7 +51,11 @@ void multiresModifier_subdivide(struct MultiresModifierData *mmd, struct Object int updateblock, int simple); int multiresModifier_reshape(struct MultiresModifierData *mmd, struct Object *dst, struct Object *src); +void multires_stitch_grids(struct Object *); + /* Related to the old multires */ -struct Multires; void multires_load_old(struct DerivedMesh *, struct Multires *); void multires_free(struct Multires*); + +#endif + diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c index cc2bd531fe6..4bd0586c592 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf.c +++ b/source/blender/blenkernel/intern/CCGSubSurf.c @@ -2228,8 +2228,9 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in VertDataZero(FACE_getCenterData(f)); for (S=0; S<f->numVerts; S++) - for (x=0; x<gridSize; x++) - VertDataZero(FACE_getIECo(f, lvl, S, x)); + if (FACE_getEdges(f)[S]->flags&Edge_eEffected) + for (x=0; x<gridSize; x++) + VertDataZero(FACE_getIECo(f, lvl, S, x)); for (S=0; S<f->numVerts; S++) { int prevS = (S+f->numVerts-1)%f->numVerts; @@ -2237,18 +2238,23 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in CCGEdge *prevE = FACE_getEdges(f)[prevS]; VertDataAdd(FACE_getCenterData(f), FACE_getIFCo(f, lvl, S, 0, 0)); - VertDataAdd(VERT_getCo(FACE_getVerts(f)[S], lvl), FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx)); + if (FACE_getVerts(f)[S]->flags&Vert_eEffected) + VertDataAdd(VERT_getCo(FACE_getVerts(f)[S], lvl), FACE_getIFCo(f, lvl, S, cornerIdx, cornerIdx)); for (x=1; x<gridSize-1; x++) { - VertDataAdd(FACE_getIECo(f, lvl, S, x), FACE_getIFCo(f, lvl, S, x, 0)); - VertDataAdd(FACE_getIECo(f, lvl, prevS, x), FACE_getIFCo(f, lvl, S, 0, x)); + if (FACE_getEdges(f)[S]->flags&Edge_eEffected) + VertDataAdd(FACE_getIECo(f, lvl, S, x), FACE_getIFCo(f, lvl, S, x, 0)); + if (FACE_getEdges(f)[prevS]->flags&Edge_eEffected) + VertDataAdd(FACE_getIECo(f, lvl, prevS, x), FACE_getIFCo(f, lvl, S, 0, x)); } for (x=0; x<gridSize-1; x++) { int eI = gridSize-1-x; - VertDataAdd(_edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI,vertDataSize), FACE_getIFCo(f, lvl, S, cornerIdx, x)); - if(x != 0) - VertDataAdd(_edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI,vertDataSize), FACE_getIFCo(f, lvl, S, x, cornerIdx)); + if (FACE_getEdges(f)[S]->flags&Edge_eEffected) + VertDataAdd(_edge_getCoVert(e, FACE_getVerts(f)[S], lvl, eI,vertDataSize), FACE_getIFCo(f, lvl, S, cornerIdx, x)); + if (FACE_getEdges(f)[prevS]->flags&Edge_eEffected) + if(x != 0) + VertDataAdd(_edge_getCoVert(prevE, FACE_getVerts(f)[S], lvl, eI,vertDataSize), FACE_getIFCo(f, lvl, S, x, cornerIdx)); } } } @@ -2276,8 +2282,9 @@ CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, in VertDataMulN(FACE_getCenterData(f), 1.0f/f->numVerts); for (S=0; S<f->numVerts; S++) - for (x=1; x<gridSize-1; x++) - VertDataMulN(FACE_getIECo(f, lvl, S, x), 0.5f); + if (FACE_getEdges(f)[S]->flags&Edge_eEffected) + for (x=1; x<gridSize-1; x++) + VertDataMulN(FACE_getIECo(f, lvl, S, x), 0.5f); for (S=0; S<f->numVerts; S++) { int prevS = (S+f->numVerts-1)%f->numVerts; diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 69659db3ba7..8a76d659d5f 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -39,6 +39,7 @@ #include "BLI_math.h" #include "BLI_blenlib.h" +#include "BLI_pbvh.h" #include "BKE_btex.h" #include "BKE_cdderivedmesh.h" @@ -60,8 +61,8 @@ /* MULTIRES MODIFIER */ static const int multires_max_levels = 13; -static const int multires_grid_tot[] = {1, 4, 9, 25, 81, 289, 1089, 4225, 16641, 66049, 263169, 1050625, 4198401, 16785409}; -static const int multires_side_tot[] = {1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097}; +static const int multires_grid_tot[] = {0, 4, 9, 25, 81, 289, 1089, 4225, 16641, 66049, 263169, 1050625, 4198401, 16785409}; +static const int multires_side_tot[] = {0, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097}; static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, int invert, int add, DMGridData **oldGridData, int totlvl); @@ -307,7 +308,7 @@ static DerivedMesh *multires_dm_create_local(Object *ob, DerivedMesh *dm, int lv return multires_dm_create_from_derived(&mmd, 1, dm, ob, 0, 0); } -static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int simple) +static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl, int simple, int optimal) { SubsurfModifierData smd; @@ -316,6 +317,8 @@ static DerivedMesh *subsurf_dm_create_local(Object *ob, DerivedMesh *dm, int lvl smd.flags |= eSubsurfModifierFlag_SubsurfUv; if(simple) smd.subdivType = ME_SIMPLE_SUBSURF; + if(optimal) + smd.flags |= eSubsurfModifierFlag_ControlEdges; return subsurf_make_derived_from_derived(dm, &smd, 0, NULL, 0, 0); } @@ -363,7 +366,7 @@ void multiresModifier_subdivide(MultiresModifierData *mmd, Object *ob, int updat /* create subsurf DM from original mesh at high level */ cddm = CDDM_from_mesh(me, NULL); - highdm = subsurf_dm_create_local(ob, cddm, totlvl, simple); + highdm = subsurf_dm_create_local(ob, cddm, totlvl, simple, 0); /* create multires DM from original mesh at low level */ lowdm = multires_dm_create_local(ob, cddm, lvl, lvl, simple); @@ -551,7 +554,7 @@ static void multiresModifier_update(DerivedMesh *dm) /* create subsurf DM from original mesh at high level */ cddm = CDDM_from_mesh(me, NULL); - highdm = subsurf_dm_create_local(ob, cddm, totlvl, mmd->simple); + highdm = subsurf_dm_create_local(ob, cddm, totlvl, mmd->simple, 0); /* create multires DM from original mesh and displacements */ lowdm = multires_dm_create_local(ob, cddm, lvl, totlvl, mmd->simple); @@ -602,7 +605,7 @@ static void multiresModifier_update(DerivedMesh *dm) DerivedMesh *cddm, *subdm; cddm = CDDM_from_mesh(me, NULL); - subdm = subsurf_dm_create_local(ob, cddm, mmd->totlvl, mmd->simple); + subdm = subsurf_dm_create_local(ob, cddm, mmd->totlvl, mmd->simple, 0); cddm->release(cddm); multiresModifier_disp_run(dm, me, 1, 0, subdm->getGridData(subdm), mmd->totlvl); @@ -629,6 +632,25 @@ void multires_force_update(Object *ob) } } +void multires_stitch_grids(Object *ob) +{ + /* utility for smooth brush */ + if(ob && ob->derivedFinal) { + CCGDerivedMesh *ccgdm = (CCGDerivedMesh*)ob->derivedFinal; + CCGFace **faces; + int totface; + + if(ccgdm->pbvh) { + BLI_pbvh_get_grid_updates(ccgdm->pbvh, 0, (void***)&faces, &totface); + + if(totface) { + ccgSubSurf_stitchFaces(ccgdm->ss, 0, faces, totface); + MEM_freeN(faces); + } + } + } +} + struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, int local_mmd, DerivedMesh *dm, Object *ob, int useRenderParams, int isFinalCalc) { @@ -642,7 +664,8 @@ struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, i if(lvl == 0) return dm; - result = subsurf_dm_create_local(ob, dm, lvl, 0); + result = subsurf_dm_create_local(ob, dm, lvl, + mmd->simple, mmd->flags & eMultiresModifierFlag_ControlEdges); if(!local_mmd) { ccgdm = (CCGDerivedMesh*)result; @@ -680,6 +703,36 @@ struct DerivedMesh *multires_dm_create_from_derived(MultiresModifierData *mmd, i /**** Old Multires code **** ***************************/ +#if 0 +static void mdisp_copy_grid(float (*new)[3], int newstride, float (*old)[3], int oldstride, int xoff, int yoff, int xsize, int ysize) +{ + int x, y; + + for(y = 0; y < ysize; ++y) + for(x = 0; x < xsize; ++x) + copy_v3_v3(disps[x + y*side], mdisp->disps[(x + xoffs) + (y + yoffs)*oldside]); + +} + +static void mdisps_convert(MFace *mface, MDisps *mdisp, int lvl) +{ + int side = multires_side_tot[lvl]; + int nvert = (mface->v4)? 4: 3; + int totdisp = multires_grid_tot[lvl]*nvert; + int x, y; + float (*disps)[3]; + + disps = MEM_callocN(sizeof(float) * 3 * totdisp, "multires disps"); + + + +static const int multires_max_levels = 13; +static const int multires_grid_tot[] = {1, 4, 9, 25, 81, 289, 1089, 4225, 16641, 66049, 263169, 1050625, 4198401, 16785409}; +static const int multires_side_tot[] = {1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097}; + +} +#endif + /* Does not actually free lvl itself */ static void multires_free_level(MultiresLevel *lvl) { diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index c9d84670044..f6abedda2b6 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -1235,7 +1235,7 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes) CCGFace **faces; int totface; - BLI_pbvh_get_grid_updates(ccgdm->pbvh, (void***)&faces, &totface); + BLI_pbvh_get_grid_updates(ccgdm->pbvh, 1, (void***)&faces, &totface); if(totface) { ccgSubSurf_updateFromFaces(ss, 0, faces, totface); ccgSubSurf_updateNormals(ss, faces, totface); @@ -2155,8 +2155,8 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) numGrids = ccgDM_getNumGrids(dm); ccgdm->pbvh = BLI_pbvh_new(); - BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, numGrids, gridSize, - (void**)ccgdm->gridFaces); + BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, ccgdm->gridAdjacency, + numGrids, gridSize, (void**)ccgdm->gridFaces); } else if(ob->type == OB_MESH) { Mesh *me= ob->data; |