[Bf-blender-cvs] [63d331b5dea] greasepencil-object: Calc UV factor along the stroke

Antonio Vazquez noreply at git.blender.org
Tue Feb 20 17:02:07 CET 2018


Commit: 63d331b5dea8c8a550440b6ca5008246c4c9224b
Author: Antonio Vazquez
Date:   Sun Feb 18 18:19:40 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB63d331b5dea8c8a550440b6ca5008246c4c9224b

Calc UV factor along the stroke

This data will be used in texture strokes

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
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/makesrna/intern/rna_gpencil.c

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

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 67f6985eceb..25a24ea416b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -805,12 +805,18 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
 					BKE_gpencil_stroke_modifiers(&eval_ctx, ob, gpl, derived_gpf, gps, stl->storage->is_render);
 				}
 			}
+
 			/* fill */
 			if ((fillgrp) && (!GP_SIMPLIFY_FILL(ts, playing))) {
 				gpencil_add_fill_shgroup(cache, fillgrp, ob, gpd, gpl, derived_gpf, gps, tintcolor, false, custonion);
 			}
 			/* stroke */
 			if (strokegrp) {
+				/* be sure UVs are ready */
+				if (gps->flag & GP_STROKE_RECALC_CACHES) {
+					ED_gpencil_calc_stroke_uv(gps, GPENCIL_STROKE_UV);
+					gps->flag &= ~GP_STROKE_RECALC_CACHES;
+				}
 				gpencil_add_stroke_shgroup(cache, strokegrp, ob, gpd, gpl, derived_gpf, gps, opacity, tintcolor, false, custonion);
 			}
 		}
diff --git a/source/blender/draw/engines/gpencil/gpencil_geom.c b/source/blender/draw/engines/gpencil/gpencil_geom.c
index 2501c6ab87a..7dfbee04e31 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -591,6 +591,7 @@ Gwn_Batch *DRW_gpencil_get_fill_geom(bGPDstroke *gps, const float color[4])
 	/* 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, GPENCIL_STROKE_UV);
 	}
 	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 b82342b4c20..4e2b74357ba 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1016,6 +1016,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
 			MEM_freeN(depth_arr);
 	}
 	
+	/* calculate UVs along the stroke */
+	ED_gpencil_calc_stroke_uv(gps, GPENCIL_STROKE_UV);
+
 	/* Save palette color */
 	gps->palette = p->palette;
 	gps->palcolor = p->palettecolor;
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 3999716ca5c..2b72ecf5399 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1526,5 +1526,40 @@ void ED_gpencil_setup_modes(bContext *C, bGPdata *gpd, int newmode)
 	}
 }
 
+/* texture coordinate utilities */
+void ED_gpencil_calc_stroke_uv(bGPDstroke *gps, float factor)
+{
+	if (gps == NULL) {
+		return;
+	}
+	bGPDspoint *pt = NULL;
+	bGPDspoint *ptb = NULL;
+	int i;
+	float totlen = 0;
+
+	/* first read all points and calc distance */
+	for (i = 0; i < gps->totpoints; i++) {
+		pt = &gps->points[i];
+		/* first point */
+		if (i == 0) {
+			pt->uv_fac = 0.0f;
+			pt->uv_rot = 0.0f;
+			continue;
+		}
+
+		ptb = &gps->points[i - 1];
+		totlen += len_v3v3(&pt->x, &ptb->x);
+
+		pt->uv_fac = totlen;
+		pt->uv_rot = 0.0f;
+	}
+
+	/* normalize the distance using a factor */
+	for (i = 0; i < gps->totpoints; i++) {
+		pt = &gps->points[i];
+		pt->uv_fac /= factor;
+	}
+}
+
 /* ******************************************************** */
 
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index ba496ee15de..8c64b42480a 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -75,6 +75,8 @@ typedef struct tGPspoint {
 	float pressure;         /* pressure of tablet at this point */
 	float strength;         /* pressure of tablet at this point for alpha factor */
 	float time;             /* Time relative to stroke start (used when converting to path) */
+	float uv_fac;           /* factor of uv along the stroke */
+	float uv_rot;           /* uv rotation for dor mode */
 } tGPspoint;
 
 /* used to sort by zdepth gpencil objects in viewport */
@@ -209,4 +211,8 @@ void ED_gpencil_vgroup_deselect(struct bContext *C, struct Object *ob);
 /* join objects */
 int ED_gpencil_join_objects_exec(struct bContext *C, struct wmOperator *op);
 
+/* texture coordinate utilities */
+#define GPENCIL_STROKE_UV 1.0f /* TODO: Replace by brush parameter */
+void ED_gpencil_calc_stroke_uv(struct bGPDstroke *gps, float factor);
+
 #endif /*  __ED_GPENCIL_H__ */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 8716e2b5635..2351a6eb27e 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -26,6 +26,8 @@
 
 #include <stdlib.h>
 
+#include "BLI_math.h"
+
 #include "DNA_gpencil_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_brush_types.h"
@@ -830,7 +832,7 @@ static void rna_def_gpencil_stroke_point(BlenderRNA *brna)
 
 	prop = RNA_def_property(srna, "uv_rotation", PROP_FLOAT, PROP_ANGLE);
 	RNA_def_property_float_sdna(prop, NULL, "uv_rot");
-	RNA_def_property_range(prop, 0.0f, DEG2RADF(360.0f));
+	RNA_def_property_range(prop, 0.0f, M_PI * 2);
 	RNA_def_property_ui_text(prop, "UV Rotation", "Internal UV factor for dot mode");
 	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");



More information about the Bf-blender-cvs mailing list