Don't wait for sculpt stroke to create PBVH.
authorNicholas Bishop <nicholasbishop@gmail.com>
Wed, 14 Mar 2012 06:30:55 +0000 (06:30 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Wed, 14 Mar 2012 06:30:55 +0000 (06:30 +0000)
This idea is borrowed from the multires modifier, which already
checked if the object was in sculpt mode and, if so, created the
PBVH. That check is now moved higher up the chain into
mesh_build_data(), so that it occurs for CDDerivedMesh too.

This also replaces an assert in cdDM_getPBVH for tesselated mesh faces
with a call to create them if missing.

source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/modifiers/intern/MOD_multires.c

index 235bc695b66d835706b70267496c96ab43da0f7b..66cd8adc60b04dbf5d5701256b648cb39d72125e 100644 (file)
@@ -1993,6 +1993,12 @@ static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask,
        ob->derivedFinal->needsFree = 0;
        ob->derivedDeform->needsFree = 0;
        ob->lastDataMask = dataMask;
+
+       if((ob->mode & OB_MODE_SCULPT) && ob->sculpt) {
+               /* create PBVH immediately (would be created on the fly too,
+                  but this avoids waiting on first stroke) */
+               ob->sculpt->pbvh= ob->derivedFinal->getPBVH(ob, ob->derivedFinal);
+       }
 }
 
 static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, CustomDataMask dataMask)
index cc3705780e4ed39617f75b7520e84083ca238289..54f7fc1e483592f676b5a3ac9c3800a4de379d8b 100644 (file)
@@ -276,7 +276,9 @@ static struct PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
                Mesh *me= ob->data;
                cddm->pbvh = BLI_pbvh_new();
                cddm->pbvh_draw = can_pbvh_draw(ob, dm);
-               BLI_assert(!(me->mface == NULL && me->mpoly != NULL)); /* BMESH ONLY complain if mpoly is valid but not mface */
+
+               BKE_mesh_tessface_ensure(me);
+               
                BLI_pbvh_build_mesh(cddm->pbvh, me->mface, me->mvert,
                                    me->totface, me->totvert);
 
index 00572eaad86c3997296a3e1cc28fc4ad25175a40..f983204945a0c746df89449e6eab5b25cc9a23bc 100644 (file)
@@ -71,8 +71,6 @@ static void copyData(ModifierData *md, ModifierData *target)
 static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm,
                                                   int useRenderParams, int isFinalCalc)
 {
-       SculptSession *ss= ob->sculpt;
-       int sculpting= (ob->mode & OB_MODE_SCULPT) && ss;
        MultiresModifierData *mmd = (MultiresModifierData*)md;
        DerivedMesh *result;
        Mesh *me= (Mesh*)ob->data;
@@ -94,11 +92,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm,
                result->release(result);
                result= cddm;
        }
-       else if(sculpting) {
-               /* would be created on the fly too, just nicer this
-                * way on first stroke after e.g. switching levels */
-               ss->pbvh= result->getPBVH(ob, result);
-       }
 
        return result;
 }