[Bf-blender-cvs] [adda09c4180] greasepencil-object: Code Cleanup: Move 2D Monkey code to its own file in editors/gpencil

Joshua Leung noreply at git.blender.org
Wed Sep 27 03:01:39 CEST 2017


Commit: adda09c4180f133a1c525ac46743c1fd28c28381
Author: Joshua Leung
Date:   Wed Sep 27 13:55:28 2017 +1300
Branches: greasepencil-object
https://developer.blender.org/rBadda09c4180f133a1c525ac46743c1fd28c28381

Code Cleanup: Move 2D Monkey code to its own file in editors/gpencil

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/CMakeLists.txt
A	source/blender/editors/gpencil/gpencil_add_monkey.c
M	source/blender/editors/include/ED_gpencil.h
M	source/blender/editors/object/object_add.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index e806626b864..fa90750fdda 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -81,7 +81,6 @@ 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);
@@ -103,6 +102,20 @@ struct bGPDbrush *BKE_gpencil_brush_addnew(struct ToolSettings *ts, const char *
 struct bGPDbrush *BKE_gpencil_brush_duplicate(const struct bGPDbrush *brush_src);
 void BKE_gpencil_brush_init_presets(struct ToolSettings *ts);
 
+
+/* Utilities for creating and populating GP strokes */
+/* - Number of values defining each point in the built-in data 
+ *   buffers for primitives (e.g. 2D Monkey) 
+ */
+#define GP_PRIM_DATABUF_SIZE  5
+
+void BKE_gpencil_stroke_add_points(struct bGPDstroke *gps, float *array, int totpoints);
+
+struct bGPDstroke *BKE_gpencil_add_stroke(
+        struct bGPDframe *gpf, struct Palette *palette, struct PaletteColor *palcolor, int totpoints,
+        const char *colorname, short thickness);
+
+
 /* conversion of animation data from bGPDpalette to Palette */
 void BKE_gpencil_move_animdata_to_palettes(struct bContext *C, struct bGPdata *gpd);
 
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index b3bd6bd0b6f..cf4c48adf1c 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -789,8 +789,65 @@ bGPdata *BKE_gpencil_data_addnew(const char name[])
 	return gpd;
 }
 
+
+/* -------- Primitive Creation -------- */
+/* Utilities for easier bulk-creation of geometry */
+
+/** 
+ * Populate stroke with point data from data buffers
+ *
+ * \param array Flat array of point data values. Each entry has GP_PRIM_DATABUF_SIZE values
+ */
+void BKE_gpencil_stroke_add_points(bGPDstroke *gps, float *array, int totpoints)
+{
+	for (int i = 0; i < totpoints; i++) {
+		bGPDspoint *pt = &gps->points[i];
+		const int x = GP_PRIM_DATABUF_SIZE * 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];
+	}
+}
+
+/* Create a new stroke, with pre-allocated data buffers */
+bGPDstroke *BKE_gpencil_add_stroke(
+        bGPDframe *gpf, Palette *palette, PaletteColor *palcolor, int totpoints,
+        const char *colorname, short thickness)
+{
+	/* allocate memory for a new stroke */
+	bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke");
+	
+	gps->thickness = thickness * (GP_DEFAULT_PIX_FACTOR / 40);
+	gps->inittime = 0;
+	
+	/* enable recalculation flag by default */
+	gps->flag = GP_STROKE_RECALC_CACHES | GP_STROKE_3DSPACE;
+	
+	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;
+}
+
+
 /* -------- Data Duplication ---------- */
