[Bf-blender-cvs] [bdeceba5f68] greasepencil-object: Add Lock to axis and opacity control to grid

Antonioya noreply at git.blender.org
Sat Jul 28 17:58:34 CEST 2018


Commit: bdeceba5f68e5c7ecb184936af655d3060687106
Author: Antonioya
Date:   Sat Jul 28 17:58:27 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rBbdeceba5f68e5c7ecb184936af655d3060687106

Add Lock to axis and opacity control to grid

Now, the grid axis can be automatically set to the current lock axis

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 10c15b6e8ce..f468042719a 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4733,7 +4733,13 @@ class VIEW3D_PT_overlay_gpencil_options(Panel):
         sub.active = overlay.use_gpencil_paper
         sub.prop(overlay, "gpencil_paper_opacity", text="Fade 3D Objects")
 
-        layout.prop(overlay, "use_gpencil_grid", text="Show Plane Grid")
+        col = layout.column()
+        row = col.row()
+        row.prop(overlay, "use_gpencil_grid", text="")
+        sub = row.row()
+        sub.active = overlay.use_gpencil_grid
+        sub.prop(overlay, "gpencil_grid_opacity", text="Plane Grid")
+
         if overlay.use_gpencil_grid:
             layout.prop(overlay, "gpencil_grid_scale")
             row = layout.row()
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index b7b549c96d7..65043b0afb5 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -993,6 +993,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 							v3d->gpencil_grid_lines = GP_DEFAULT_GRID_LINES; // NUmber of lines
 							v3d->gpencil_paper_opacity = 0.5f;
 							v3d->gpencil_grid_axis = V3D_GP_GRID_AXIS_Y;
