[Bf-blender-cvs] [f3370eb2bb0] greasepencil-object: Redo UV calculation using color factor
Antonio Vazquez
noreply at git.blender.org
Wed Feb 21 19:33:57 CET 2018
Commit: f3370eb2bb017aa18fe47ff9dd1216b0c5f726c9
Author: Antonio Vazquez
Date: Wed Feb 21 19:32:17 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rBf3370eb2bb017aa18fe47ff9dd1216b0c5f726c9
Redo UV calculation using color factor
Now the Pixel size ratio is determined by a parameter of the color and not by view pixelsize.
This solves various problems and allow the user define dfifferent effects.
NOTE: Still pending to use the same logic while draw.
===================================================================
M release/scripts/startup/bl_ui/properties_material_gpencil.py
M source/blender/blenkernel/intern/paint.c
M source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
M source/blender/draw/engines/gpencil/gpencil_geom.c
M source/blender/editors/gpencil/gpencil_paint.c
M source/blender/editors/gpencil/gpencil_utils.c
M source/blender/editors/include/ED_gpencil.h
M source/blender/makesdna/DNA_brush_types.h
M source/blender/makesrna/intern/rna_palette.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index 9c57f49fab3..664fb95f7d2 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -169,7 +169,10 @@ class MATERIAL_PT_gpencil_palette_strokecolor(Panel):
# Options
row = layout.row()
row.active = not pcolor.lock
- row.prop(pcolor, "pass_index")
+ col = row.column(align=True)
+ col.prop(pcolor, "pass_index")
+ if pcolor.stroke_style == 'TEXTURE':
+ col.prop(pcolor, "pixel_size", text="Pixel Factor")
class MATERIAL_PT_gpencil_palette_fillcolor(Panel):
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 5e0325ac450..db9655de88c 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -606,6 +606,7 @@ PaletteColor *BKE_palette_color_copy(Palette *palette, PaletteColor *palcolor)
copy_v2_v2(newcolor->t_scale, palcolor->t_scale);
copy_v2_v2(newcolor->t_offset, palcolor->t_offset);
newcolor->t_opacity = palcolor->t_opacity;
+ newcolor->t_pixsize = palcolor->t_pixsize;
newcolor->sima = palcolor->sima;
newcolor->ima = palcolor->ima;
@@ -630,6 +631,7 @@ PaletteColor *BKE_palette_color_add_name(Palette *palette, const char *name)
ARRAY_SET_ITEMS(color->g_scale, 1.0f, 1.0f);
ARRAY_SET_ITEMS(color->t_scale, 1.0f, 1.0f);
color->t_opacity = 1.0f;
+ color->t_pixsize = 100.0f;
/* auto-name */
BLI_strncpy(color->info, name, sizeof(color->info));
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 228d4ddaff0..d98259deef4 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -714,7 +714,6 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
*/
const DRWContextState *draw_ctx = DRW_context_state_get();
const bContext *C = draw_ctx->evil_C;
- RegionView3D *rv3d = draw_ctx->rv3d;
EvaluationContext eval_ctx = {0};
if (C) {
@@ -757,7 +756,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
/* be sure recalc all chache in source stroke to avoid recalculation when frame change
* and improve fps */
if (src_gps) {
- DRW_gpencil_recalc_geometry_caches(src_gps, rv3d);
+ DRW_gpencil_recalc_geometry_caches(src_gps);
}
/* if the fill has any value, it's considered a fill and is not drawn if simplify fill is enabled */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index ea5bf27109e..9e378092135 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -31,7 +31,6 @@
struct tGPspoint;
struct ModifierData;
struct GPENCIL_StorageList;
-struct RegionView3D;
/* TODO: these could be system parameter in userprefs screen */
#define GPENCIL_MAX_GP_OBJ 256
@@ -339,7 +338,7 @@ struct Gwn_Batch *DRW_gpencil_get_buffer_stroke_geom(struct bGPdata *gpd, float
struct Gwn_Batch *DRW_gpencil_get_buffer_fill_geom(struct bGPdata *gpd);
struct Gwn_Batch *DRW_gpencil_get_buffer_point_geom(struct bGPdata *gpd, float matrix[4][4], short thickness);
-void DRW_gpencil_recalc_geometry_caches(struct bGPDstroke *gps, struct RegionView3D *rv3d);
+void DRW_gpencil_recalc_geometry_caches(struct bGPDstroke *gps);
struct GPUTexture *DRW_gpencil_create_blank_texture(int width, int height);
diff --git a/source/blender/draw/engines/gpencil/gpencil_geom.c b/source/blender/draw/engines/gpencil/gpencil_geom.c
index b191fd64c2b..0f6389912f9 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -611,7 +611,7 @@ static void gpencil_set_fill_point(
}
/* recalc the internal geometry caches for fill and uvs */
-void DRW_gpencil_recalc_geometry_caches(bGPDstroke *gps, RegionView3D *rv3d) {
+void DRW_gpencil_recalc_geometry_caches(bGPDstroke *gps) {
if (gps->flag & GP_STROKE_RECALC_CACHES) {
/* Calculate triangles cache for filling area (must be done only after changes) */
if ((gps->tot_triangles == 0) || (gps->triangles == NULL)) {
@@ -623,7 +623,7 @@ void DRW_gpencil_recalc_geometry_caches(bGPDstroke *gps, RegionView3D *rv3d) {
}
/* calc uv data along the stroke */
- ED_gpencil_calc_stroke_uv(gps, rv3d->pixsize);
+ ED_gpencil_calc_stroke_uv(gps);
/* clear flag */
gps->flag &= ~GP_STROKE_RECALC_CACHES;
@@ -635,13 +635,10 @@ Gwn_Batch *DRW_gpencil_get_fill_geom(bGPDstroke *gps, const float color[4])
{
BLI_assert(gps->totpoints >= 3);
- const DRWContextState *draw_ctx = DRW_context_state_get();
- RegionView3D *rv3d = draw_ctx->rv3d;
-
/* Calculate triangles cache for filling area (must be done only after changes) */
if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) {
gp_triangulate_stroke_fill(gps);
- ED_gpencil_calc_stroke_uv(gps, rv3d->pixsize);
+ ED_gpencil_calc_stroke_uv(gps);
}
BLI_assert(gps->tot_triangles >= 1);
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index ec0f48e0bdb..8036fab96aa 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -806,7 +806,6 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
bGPDbrush *brush = p->brush;
ToolSettings *ts = p->scene->toolsettings;
Object *obact = (Object *)p->ownerPtr.data;
- RegionView3D *rv3d = p->ar->regiondata;
int i, totelem;
/* since strokes are so fine, when using their depth we need a margin otherwise they might get missed */
@@ -1058,7 +1057,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
BLI_strncpy(gps->colorname, p->palettecolor->info, sizeof(gps->colorname));
/* calculate UVs along the stroke */
- ED_gpencil_calc_stroke_uv(gps, rv3d->pixsize);
+ ED_gpencil_calc_stroke_uv(gps);
/* add stroke to frame, usually on tail of the listbase, but if on back is enabled the stroke is added on listbase head
* because the drawing order is inverse and the head stroke is the first to draw. This is very useful for artist
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 0f358d6bff7..36038a6120b 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1532,16 +1532,24 @@ void ED_gpencil_setup_modes(bContext *C, bGPdata *gpd, int newmode)
}
/* texture coordinate utilities */
-void ED_gpencil_calc_stroke_uv(bGPDstroke *gps, float pixsize)
+void ED_gpencil_calc_stroke_uv(bGPDstroke *gps)
{
- /* TODO: In camera view the pixsize (rv3d->pixsize) looks wrong */
if (gps == NULL) {
return;
}
+ PaletteColor *palcolor = gps->palcolor;
+ float pixsize;
+ if (palcolor) {
+ pixsize = palcolor->t_pixsize / 1000000.0f;
+ }
+ else {
+ /* use this value by default */
+ pixsize = 0.000100f;
+ }
+ pixsize = MAX2(pixsize, 0.0000001f);
bGPDspoint *pt = NULL;
bGPDspoint *ptb = NULL;
- PaletteColor *palcolor = gps->palcolor;
int i;
float totlen = 0;
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 2de5b3fb56b..463808e996c 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -212,6 +212,6 @@ void ED_gpencil_vgroup_deselect(struct bContext *C, struct Object *ob);
int ED_gpencil_join_objects_exec(struct bContext *C, struct wmOperator *op);
/* texture coordinate utilities */
-void ED_gpencil_calc_stroke_uv(struct bGPDstroke *gps, float pixsize);
+void ED_gpencil_calc_stroke_uv(struct bGPDstroke *gps);
#endif /* __ED_GPENCIL_H__ */
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 0062df8b142..53ede5e99f5 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -164,9 +164,9 @@ typedef struct PaletteColor {
float g_shift[2]; /* factor to shift filling in 2d space */
float t_angle; /* angle used for texture orientation */
float t_scale[2]; /* texture scale (separated of uv scale) */
- float t_offset[2]; /* factor to shift texture in 2d space */
+ float t_offset[2]; /* factor to shift texture in 2d space */
float t_opacity; /* texture opacity */
- char pad[4];
+ float t_pixsize; /* pixel size for uv along the stroke */
} PaletteColor;
/* PaletteColor->flag (mainly used by grease pencil) */
diff --git a/source/blender/makesrna/intern/rna_palette.c b/source/blender/makesrna/intern/rna_palette.c
index 2c9d52a51da..f26bb2b39cf 100644
--- a/source/blender/makesrna/intern/rna_palette.c
+++ b/source/blender/makesrna/intern/rna_palette.c
@@ -382,6 +382,13 @@ static void rna_def_palettecolor(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Opacity", "Texture Opacity");
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS | ND_DATA | NC_GPENCIL, "rna_Palette_dependency_update");
+ /* texture pixsize (used for UV along the stroke */
+ prop = RNA_def_property(srna, "pixel_size", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "t_pixsize");
+ RNA_def_property_range(prop, 1, 5000);
+ RNA_def_property_ui_text(prop, "Pixel", "Texture Pixel Size factor along the stroke");
+ RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS | ND_DATA | NC_GPENCIL, "rna_Palette_dependency_update");
+
/* Flags */
prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", PAC_COLOR_HIDE);
More information about the Bf-blender-cvs
mailing list