Don't wait for sculpt stroke to create PBVH.

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.
This commit is contained in:
Nicholas Bishop 2012-03-14 06:30:55 +00:00
parent ee9a00948b
commit 38d4848020
3 changed files with 9 additions and 8 deletions

View 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)

View 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);

View 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;
}