Cycles: svn merge -r36352:36495 https://svn.blender.org/svnroot/bf-blender/trunk...
[blender.git] / source / blender / blenkernel / intern / subsurf_ccg.c
index 05a653d7c953be72fe271f8dcac37d4c2c6a3a4b..a66caf8879f2b79679d9d9032e51ac108a864b4b 100644 (file)
@@ -74,6 +74,7 @@
 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);
 
 ///
 
@@ -1157,7 +1158,7 @@ static void ccgDM_drawVerts(DerivedMesh *dm) {
 
 static void ccgdm_pbvh_update(CCGDerivedMesh *ccgdm)
 {
-       if(ccgdm->pbvh) {
+       if(ccgdm->pbvh && ccgDM_use_grid_pbvh(ccgdm)) {
                CCGFace **faces;
                int totface;
 
@@ -2249,10 +2250,22 @@ static ListBase *ccgDM_getFaceMap(Object *ob, DerivedMesh *dm)
        return ccgdm->fmap;
 }
 
+static int ccgDM_use_grid_pbvh(CCGDerivedMesh *ccgdm)
+{
+       MultiresModifierData *mmd= ccgdm->multires.mmd;
+
+       /* both of multires and subsurm modifiers are CCG, but
+          grids should only be used when sculpting on multires */
+       if(!mmd)
+               return 0;
+
+       return 1;
+}
+
 static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm)
 {
        CCGDerivedMesh *ccgdm= (CCGDerivedMesh*)dm;
-       int gridSize, numGrids;
+       int gridSize, numGrids, grid_pbvh;
 
        if(!ob) {
                ccgdm->pbvh= NULL;
@@ -2262,13 +2275,17 @@ 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) {
-          /* 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(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);
+               }
 
                ccgdm->pbvh = ob->sculpt->pbvh;
        }
@@ -2279,14 +2296,21 @@ 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. */
-       ccgdm_create_grids(dm);
+       if(grid_pbvh) {
+               ccgdm_create_grids(dm);
 
-       gridSize = ccgDM_getGridSize(dm);
-       numGrids = ccgDM_getNumGrids(dm);
+               gridSize = ccgDM_getGridSize(dm);
+               numGrids = ccgDM_getNumGrids(dm);
 
-       ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new();
-       BLI_pbvh_build_grids(ccgdm->pbvh, ccgdm->gridData, ccgdm->gridAdjacency,
-               numGrids, gridSize, (void**)ccgdm->gridFaces);
+               ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new();
+               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;
+               ob->sculpt->pbvh= ccgdm->pbvh = BLI_pbvh_new();
+               BLI_pbvh_build_mesh(ccgdm->pbvh, me->mface, me->mvert,
+                                  me->totface, me->totvert);
+       }
 
        return ccgdm->pbvh;
 }