[Bf-blender-cvs] [13b283504f0] greasepencil-object: Create new option to keep stroke thickness

Antonio Vazquez noreply at git.blender.org
Tue Jun 6 13:18:25 CEST 2017


Commit: 13b283504f0613731e4f86827d1078d10b74eb6a
Author: Antonio Vazquez
Date:   Tue Jun 6 13:18:13 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB13b283504f0613731e4f86827d1078d10b74eb6a

Create new option to keep stroke thickness

In some situations is good to be able to keep the stroke thickness when viewport zoom factor change.

This option is disabled by default.

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

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index e4b75388e71..e9e93425195 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -951,7 +951,8 @@ class GreasePencilDataPanel:
             layout.operator("gpencil.layer_add", text="New Layer")
         else:
             row = layout.row()
-            row.prop(gpd, "xray_mode", text="Xray Mode")
+            row.prop(gpd, "xray_mode", text="Draw Mode")
+            row.prop(gpd, "keep_stroke_thickness")
             self.draw_layers(context, layout, gpd)
 
     def draw_layers(self, context, layout, gpd):
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 eba164a12f4..6a2b6bc267e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -311,7 +311,12 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRWPass
 	DRW_shgroup_uniform_float(grp, "pixsize", &rv3d->pixsize, 1);
 	DRW_shgroup_uniform_float(grp, "pixelsize", &U.pixelsize, 1);
 
-	stl->storage->is_persp = rv3d->is_persp ? 1 : 0;
+	stl->storage->is_persp = rv3d->is_persp ? 1 : 2;
+	/* If disable zoom for strokes, disable scale */
+	if ((gpd) && (gpd->flag & GP_DATA_STROKE_KEEPTHICKNESS)) {
+		stl->storage->is_persp = 0;
+	}
+
 	DRW_shgroup_uniform_int(grp, "is_persp", &stl->storage->is_persp, 1);
 
 	if (gpd) {
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
index d5c33ef40ef..d01fd3b6297 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl
@@ -2,7 +2,7 @@ uniform mat4 ModelViewProjectionMatrix;
 
 uniform float pixsize;   /* rv3d->pixsize */
 uniform float pixelsize; /* U.pixelsize */
-uniform int is_persp;    /* rv3d->is_persp (1-yes) */
+uniform int is_persp;    /* rv3d->is_persp (1-yes, 2->Orto), 0: No scale_thickness */
 
 in vec3 pos;
 in vec4 color;
@@ -29,13 +29,13 @@ void main(void)
 	finalColor = color;
 
 	float pixsize = mul_project_m4_v3_zfac(ModelViewProjectionMatrix, pos) * defaultpixsize;
-	float scale_thickness = 0.0f;
+	float scale_thickness = 1.0f;
 	
-	if (is_persp == TRUE) {
+	if (is_persp == 1) {
 		/* need a factor to mimmic old glLine size, 10.0f works fine */
 		scale_thickness = (defaultpixsize / pixsize) * 10.0f;
 	}
-	else {
+	if (is_persp == 2) {
 		scale_thickness = (1.0f / pixsize) / 100.0f;
 	}
 
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index ca935ebb02c..6e272afaca3 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -361,7 +361,9 @@ typedef enum eGPdata_Flag {
 	/* Stroke Paint Mode - Toggle paint mode */
 	GP_DATA_STROKE_PAINTMODE = (1 << 12),
 	/* Stroke Editing Mode - Toggle sculpt mode */
-	GP_DATA_STROKE_SCULPTMODE = (1 << 13)
+	GP_DATA_STROKE_SCULPTMODE = (1 << 13),
+	/* keep stroke thickness unchanged when zoom change */
+	GP_DATA_STROKE_KEEPTHICKNESS = (1 << 14)
 
 } eGPdata_Flag;
 
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 96453ce0185..895a1aaaac6 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -1218,6 +1218,11 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
 	                         "and smaller red dot (end) points");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 
+	prop = RNA_def_property(srna, "keep_stroke_thickness", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_DATA_STROKE_KEEPTHICKNESS);
+	RNA_def_property_ui_text(prop, "Keep thickness", "Show stroke with same thickness when viewport zoom change");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+
 	/* API Functions */
 	func = RNA_def_function(srna, "clear", "rna_GPencil_clear");
 	RNA_def_function_ui_description(func, "Remove all the grease pencil data");




More information about the Bf-blender-cvs mailing list