Cleanup a bit of the locked shape keys painting

It's still gives some slowdown when painting a locked
key in the solid view, but since shape key is now longer
being re-used by DM.

but this change should still give some degree of speedup
propagating delta onto the keyblock if i remember the
code correct.
This commit is contained in:
Sergey Sharybin 2014-05-06 14:49:50 +02:00
parent 35380cdcad
commit 45b4506c0d
2 changed files with 37 additions and 17 deletions

View File

@ -222,24 +222,33 @@ static const MeshElemMap *cdDM_getPolyMap(Object *ob, DerivedMesh *dm)
return cddm->pmap;
}
static bool can_pbvh_draw(Object *ob, DerivedMesh *dm)
static bool check_sculpt_object_deformed(Object *object)
{
CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
Mesh *me = ob->data;
int deformed = 0;
bool deformed = false;
/* active modifiers means extra deformation, which can't be handled correct
/* Active modifiers means extra deformation, which can't be handled correct
* on birth of PBVH and sculpt "layer" levels, so use PBVH only for internal brush
* stuff and show final DerivedMesh so user would see actual object shape */
deformed |= ob->sculpt->modifiers_active;
* stuff and show final DerivedMesh so user would see actual object shape.
*/
deformed |= object->sculpt->modifiers_active;
/* as in case with modifiers, we can't synchronize deformation made against
* PBVH and non-locked keyblock, so also use PBVH only for brushes and
* final DM to give final result to user */
deformed |= ob->sculpt->kb && (ob->shapeflag & OB_SHAPE_LOCK) == 0;
deformed |= object->sculpt->kb && (object->shapeflag & OB_SHAPE_LOCK) == 0;
if (deformed)
return 0;
return deformed;
}
static bool can_pbvh_draw(Object *ob, DerivedMesh *dm)
{
CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
Mesh *me = ob->data;
bool deformed = check_sculpt_object_deformed(ob);
if (deformed) {
return false;
}
return cddm->mvert == me->mvert || ob->sculpt->kb;
}
@ -279,9 +288,8 @@ static PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
* this derivedmesh is just original mesh. it's the multires subsurf dm
* that this is actually for, to support a pbvh on a modified mesh */
if (!cddm->pbvh && ob->type == OB_MESH) {
SculptSession *ss = ob->sculpt;
Mesh *me = ob->data;
int deformed = 0;
bool deformed;
cddm->pbvh = BKE_pbvh_new();
cddm->pbvh_draw = can_pbvh_draw(ob, dm);
@ -293,7 +301,7 @@ static PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
pbvh_show_diffuse_color_set(cddm->pbvh, ob->sculpt->show_diffuse_color);
deformed = ss->modifiers_active || me->key;
deformed = check_sculpt_object_deformed(ob);
if (deformed && ob->derivedDeform) {
DerivedMesh *deformdm = ob->derivedDeform;

View File

@ -198,7 +198,8 @@ static bool sculpt_modifiers_active(Scene *scene, Sculpt *sd, Object *ob)
if (mmd || ob->sculpt->bm)
return 0;
if (me->key && ob->shapenr)
/* non-locked shape keys could be handled in the same way as deformed mesh */
if ((ob->shapeflag & OB_SHAPE_LOCK) == 0 && me->key && ob->shapenr)
return 1;
md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
@ -3423,7 +3424,7 @@ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob)
MEM_freeN(nodes);
/* Modifiers could depend on mesh normals, so we should update them/
* Note, then if sculpting happens on key, normals should be re-calculated
* Note, then if sculpting happens on locked key, normals should be re-calculated
* after applying coords from keyblock on base mesh */
BKE_mesh_calc_normals(me);
}
@ -4465,7 +4466,7 @@ static void sculpt_flush_update(bContext *C)
if (ob->derivedFinal) /* VBO no longer valid */
GPU_drawobject_free(ob->derivedFinal);
if (ss->modifiers_active) {
if (ss->kb || ss->modifiers_active) {
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
ED_region_tag_redraw(ar);
}
@ -4566,8 +4567,19 @@ static void sculpt_stroke_update_step(bContext *C, struct PaintStroke *UNUSED(st
/* hack to fix noise texture tearing mesh */
sculpt_fix_noise_tear(sd, ob);
if (ss->modifiers_active)
/* TODO(sergey): This is not really needed for the solid shading,
* which does use pBVH drawing anyway, but texture and wireframe
* requires this.
*
* Could be optimized later, but currently don't think it's so
* much common scenario.
**
** Same applies to the DAG_id_tag_update() invoked from
* sculpt_flush_update().
*/
if (ss->kb || ss->modifiers_active) {
sculpt_flush_stroke_deform(sd, ob);
}
ss->cache->first_time = false;