[Bf-blender-cvs] [8f0e5be8aab] greasepencil-object: Add a primitive for 2D Suzanne

Antonio Vazquez noreply at git.blender.org
Thu Aug 3 20:43:13 CEST 2017


Commit: 8f0e5be8aab1427520fbe8b70a3827cc6a44b70e
Author: Antonio Vazquez
Date:   Thu Aug 3 20:42:19 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB8f0e5be8aab1427520fbe8b70a3827cc6a44b70e

Add a primitive for 2D Suzanne

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/object/object_add.c
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_object.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 9fd485170bd..f53628d9182 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -1268,7 +1268,7 @@ class INFO_MT_add(Menu):
         layout.menu("INFO_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
         layout.operator_menu_enum("object.empty_add", "type", text="Empty", icon='OUTLINER_OB_EMPTY')
-        layout.operator("object.gpencil_add", text="Gpencil", icon='OUTLINER_OB_GPENCIL')
+        layout.operator_menu_enum("object.gpencil_add", "type", text="GPencil", icon='OUTLINER_OB_GPENCIL')
         layout.separator()
 
         layout.operator("object.speaker_add", text="Speaker", icon='OUTLINER_OB_SPEAKER')
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index b8c920093dc..bf733bf4869 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -78,6 +78,7 @@ struct bGPDframe *BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe);
 struct bGPDframe *BKE_gpencil_frame_addcopy(struct bGPDlayer *gpl, int cframe);
 struct bGPDlayer *BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive);
 struct bGPdata   *BKE_gpencil_data_addnew(const char name[]);
+void BKE_gpencil_create_monkey(struct bContext *C, struct bGPdata *gpd);
 
 struct bGPDframe *BKE_gpencil_frame_duplicate(const struct bGPDframe *gpf_src);
 struct bGPDframe *BKE_gpencil_frame_color_duplicate(const struct bGPDframe *gpf_src);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 95bfdf661fa..6b646510a5e 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -61,6 +61,7 @@
 #include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_object.h"
+#include "BKE_paint.h"
 
 /* Draw Engine */
 void(*BKE_gpencil_batch_cache_dirty_cb)(bGPdata *gpd) = NULL;
@@ -1803,3 +1804,1385 @@ bool BKE_gpencil_vgroup_remove_point_weight(bGPDspoint *pt, int index)
 
 	return true;
 }