+							v3d->gpencil_grid_opacity = 0.9f;
 						}
 					}
 				}
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 1241c88b061..77e55861bf6 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -600,9 +600,9 @@ GPUBatch *DRW_gpencil_get_edlin_geom(bGPDstroke *gps, float alpha, short UNUSED(
 	return GPU_batch_create_ex(GPU_PRIM_LINE_STRIP, vbo, NULL, GPU_BATCH_OWNS_VBO);
 }
 
-static void set_grid_point(GPUVertBuf *vbo, int idx, uchar col_grid[3],
+static void set_grid_point(GPUVertBuf *vbo, int idx, float col_grid[4],
 						uint pos_id, uint color_id,
-						float v1, float v2, const int axis)
+						float v1, float v2, int axis)
 {
 	GPU_vertbuf_attr_set(vbo, color_id, idx, col_grid);
 
@@ -635,12 +635,12 @@ GPUBatch *DRW_gpencil_get_grid(void)
 {
 	const DRWContextState *draw_ctx = DRW_context_state_get();
 	Scene *scene = draw_ctx->scene;
+	ToolSettings *ts = scene->toolsettings;
 	View3D *v3d = draw_ctx->v3d;
 
-	uchar col_grid[3];
-	UI_GetThemeColor3ubv(TH_GRID, col_grid);
+	float col_grid[4];
 
-	/* verify we have something to draw */
+	/* verify we have something to draw and valid values */
 	if (v3d->gpencil_grid_lines < 4) {
 		v3d->gpencil_grid_lines = GP_DEFAULT_GRID_LINES;
 	}
@@ -649,11 +649,40 @@ GPUBatch *DRW_gpencil_get_grid(void)
 		v3d->gpencil_grid_scale = 1.0f;
 	}
 
-	if (v3d->gpencil_grid_axis == 0) {
-		v3d->gpencil_grid_axis |= V3D_GP_GRID_AXIS_Y;
+	if (v3d->gpencil_grid_opacity < 0.1f) {
+		v3d->gpencil_grid_opacity = 0.1f;
+	}
+
+	UI_GetThemeColor3fv(TH_GRID, col_grid);
+	col_grid[3] = v3d->gpencil_grid_opacity;
+
+	/* if use locked axis, copy value */
+	int axis = v3d->gpencil_grid_axis;
+	if ((v3d->gpencil_grid_axis & V3D_GP_GRID_AXIS_LOCK) == 0) {
+
+		axis = v3d->gpencil_grid_axis;
+	}
+	else {
+		switch (ts->gp_sculpt.lock_axis) {
+			case GP_LOCKAXIS_X:
+			{
+				axis = V3D_GP_GRID_AXIS_X;
+				break;
+			}
+			case GP_LOCKAXIS_NONE:
+			case GP_LOCKAXIS_Y:
+			{
+				axis = V3D_GP_GRID_AXIS_Y;
+				break;
+			}
+			case GP_LOCKAXIS_Z:
+			{
+				axis = V3D_GP_GRID_AXIS_Z;
+				break;
+			}
+		}
 	}
 
-	const int axis = v3d->gpencil_grid_axis;
 	const char *grid_unit = NULL;
 	const int gridlines = v3d->gpencil_grid_lines / 2; 
 	const float grid_scale = v3d->gpencil_grid_scale * ED_scene_grid_scale(scene, &grid_unit);
@@ -665,7 +694,7 @@ GPUBatch *DRW_gpencil_get_grid(void)
 	static uint pos_id, color_id;
 	if (format.attr_len == 0) {
 		pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
-		color_id = GPU_vertformat_attr_add(&format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+		color_id = GPU_vertformat_attr_add(&format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
 	}
 
 	GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 1fe3a39e49d..ff563cea353 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -346,6 +346,7 @@ static SpaceLink *view3d_new(const ScrArea *UNUSED(sa), const Scene *scene)
 	v3d->gpencil_grid_lines = GP_DEFAULT_GRID_LINES; // NUmber of Lines
 	v3d->gpencil_paper_opacity = 0.5f;
 	v3d->gpencil_grid_axis = V3D_GP_GRID_AXIS_Y;
+	v3d->gpencil_grid_opacity = 0.9f;
 
 	v3d->bundle_size = 0.2f;
 	v3d->bundle_drawtype = OB_PLAINAXES;
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index f2b3fec81e6..9883587783d 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -271,6 +271,8 @@ typedef struct View3D {
 	float gpencil_paper_opacity;
 	int   gpencil_grid_lines;
 	int   gpencil_grid_axis;
+	float gpencil_grid_opacity;
+	char pad6[4];
 
 	/* Stereoscopy settings */
 	short stereo3d_flag;
@@ -493,9 +495,10 @@ enum {
 
 /* View3d.gpencil_grid_axis */
 enum {
-	V3D_GP_GRID_AXIS_X = (1 << 1),
-	V3D_GP_GRID_AXIS_Y = (1 << 2),
-	V3D_GP_GRID_AXIS_Z = (1 << 3)
+	V3D_GP_GRID_AXIS_LOCK = (1 << 0),
+	V3D_GP_GRID_AXIS_X    = (1 << 1),
+	V3D_GP_GRID_AXIS_Y    = (1 << 2),
+	V3D_GP_GRID_AXIS_Z    = (1 << 3),
 };
 
 #endif
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 061d48dfd7d..385306bb805 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -310,6 +310,7 @@ const EnumPropertyItem rna_enum_file_sort_items[] = {
 };
 
 static const EnumPropertyItem rna_enum_gpencil_grid_axis_items[] = {
+	{V3D_GP_GRID_AXIS_LOCK, "LOCK", 0, "Lock", "Use current drawing locked axis" },
 	{V3D_GP_GRID_AXIS_X, "X", 0, "X", ""},
 	{V3D_GP_GRID_AXIS_Y, "Y", 0, "Y", ""},
 	{V3D_GP_GRID_AXIS_Z, "Z", 0, "Z", ""},
@@ -2894,6 +2895,13 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Axis", "Axis to display grid");
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
+	prop = RNA_def_property(srna, "gpencil_grid_opacity", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_float_sdna(prop, NULL, "gpencil_grid_opacity");
+	RNA_def_property_range(prop, 0.1f, 1.0f);
+	RNA_def_property_float_default(prop, 0.9f);
+	RNA_def_property_ui_text(prop, "Opacity", "Grid opacity");
+	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
 	/* Paper opacity factor */
 	prop = RNA_def_property(srna, "gpencil_paper_opacity", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_float_sdna(prop, NULL, "gpencil_paper_opacity");



More information about the Bf-blender-cvs mailing list