Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2019-06-25 14:59:59 +0300
committerAntonioya <blendergit@gmail.com>2019-06-25 15:00:34 +0300
commitc186cfe419baa6f715544353b0861c374150b87b (patch)
treeb8b57da7414a9dd127c507cb89fd816b6817348b
parent30bf48c9caee40ce457d58b5bfe7fc398b7e9891 (diff)
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.
-rw-r--r--source/blender/editors/gpencil/gpencil_data.c42
-rw-r--r--source/blender/editors/include/ED_gpencil.h6
-rw-r--r--source/blender/editors/object/object_relations.c11
3 files changed, 59 insertions, 0 deletions
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index a7072facf36..941c7645dc0 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -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;
+}
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 6af8197aa8f..73e239f0d33 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -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
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index 42b27d1d255..e6637265fbc 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -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);