+
+/* helpers to create the monkey */
+static void gpencil_add_points(bGPDstroke *gps, float *array, int totpoints)
+{
+	for (int i = 0; i < totpoints; ++i) {
+		bGPDspoint *pt = &gps->points[i];
+		int x = 5 * i;
+		pt->x = array[x];
+		pt->y = array[x + 1];
+		pt->z = array[x + 2];
+		pt->pressure = array[x + 3];
+		pt->strength = array[x + 4];
+	}
+}
+
+static bGPDstroke *gpencil_add_stroke(bGPDframe *gpf, Palette *palette, PaletteColor *palcolor, int totpoints, 
+	char *colorname, short thickness)
+{
+	/* allocate memory for a new stroke */
+	bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke");
+
+	gps->thickness = thickness;
+	gps->inittime = 0;
+	/* enable recalculation flag by default */
+	gps->flag = GP_STROKE_RECALC_CACHES;
+
+	gps->totpoints = totpoints;
+	gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
+	/* initialize triangle memory to dummy data */
+	gps->triangles = MEM_callocN(sizeof(bGPDtriangle), "GP Stroke triangulation");
+	gps->flag |= GP_STROKE_RECALC_CACHES;
+	gps->tot_triangles = 0;
+
+	gps->palette = palette;
+	gps->palcolor = palcolor;
+	BLI_strncpy(gps->colorname, colorname, sizeof(gps->colorname));
+
+	/* add to frame */
+	BLI_addtail(&gpf->strokes, gps);
+	
+	return gps;
+}
+
+/* add a 2D Suzanne (original model created by Matias Mendiola) */
+void BKE_gpencil_create_monkey(bContext *C, bGPdata *gpd)
+{
+	bGPDstroke *gps;
+	Scene *scene = CTX_data_scene(C);
+	/* create palette and colors */
+	Palette *palette = BKE_palette_add(G.main, "Palette");
+
+	PaletteColor *color_Black = BKE_palette_color_add_name(palette, "Black");
+	ARRAY_SET_ITEMS(color_Black->rgb, 0.0f, 0.0f, 0.0f, 1.0f);
+	ARRAY_SET_ITEMS(color_Black->fill, 0.0f, 0.0f, 0.0f, 0.0f);
+	PaletteColor *color_Skin = BKE_palette_color_add_name(palette, "Skin");
+	ARRAY_SET_ITEMS(color_Skin->rgb, 0.553f, 0.39f, 0.266f, 0.0f);
+	ARRAY_SET_ITEMS(color_Skin->fill, 0.733f, 0.567f, 0.359f, 1.0f);
+	PaletteColor *color_Skin_Light = BKE_palette_color_add_name(palette, "Skin_Light");
+	ARRAY_SET_ITEMS(color_Skin_Light->rgb, 0.553f, 0.39f, 0.266f, 0.0f);
+	ARRAY_SET_ITEMS(color_Skin_Light->fill, 0.913f, 0.828f, 0.637f, 1.0f);
+	PaletteColor *color_Skin_Shadow = BKE_palette_color_add_name(palette, "Skin_Shadow");
+	ARRAY_SET_ITEMS(color_Skin_Shadow->rgb, 0.553f, 0.39f, 0.266f, 0.0f);
+	ARRAY_SET_ITEMS(color_Skin_Shadow->fill, 0.32f, 0.29f, 0.223f, 1.0f);
+	PaletteColor *color_Eyes = BKE_palette_color_add_name(palette, "Eyes");
+	ARRAY_SET_ITEMS(color_Eyes->rgb, 0.553f, 0.39f, 0.266f, 0.0f);
+	ARRAY_SET_ITEMS(color_Eyes->fill, 0.773f, 0.762f, 0.73f, 1.0f);
+	PaletteColor *color_Pupils = BKE_palette_color_add_name(palette, "Pupils");
+	ARRAY_SET_ITEMS(color_Pupils->rgb, 0.107f, 0.075f, 0.051f, 0.0f);
+	ARRAY_SET_ITEMS(color_Pupils->fill, 0.153f, 0.057f, 0.063f, 1.0f);
+
+	/* layers */
+	bGPDlayer *Colors = BKE_gpencil_layer_addnew(gpd, "Colors", false);
+	bGPDlayer *Lines = BKE_gpencil_layer_addnew(gpd, "Lines", true);
+
+	/* frames */
+	bGPDframe *frameColor = BKE_gpencil_frame_addnew(Colors, CFRA);
+	bGPDframe *frameLines = BKE_gpencil_frame_addnew(Lines, CFRA);
+
+	gps = gpencil_add_stroke(frameColor, palette, color_Skin, 538, "Skin", 3);
+	float data0[538 * 5] = { -0.506f, -0.0f, 1.352f, 0.267f, 0.362f, -0.517f, -0.0f, 1.35f, 0.31f, 0.407f, -0.528f, -0.0f, 1.348f, 0.347f, 0.426f, -0.539f, -0.0f, 1.346f, 0.38f, 0.439f,
+		-0.551f, -0.0f, 1.343f, 0.409f, 0.448f, -0.562f, -0.0f, 1.34f, 0.433f, 0.458f, -0.576f, -0.0f, 1.337f, 0.454f, 0.478f, -0.589f, -0.0f, 1.334f, 0.471f, 0.5f,
+		-0.603f, -0.0f, 1.332f, 0.485f, 0.51f, -0.618f, -0.0f, 1.33f, 0.496f, 0.516f, -0.633f, -0.0f, 1.328f, 0.504f, 0.519f, -0.649f, -0.0f, 1.328f, 0.511f, 0.519f,
+		-0.665f, -0.0f, 1.329f, 0.516f, 0.521f, -0.681f, -0.0f, 1.331f, 0.521f, 0.53f, -0.697f, -0.0f, 1.333f, 0.524f, 0.533f, -0.713f, 0.0f, 1.338f, 0.527f, 0.533f,
+		-0.73f, 0.0f, 1.341f, 0.53f, 0.534f, -0.747f, 0.0f, 1.345f, 0.531f, 0.534f, -0.764f, 0.0f, 1.35f, 0.533f, 0.535f, -0.779f, 0.0f, 1.354f, 0.534f, 0.535f,
+		-0.795f, 0.0f, 1.36f, 0.535f, 0.536f, -0.81f, 0.0f, 1.365f, 0.535f, 0.535f, -0.824f, 0.0f, 1.37f, 0.536f, 0.537f, -0.838f, 0.0f, 1.376f, 0.536f, 0.537f,
+		-0.851f, 0.0f, 1.381f, 0.536f, 0.537f, -0.864f, 0.0f, 1.387f, 0.536f, 0.537f, -0.877f, 0.0f, 1.394f, 0.536f, 0.537f, -0.89f, 0.0f, 1.401f, 0.536f, 0.537f,
+		-0.903f, 0.0f, 1.409f, 0.535f, 0.535f, -0.917f, 0.0f, 1.418f, 0.535f, 0.535f, -0.931f, 0.0f, 1.427f, 0.534f, 0.534f, -0.945f, 0.0f, 1.438f, 0.534f, 0.534f,
+		-0.96f, 0.0f, 1.448f, 0.534f, 0.534f, -0.974f, 0.0f, 1.459f, 0.534f, 0.534f, -0.987f, 0.0f, 1.47f, 0.534f, 0.534f, -1.0f, 0.0f, 1.481f, 0.533f, 0.534f,
+		-1.014f, 0.0f, 1.492f, 0.533f, 0.533f, -1.025f, 0.0f, 1.503f, 0.533f, 0.534f, -1.038f, 0.0f, 1.512f, 0.533f, 0.533f, -1.047f, 0.0f, 1.522f, 0.532f, 0.532f,
+		-1.057f, 0.0f, 1.53f, 0.532f, 0.532f, -1.067f, 0.0f, 1.542f, 0.531f, 0.531f, -1.072f, 0.0f, 1.55f, 0.531f, 0.531f, -1.079f, 0.0f, 1.566f, 0.531f, 0.531f,
+		-1.088f, 0.0f, 1.574f, 0.531f, 0.531f, -1.093f, 0.0f, 1.586f, 0.532f, 0.532f, -1.102f, 0.0f, 1.595f, 0.533f, 0.533f, -1.107f, 0.0f, 1.612f, 0.535f, 0.535f,
+		-1.115f, 0.0f, 1.626f, 0.539f, 0.539f, -1.122f, 0.0f, 1.645f, 0.54f, 0.54f, -1.126f, 0.0f, 1.655f, 0.541f, 0.541f, -1.128f, 0.0f, 1.669f, 0.542f, 0.542f,
+		-1.127f, 0.0f, 1.683f, 0.542f, 0.542f, -1.13f, 0.0f, 1.698f, 0.543f, 0.543f, -1.128f, 0.0f, 1.712f, 0.543f, 0.543f, -1.129f, 0.0f, 1.732f, 0.543f, 0.543f,
+		-1.126f, 0.0f, 1.746f, 0.545f, 0.545f, -1.124f, 0.0f, 1.76f, 0.546f, 0.546f, -1.122f, 0.0f, 1.784f, 0.548f, 0.548f, -1.121f, 0.0f, 1.803f, 0.549f, 0.549f,
+		-1.117f, 0.0f, 1.82f, 0.549f, 0.549f, -1.108f, 0.0f, 1.834f, 0.549f, 0.549f, -1.1f, 0.0f, 1.842f, 0.549f, 0.549f, -1.095f, 0.0f, 1.851f, 0.549f, 0.549f,
+		-1.086f, 0.0f, 1.855f, 0.55f, 0.55f, -1.083f, 0.0f, 1.864f, 0.549f, 0.549f, -1.074f, 0.0f, 1.873f, 0.55f, 0.55f, -1.065f, 0.0f, 1.878f, 0.551f, 0.551f,
+		-1.053f, 0.0f, 1.891f, 0.552f, 0.552f, -1.045f, 0.0f, 1.895f, 0.553f, 0.553f, -1.036f, 0.0f, 1.9f, 0.553f, 0.553f, -1.023f, 0.0f, 1.904f, 0.554f, 0.554f,
+		-1.014f, 0.0f, 1.908f, 0.554f, 0.554f, -1.005f, 0.0f, 1.913f, 0.554f, 0.554f, -0.996f, 0.0f, 1.917f, 0.554f, 0.554f, -0.983f, 0.0f, 1.922f, 0.555f, 0.555f,
+		-0.966f, 0.0f, 1.926f, 0.555f, 0.555f, -0.948f, 0.0f, 1.924f, 0.556f, 0.556f, -0.934f, 0.0f, 1.923f, 0.556f, 0.556f, -0.918f, 0.0f, 1.92f, 0.557f, 0.557f,
+		-0.907f, 0.0f, 1.916f, 0.557f, 0.557f, -0.894f, 0.0f, 1.911f, 0.557f, 0.557f, -0.88f, 0.0f, 1.904f, 0.557f, 0.558f, -0.868f, 0.0f, 1.898f, 0.557f, 0.557f,
+		-0.856f, 0.0f, 1.892f, 0.557f, 0.557f, -0.845f, 0.0f, 1.886f, 0.557f, 0.557f, -0.835f, 0.0f, 1.881f, 0.558f, 0.557f, -0.825f, 0.0f, 1.875f, 0.558f, 0.557f,
+		-0.816f, 0.0f, 1.871f, 0.558f, 0.558f, -0.806f, 0.0f, 1.867f, 0.558f, 0.558f, -0.797f, 0.0f, 1.863f, 0.557f, 0.559f, -0.788f, 0.0f, 1.861f, 0.557f, 0.559f,
+		-0.78f, 0.0f, 1.859f, 0.556f, 0.559f, -0.771f, 0.0f, 1.858f, 0.556f, 0.559f, -0.763f, 0.0f, 1.857f, 0.555f, 0.559f, -0.755f, 0.0f, 1.858f, 0.554f, 0.559f,
+		-0.746f, 0.0f, 1.859f, 0.553f, 0.554f, -0.739f, 0.0f, 1.862f, 0.552f, 0.548f, -0.732f, 0.0f, 1.864f, 0.551f, 0.544f, -0.725f, 0.0f, 1.868f, 0.551f, 0.546f,
+		-0.718f, 0.0f, 1.872f, 0.55f, 0.546f, -0.711f, 0.0f, 1.878f, 0.55f, 0.547f, -0.704f, 0.0f, 1.883f, 0.549f, 0.547f, -0.697f, 0.0f, 1.89f, 0.549f, 0.547f,
+		-0.691f, 0.0f, 1.897f, 0.549f, 0.548f, -0.684f, 0.0f, 1.904f, 0.549f, 0.548f, -0.677f, 0.0f, 1.912f, 0.549f, 0.549f, -0.671f, 0.0f, 1.921f, 0.549f, 0.548f,
+		-0.665f, 0.0f, 1.93f, 0.549f, 0.549f, -0.658f, 0.0f, 1.94f, 0.55f, 0.549f, -0.651f, 0.0f, 1.95f, 0.551f, 0.548f, -0.645f, 0.0f, 1.961f, 0.552f, 0.548f,
+		-0.639f, 0.0f, 1.972f, 0.554f, 0.548f, -0.632f, 0.0f, 1.983f, 0.556f, 0.549f, -0.625f, 0.0f, 1.994f, 0.559f, 0.549f, -0.617f, 0.0f, 2.005f, 0.563f, 0.549f,
+		-0.61f, 0.0f, 2.017f, 0.567f, 0.549f, -0.602f, 0.0f, 2.028f, 0.572f, 0.558f, -0.594f, 0.0f, 2.039f, 0.577f, 0.574f, -0.586f, 0.0f, 2.05f, 0.582f, 0.587f,
+		-0

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list