-/* make a copy of a given gpencil point weights*/
+
+/* make a copy of a given gpencil point weights */
 void BKE_gpencil_stroke_weights_duplicate(bGPDstroke *gps_src, bGPDstroke *gps_dst)
 {
 	if (gps_src == NULL) {
@@ -1853,1387 +1910,3 @@ 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,
-        const char *colorname, short thickness)
-{
-	/* allocate memory for a new stroke */
-	bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke");
-
-	gps->thickness = thickness * (GP_DEFAULT_PIX_FACTOR / 40);
-	gps->inittime = 0;
-	/* enable recalculation flag by default */
-	gps->flag = GP_STROKE_RECALC_CACHES | GP_STROKE_3DSPACE;
-
-	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.509f, 0.0f, -0.156f, 0.267f, 0.362f, -0.522f, 0.0f, -0.159f, 0.31f, 0.407f, -0.531f, 0.0f, -0.16f, 0.347f, 0.426f, -0.543f, -0.0f, -0.162f, 0.38f, 0.439f,
-		-0.554f, -0.0f, -0.163f, 0.409f, 0.448f, -0.566f, -0.0f, -0.165f, 0.433f, 0.458f, -0.578f, -0.0f, -0.167f, 0.454f, 0.478f, -0.591f, -0.0f, -0.168f, 0.471f, 0.5f,
-		-0.604f, -0.0f, -0.169f, 0.485f, 0.51f, -0.619f, -0.0f, -0.171f, 0.496f, 0.516f, -0.634f, -0.0f, -0.171f, 0.504f, 0.519f, -0.649f, -0.0f, -0.171f, 0.511f, 0.519f,
-		-0.665f, -0.0f, -0.17f, 0.516f, 0.521f, -0.681f, -0.0f, -0.17f, 0.521f, 0.53f, -0.697f, -0.0f, -0.169f, 0.524f, 0.533f, -0.713f, -0.0f, -0.167f, 0.527f, 0.533f,
-		-0.729f, 0.0f, -0.165f, 0.53f, 0.534f, -0.745f, 0.0f, -0.161f, 0.531f, 0.534f, -0.761f, 0.0f, -0.157f, 0.533f, 0.535f, -0.777f, 0.0f, -0.153f, 0.534f, 0.535f,
-		-0.792f, 0.0f, -0.148f, 0.535f, 0.536f, -0.808f, 0.0f, -0.144f, 0.535f, 0.535f, -0.822f, 0.0f, -0.139f, 0.536f, 0.537f, -0.837f, 0.0f, -0.133f, 0.536f, 0.537f,
-		-0.852f, 0.0f, -0.128f, 0.536f, 0.537f, -0.866f, 0.0f, -0.122f, 0.536f, 0.537f, -0.88f, 0.0f, -0.115f, 0.536f, 0.537f, -0.894f, 0.0f, -0.109f, 0.536f, 0.537f,
-		-0.908f, 0.0f, -0.101f, 0.535f, 0.535f, -0.922f, 0.0f, -0.092f, 0.535f, 0.535f, -0.936f, 0.0f, -0.082f, 0.534f, 0.534f, -0.949f, 0.0f, -0.072f, 0.534f, 0.534f,
-		-0.963f, 0.0f, -0.061f, 0.534f, 0.534f, -0.976f, 0.0f, -0.05f, 0.534f, 0.534f, -0.988f, 0.0f, -0.039f, 0.534f, 0.534f, -1.0f, 0.0f, -0.028f, 0.533f, 0.534f,
-		-1.011f, 0.0f, -0.017f, 0.533f, 0.533f, -1.022f, 0.0f, -0.007f, 0.533f, 0.534f, -1.033f, 0.0f, 0.004f, 0.533f, 0.533f, -1.043f, 0.0f, 0.014f, 0.532f, 0.532f,
-		-1.053f, 0.0f, 0.025f, 0.532f, 0.532f, -1.062f, 0.0f, 0.036f, 0.531f, 0.531f, -1.071f, 0.0f, 0.046f, 0.531f, 0.531f, -1.078f, 0.0f, 0.057f, 0.531f, 0.531f,
-		-1.085f, 0.0f, 0.068f, 0.531f, 0.531f, -1.092f, 0.0f, 0.08f, 0.532f, 0.532f, -1.098f, 0.0f, 0.091f, 0.533f, 0.533f, -1.104f, 0.0f, 0.105f, 0.535f, 0.535f,
-		-1.11f, 0.0f, 0.119f, 0.539f, 0.539f, -1.115f, 0.0f, 0.133f, 0.54f, 0.54f, -1.118f, 0.0f, 0.148f, 0.541f, 0.541f, -1.121f, 0.0f, 0.162f, 0.542f, 0.542f,
-		-1.123f, 0.0f, 0.177f, 0.542f, 0.542f, -1.125f, 0.0f, 0.193f, 0.543f, 0.543f, -1.125f, 0.0f, 0.208f, 0.543f, 0.543f, -1.125f, 0.0f, 0.225f, 0.543f, 0.543f,
-		-1.124f, 0.0f, 0.241f, 0.545f, 0.545f, -1.122f, 0.0f, 0.258f, 0.546f, 0.546f, -1.119f, 0.0f, 0.274f, 0.548f, 0.548f, -1.116f, 0.0f, 0.29f, 0.549f, 0.549f,
-		-1.111f, 0.0f, 0.305f, 0.549f, 0.549f, -1.106f, 0.0f, 0.318f, 0.549f, 0.549f, -1.1f, 0.0f, 0.33f, 0.549f, 0.549f, -1.094f, 0.0f, 0.34f, 0.549f, 0.549f,
-		-1.087f, 0.0f, 0.349f, 0.55f, 0.55f, -1.08f, 0.0f, 0.357f, 0.549f, 0.549f, -1.072f, 0.0f, 0.365f, 0.55f, 0.55f, -1.063f, 0.0f, 0.372f, 0.551f, 0.551f,
-		-1.054f, 0.0f, 0.379f, 0.552f, 0.552f, -1.044f, 0.0f, 0.385f, 0.553f, 0.553f, -1.034f, 0.0f, 0.391f, 0.553f

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list