[Bf-blender-cvs] [c186cfe419b] master: GPencil: Add Lattice modifier when use Ctrl+P to Lattice Deform

Antonioya noreply at git.blender.org
Tue Jun 25 14:00:39 CEST 2019


Commit: c186cfe419baa6f715544353b0861c374150b87b
Author: Antonioya
Date:   Tue Jun 25 13:59:59 2019 +0200
Branches: master
https://developer.blender.org/rBc186cfe419baa6f715544353b0861c374150b87b

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.

===================================================================

M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/editors/object/object_relations.c

===================================================================

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



More information about the Bf-blender-cvs mailing list