GPencil: Add Lattice modifier when use Ctrl+P to Lattice Deform

When parent a Grease Pencil object to Lattice, automatically a Lattice modifier is added.
This commit is contained in:
2019-06-25 13:59:59 +02:00
parent 30bf48c9ca
commit c186cfe419
3 changed files with 59 additions and 0 deletions

View File

@@ -2895,3 +2895,45 @@ void GPENCIL_OT_color_select(wmOperatorType *ot)
ot->prop = RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Unselect strokes");
RNA_def_property_flag(ot->prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
/* Parent GPencil object to Lattice */
bool ED_gpencil_add_lattice_modifier(const bContext *C,
ReportList *reports,
Object *ob,
Object *ob_latt)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
if (ob == NULL) {
return false;
}
/* if no lattice modifier, add a new one */
GpencilModifierData *md = BKE_gpencil_modifiers_findByType(ob, eGpencilModifierType_Lattice);
if (md == NULL) {
md = ED_object_gpencil_modifier_add(
reports, bmain, scene, ob, "Lattice", eGpencilModifierType_Lattice);
if (md == NULL) {
BKE_report(reports, RPT_ERROR, "Unable to add a new Lattice modifier to object");
return false;
}
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
}
/* verify lattice */
LatticeGpencilModifierData *mmd = (LatticeGpencilModifierData *)md;
if (mmd->object == NULL) {
mmd->object = ob_latt;
}
else {
if (ob_latt != mmd->object) {
BKE_report(reports,
RPT_ERROR,
"The existing Lattice modifier is already using a different Lattice object");
return false;
}
}
return true;
}

View File

@@ -187,6 +187,12 @@ bool ED_gpencil_add_armature_weights(const struct bContext *C,
struct Object *ob_arm,
int mode);
/* Add Lattice modifier using Parent operator */
bool ED_gpencil_add_lattice_modifier(const struct bContext *C,
struct ReportList *reports,
struct Object *ob,
struct Object *ob_latt);
/* keep this aligned with gpencil_armature enum */
#define GP_PAR_ARMATURE_NAME 0
#define GP_PAR_ARMATURE_AUTO 1

View File

@@ -898,6 +898,17 @@ bool ED_object_parent_set(ReportList *reports,
invert_m4_m4(ob->parentinv, workob.obmat);
}
else if ((ob->type == OB_GPENCIL) && (par->type == OB_LATTICE)) {
/* Add Lattice modifier */
if (partype == PAR_LATTICE) {
ED_gpencil_add_lattice_modifier(C, reports, ob, par);
}
/* get corrected inverse */
ob->partype = PAROBJECT;
BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
invert_m4_m4(ob->parentinv, workob.obmat);
}
else {
/* calculate inverse parent matrix */
BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);