Modifier: remove derived mesh call for bind

This commit is contained in:
Campbell Barton 2018-10-12 18:39:24 +11:00
parent b15123d279
commit fe1befcadf
1 changed files with 19 additions and 31 deletions

View File

@ -98,6 +98,23 @@ static void modifier_skin_customdata_delete(struct Object *ob);
/******************************** API ****************************/
static void object_force_modifier_update_for_bind(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
if (ob->type == OB_MESH) {
Mesh *me_eval = mesh_create_eval_final_view(depsgraph, scene, ob, 0);
BKE_id_free(NULL, me_eval);
}
else if (ob->type == OB_LATTICE) {
BKE_lattice_modifiers_calc(depsgraph, scene, ob);
}
else if (ob->type == OB_MBALL) {
BKE_displist_make_mball(depsgraph, scene, ob);
}
else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
BKE_displist_make_curveTypes(depsgraph, scene, ob, 0);
}
}
ModifierData *ED_object_modifier_add(ReportList *reports, Main *bmain, Scene *scene, Object *ob, const char *name, int type)
{
ModifierData *md = NULL, *new_md = NULL;
@ -2269,27 +2286,13 @@ static int laplaciandeform_bind_exec(bContext *C, wmOperator *op)
lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND;
}
else {
DerivedMesh *dm;
int mode = lmd->modifier.mode;
/* Force modifier to run, it will call binding routine. */
/* TODO(Sybren): deduplicate the code below, it's used multiple times here. */
lmd->modifier.mode |= eModifierMode_Realtime;
lmd->flag |= MOD_LAPLACIANDEFORM_BIND;
if (ob->type == OB_MESH) {
dm = mesh_create_derived_view(depsgraph, scene, ob, 0);
dm->release(dm);
}
else if (ob->type == OB_LATTICE) {
BKE_lattice_modifiers_calc(depsgraph, scene, ob);
}
else if (ob->type == OB_MBALL) {
BKE_displist_make_mball(depsgraph, scene, ob);
}
else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
BKE_displist_make_curveTypes(depsgraph, scene, ob, 0);
}
object_force_modifier_update_for_bind(depsgraph, scene, ob);
lmd->modifier.mode = mode;
}
@ -2340,39 +2343,24 @@ static int surfacedeform_bind_exec(bContext *C, wmOperator *op)
if (!smd)
return OPERATOR_CANCELLED;
if (smd->flags & MOD_SDEF_BIND) {
/* Un-binding happens inside the modifier when it's evaluated. */
smd->flags &= ~MOD_SDEF_BIND;
}
else if (smd->target) {
DerivedMesh *dm;
int mode = smd->modifier.mode;
/* Force modifier to run, it will call binding routine. */
smd->modifier.mode |= eModifierMode_Realtime;
smd->flags |= MOD_SDEF_BIND;
if (ob->type == OB_MESH) {
dm = mesh_create_derived_view(depsgraph, scene, ob, 0);
dm->release(dm);
}
else if (ob->type == OB_LATTICE) {
BKE_lattice_modifiers_calc(depsgraph, scene, ob);
}
else if (ob->type == OB_MBALL) {
BKE_displist_make_mball(depsgraph, scene, ob);
}
else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
BKE_displist_make_curveTypes(depsgraph, scene, ob, 0);
}
object_force_modifier_update_for_bind(depsgraph, scene, ob);
smd->modifier.mode = mode;
}
DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
}