[Bf-blender-cvs] [91767d7e888] lanpr-under-gp: LineArt: Quick line art set-up in add objects menu.

YimingWu noreply at git.blender.org
Tue Jul 28 10:40:11 CEST 2020


Commit: 91767d7e8880078425cbacb46425d786af5dc23a
Author: YimingWu
Date:   Tue Jul 28 16:34:08 2020 +0800
Branches: lanpr-under-gp
https://developer.blender.org/rB91767d7e8880078425cbacb46425d786af5dc23a

LineArt: Quick line art set-up in add objects menu.

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

M	source/blender/editors/gpencil/CMakeLists.txt
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/editors/object/object_add.c
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesrna/intern/rna_object.c

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

diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt
index 735ad8bc039..2ef47eb8673 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -40,6 +40,7 @@ set(SRC
   annotate_paint.c
   drawgpencil.c
   editaction_gpencil.c
+  gpencil_add_lineart.c
   gpencil_add_monkey.c
   gpencil_add_stroke.c
   gpencil_armature.c
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 64276706759..1c2fdf9e3b6 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -244,6 +244,7 @@ void ED_gpencil_brush_draw_eraser(struct Brush *brush, int x, int y);
 
 void ED_gpencil_create_monkey(struct bContext *C, struct Object *ob, float mat[4][4]);
 void ED_gpencil_create_stroke(struct bContext *C, struct Object *ob, float mat[4][4]);
+void ED_gpencil_create_lineart(struct bContext *C, struct Object *ob, float mat[4][4]);
 
 /* ------------ Object Utilities ------------ */
 struct Object *ED_gpencil_add_object(struct bContext *C,
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index f92dafcc7f9..1faaf8f88bf 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -31,6 +31,7 @@
 #include "DNA_camera_types.h"
 #include "DNA_collection_types.h"
 #include "DNA_curve_types.h"
+#include "DNA_gpencil_modifier_types.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_key_types.h"
 #include "DNA_light_types.h"
@@ -66,6 +67,7 @@
 #include "BKE_font.h"
 #include "BKE_gpencil_curve.h"
 #include "BKE_gpencil_geom.h"
+#include "BKE_gpencil_modifier.h"
 #include "BKE_hair.h"
 #include "BKE_key.h"
 #include "BKE_lattice.h"
@@ -1160,7 +1162,7 @@ static bool object_gpencil_add_poll(bContext *C)
 
 static int object_gpencil_add_exec(bContext *C, wmOperator *op)
 {
-  Object *ob = CTX_data_active_object(C);
+  Object *ob = CTX_data_active_object(C), *ob_orig = ob;
   bGPdata *gpd = (ob && (ob->type == OB_GPENCIL)) ? ob->data : NULL;
 
   const int type = RNA_enum_get(op->ptr, "type");
@@ -1188,6 +1190,11 @@ static int object_gpencil_add_exec(bContext *C, wmOperator *op)
         ob_name = "Stroke";
         break;
       }
+      case GP_LRT_OBJECT:
+      case GP_LRT_COLLECTION: {
+        ob_name = "Line Art";
+        break;
+      }
       default: {
         break;
       }
@@ -1228,6 +1235,45 @@ static int object_gpencil_add_exec(bContext *C, wmOperator *op)
       ED_gpencil_create_monkey(C, ob, mat);
       break;
     }
+    case GP_LRT_COLLECTION:
+    case GP_LRT_OBJECT: {
+      float radius = RNA_float_get(op->ptr, "radius");
+      float mat[4][4];
+
+      ED_object_new_primitive_matrix(C, ob, loc, rot, mat);
+      mul_v3_fl(mat[0], radius);
+      mul_v3_fl(mat[1], radius);
+      mul_v3_fl(mat[2], radius);
+
+      ED_gpencil_create_lineart(C, ob, mat);
+
+      gpd = ob->data;
+
+      /* Add Line Art modifier */
+      LineartGpencilModifierData *md = (LineartGpencilModifierData *)BKE_gpencil_modifier_new(
+          eGpencilModifierType_Lineart);
+      BLI_addtail(&ob->greasepencil_modifiers, md);
+      BKE_gpencil_modifier_unique_name(&ob->greasepencil_modifiers, (GpencilModifierData *)md);
+
+      if (type == GP_LRT_COLLECTION) {
+        md->source_type = LRT_SOURCE_COLLECTION;
+        md->source_collection = CTX_data_collection(C);
+      }
+      else {
+        md->source_type = LRT_SOURCE_OBJECT;
+        md->source_object = ob_orig;
+      }
+      /* Only created one layer and one material. */
+      strcpy(md->target_layer, ((bGPDlayer *)gpd->layers.first)->info);
+      md->target_material = BKE_gpencil_material(ob, 1);
+
+      /* Stroke object is drawn in front of meshes by default. */
+      ob->dtx |= OB_DRAW_IN_FRONT;
+
+      /* Turn on Line Art auto update to show the result. */
+      Scene *scene = CTX_data_scene(C);
+      scene->lineart.flags |= LRT_AUTO_UPDATE;
+    }
     case GP_EMPTY:
       /* do nothing */
       break;
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 149352e4a4d..78fd7ed6dcc 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -631,6 +631,8 @@ enum {
   GP_EMPTY = 0,
   GP_STROKE = 1,
   GP_MONKEY = 2,
+  GP_LRT_OBJECT = 3,
+  GP_LRT_COLLECTION = 4,
 };
 
 /* boundtype */
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 4e43c00b96d..f684dfa54f3 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -159,6 +159,16 @@ const EnumPropertyItem rna_enum_object_gpencil_type_items[] = {
     {GP_EMPTY, "EMPTY", ICON_EMPTY_AXIS, "Blank", "Create an empty grease pencil object"},
     {GP_STROKE, "STROKE", ICON_STROKE, "Stroke", "Create a simple stroke with basic colors"},
     {GP_MONKEY, "MONKEY", ICON_MONKEY, "Monkey", "Construct a Suzanne grease pencil object"},
+    {GP_LRT_COLLECTION,
+     "LRT_COLLECTION",
+     ICON_GROUP,
+     "Collection Line Art",
+     "Quickly set up Line Art for active collection"},
+    {GP_LRT_OBJECT,
+     "LRT_OBJECT",
+     ICON_CUBE,
+     "Object Line Art",
+     "Quickly set up Line Art for active collection"},
     {0, NULL, 0, NULL, NULL}};
 
 static const EnumPropertyItem parent_type_items[] = {



More information about the Bf-blender-cvs mailing list