GP: New automatic adaptative UVs parameter

Now by default the UVs are calculated with a fixed size and this makes easier to add patterns for drawings like Manga. Before, the texture changed depending of the stroke size.
This commit is contained in:
Antonioya 2018-10-08 18:33:26 +02:00
parent e5c7c21630
commit b8a0434bc5
6 changed files with 29 additions and 14 deletions

@ -345,6 +345,7 @@ class DATA_PT_gpencil_display(DataButtonsPanel, Panel):
layout.prop(gpd, "show_stroke_direction", text="Show Stroke Directions") layout.prop(gpd, "show_stroke_direction", text="Show Stroke Directions")
layout.prop(gpd, "use_force_fill_recalc", text="Force Fill Update") layout.prop(gpd, "use_force_fill_recalc", text="Force Fill Update")
layout.prop(gpd, "use_adaptative_uv", text="Adaptative UVs")
layout.prop(gpd, "zdepth_offset", text="Surface Offset") layout.prop(gpd, "zdepth_offset", text="Surface Offset")

@ -414,7 +414,7 @@ GPUBatch *DRW_gpencil_get_fill_geom(Object *ob, bGPDstroke *gps, const float col
/* Calculate triangles cache for filling area (must be done only after changes) */ /* 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)) { if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) {
DRW_gpencil_triangulate_stroke_fill(gps); DRW_gpencil_triangulate_stroke_fill(ob, gps);
ED_gpencil_calc_stroke_uv(ob, gps); ED_gpencil_calc_stroke_uv(ob, gps);
} }

@ -92,7 +92,7 @@ static bool gpencil_can_draw_stroke(
/* calc bounding box in 2d using flat projection data */ /* calc bounding box in 2d using flat projection data */
static void gpencil_calc_2d_bounding_box( static void gpencil_calc_2d_bounding_box(
const float(*points2d)[2], int totpoints, float minv[2], float maxv[2], bool expand) const float(*points2d)[2], int totpoints, float minv[2], float maxv[2])
{ {
minv[0] = points2d[0][0]; minv[0] = points2d[0][0];
minv[1] = points2d[0][1]; minv[1] = points2d[0][1];
@ -115,8 +115,7 @@ static void gpencil_calc_2d_bounding_box(
maxv[1] = points2d[i][1]; maxv[1] = points2d[i][1];
} }
} }
/* If not expanded, use a perfect square */ /* use a perfect square */
if (expand == false) {
if (maxv[0] > maxv[1]) { if (maxv[0] > maxv[1]) {
maxv[1] = maxv[0]; maxv[1] = maxv[0];
} }
@ -124,7 +123,6 @@ static void gpencil_calc_2d_bounding_box(
maxv[0] = maxv[1]; maxv[0] = maxv[1];
} }
} }
}
/* calc texture coordinates using flat projected points */ /* calc texture coordinates using flat projected points */
static void gpencil_calc_stroke_fill_uv( static void gpencil_calc_stroke_fill_uv(
@ -184,10 +182,12 @@ static void gpencil_stroke_2d_flat(const bGPDspoint *points, int totpoints, floa
} }
/* Triangulate stroke for high quality fill (this is done only if cache is null or stroke was modified) */ /* Triangulate stroke for high quality fill (this is done only if cache is null or stroke was modified) */
void DRW_gpencil_triangulate_stroke_fill(bGPDstroke *gps) void DRW_gpencil_triangulate_stroke_fill(Object *ob, bGPDstroke *gps)
{ {
BLI_assert(gps->totpoints >= 3); BLI_assert(gps->totpoints >= 3);
bGPdata *gpd = (bGPdata *)ob->data;
/* allocate memory for temporary areas */ /* allocate memory for temporary areas */
gps->tot_triangles = gps->totpoints - 2; gps->tot_triangles = gps->totpoints - 2;
uint(*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->tot_triangles, "GP Stroke temp triangulation"); uint(*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->tot_triangles, "GP Stroke temp triangulation");
@ -204,7 +204,14 @@ void DRW_gpencil_triangulate_stroke_fill(bGPDstroke *gps)
float minv[2]; float minv[2];
float maxv[2]; float maxv[2];
/* first needs bounding box data */ /* first needs bounding box data */
gpencil_calc_2d_bounding_box(points2d, gps->totpoints, minv, maxv, false); if (gpd->flag & GP_DATA_UV_ADAPTATIVE) {
gpencil_calc_2d_bounding_box(points2d, gps->totpoints, minv, maxv);
}
else {
ARRAY_SET_ITEMS(minv, -1.0f, -1.0f);
ARRAY_SET_ITEMS(maxv, 1.0f, 1.0f);
}
/* calc uv data */ /* calc uv data */
gpencil_calc_stroke_fill_uv(points2d, gps->totpoints, minv, maxv, uv); gpencil_calc_stroke_fill_uv(points2d, gps->totpoints, minv, maxv, uv);
@ -256,7 +263,7 @@ static void DRW_gpencil_recalc_geometry_caches(Object *ob, MaterialGPencilStyle
if ((gps->totpoints > 2) && if ((gps->totpoints > 2) &&
((gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gp_style->fill_style > 0))) ((gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (gp_style->fill_style > 0)))
{ {
DRW_gpencil_triangulate_stroke_fill(gps); DRW_gpencil_triangulate_stroke_fill(ob, gps);
} }
} }

@ -303,7 +303,7 @@ void DRW_gpencil_populate_buffer_strokes(
void DRW_gpencil_populate_multiedit( void DRW_gpencil_populate_multiedit(
struct GPENCIL_e_data *e_data, void *vedata, struct GPENCIL_e_data *e_data, void *vedata,
struct Scene *scene, struct Object *ob, struct tGPencilObjectCache *cache_ob); struct Scene *scene, struct Object *ob, struct tGPencilObjectCache *cache_ob);
void DRW_gpencil_triangulate_stroke_fill(struct bGPDstroke *gps); void DRW_gpencil_triangulate_stroke_fill(struct Object *ob, struct bGPDstroke *gps);
void DRW_gpencil_multisample_ensure(struct GPENCIL_Data *vedata, int rect_w, int rect_h); void DRW_gpencil_multisample_ensure(struct GPENCIL_Data *vedata, int rect_w, int rect_h);

@ -442,6 +442,8 @@ typedef enum eGPdata_Flag {
GP_DATA_STROKE_FORCE_RECALC = (1 << 17), GP_DATA_STROKE_FORCE_RECALC = (1 << 17),
/* Special mode drawing polygons */ /* Special mode drawing polygons */
GP_DATA_STROKE_POLYGON = (1 << 18), GP_DATA_STROKE_POLYGON = (1 << 18),
/* Use adaptative UV scales */
GP_DATA_UV_ADAPTATIVE = (1 << 19),
} eGPdata_Flag; } eGPdata_Flag;
/* gpd->onion_flag */ /* gpd->onion_flag */

@ -1383,6 +1383,11 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Force Fill Update", "Force recalc of fill data after use deformation modifiers (reduce FPS)"); RNA_def_property_ui_text(prop, "Force Fill Update", "Force recalc of fill data after use deformation modifiers (reduce FPS)");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update"); RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
prop = RNA_def_property(srna, "use_adaptative_uv", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_DATA_UV_ADAPTATIVE);
RNA_def_property_ui_text(prop, "Adaptative UV", "Automatic UVs are calculated depending of the stroke size");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
prop = RNA_def_property(srna, "edit_line_color", PROP_FLOAT, PROP_COLOR_GAMMA); prop = RNA_def_property(srna, "edit_line_color", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "line_color"); RNA_def_property_float_sdna(prop, NULL, "line_color");
RNA_def_property_array(prop, 4); RNA_def_property_array(prop, 4);