Fix T64441: GPencil textures weird rotation
New option to disable the follow drawing path. Before it had only a switch property, now there is a list of options. Modes: Path: Follows drawing stroke and rotate with object. Object: Only follows object rotation. None: Don't rotate.
This commit is contained in:
parent
21bfc469ab
commit
254b1a4294
Notes:
blender-bot
2023-02-14 04:20:36 +01:00
Referenced by issue #64441, Gpencil Texture Rotation issue when object is rotated.
|
@ -134,7 +134,7 @@ void DRW_gpencil_get_point_geom(GpencilBatchCacheElem *be,
|
|||
bGPDstroke *gps,
|
||||
short thickness,
|
||||
const float ink[4],
|
||||
const bool follow)
|
||||
const int follow_mode)
|
||||
{
|
||||
int totvertex = gps->totpoints;
|
||||
if (be->vbo == NULL) {
|
||||
|
@ -178,7 +178,7 @@ void DRW_gpencil_get_point_geom(GpencilBatchCacheElem *be,
|
|||
/* use previous point to determine stroke direction */
|
||||
bGPDspoint *pt2 = NULL;
|
||||
float fpt[3];
|
||||
if (!follow) {
|
||||
if (follow_mode != GP_STYLE_FOLLOW_PATH) {
|
||||
/* add small offset to get a vector */
|
||||
copy_v3_v3(fpt, &pt->x);
|
||||
fpt[0] += 0.00001f;
|
||||
|
|
|
@ -725,8 +725,8 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(GPENCIL_e_data *e_data,
|
|||
DRW_shgroup_uniform_float(grp, "mix_stroke_factor", &stl->shgroups[id].mix_stroke_factor, 1);
|
||||
|
||||
/* lock rotation of dots and boxes */
|
||||
stl->shgroups[id].use_follow_path = (gp_style->flag & GP_STYLE_COLOR_LOCK_DOTS) ? 0 : 1;
|
||||
DRW_shgroup_uniform_int(grp, "use_follow_path", &stl->shgroups[id].use_follow_path, 1);
|
||||
stl->shgroups[id].follow_mode = gp_style->follow_mode;
|
||||
DRW_shgroup_uniform_int(grp, "follow_mode", &stl->shgroups[id].follow_mode, 1);
|
||||
}
|
||||
else {
|
||||
stl->storage->obj_scale = 1.0f;
|
||||
|
@ -758,7 +758,7 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(GPENCIL_e_data *e_data,
|
|||
DRW_shgroup_uniform_float(grp, "mix_stroke_factor", &stl->storage->mix_stroke_factor, 1);
|
||||
|
||||
/* lock rotation of dots and boxes */
|
||||
DRW_shgroup_uniform_int(grp, "use_follow_path", &stl->storage->use_follow_path, 1);
|
||||
DRW_shgroup_uniform_int(grp, "follow_mode", &stl->storage->follow_mode, 1);
|
||||
}
|
||||
|
||||
DRW_shgroup_uniform_vec4(grp, "colormix", gp_style->stroke_rgba, 1);
|
||||
|
@ -870,7 +870,7 @@ static void gpencil_add_stroke_vertexdata(GpencilBatchCache *cache,
|
|||
float ink[4];
|
||||
short sthickness;
|
||||
MaterialGPencilStyle *gp_style = BKE_material_gpencil_settings_get(ob, gps->mat_nr + 1);
|
||||
const bool follow = ((gp_style) && (gp_style->flag & GP_STYLE_COLOR_LOCK_DOTS)) ? 0 : 1;
|
||||
const int follow_mode = (gp_style) ? gp_style->follow_mode : GP_STYLE_FOLLOW_PATH;
|
||||
|
||||
/* set color using base color, tint color and opacity */
|
||||
if (cache->is_dirty) {
|
||||
|
@ -920,7 +920,7 @@ static void gpencil_add_stroke_vertexdata(GpencilBatchCache *cache,
|
|||
else {
|
||||
/* create vertex data */
|
||||
const int old_len = cache->b_point.vbo_len;
|
||||
DRW_gpencil_get_point_geom(&cache->b_point, gps, sthickness, ink, follow);
|
||||
DRW_gpencil_get_point_geom(&cache->b_point, gps, sthickness, ink, follow_mode);
|
||||
|
||||
/* add to list of groups */
|
||||
if (old_len < cache->b_point.vbo_len) {
|
||||
|
@ -1491,7 +1491,7 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data,
|
|||
/* save gradient info */
|
||||
stl->storage->gradient_f = brush->gpencil_settings->gradient_f;
|
||||
copy_v2_v2(stl->storage->gradient_s, brush->gpencil_settings->gradient_s);
|
||||
stl->storage->use_follow_path = (gp_style->flag & GP_STYLE_COLOR_LOCK_DOTS) ? 0 : 1;
|
||||
stl->storage->follow_mode = (gp_style) ? gp_style->follow_mode : GP_STYLE_FOLLOW_PATH;
|
||||
|
||||
/* if only one point, don't need to draw buffer because the user has no time to see it */
|
||||
if (gpd->runtime.sbuffer_size > 1) {
|
||||
|
|
|
@ -129,7 +129,7 @@ typedef struct GPENCIL_shgroup {
|
|||
int caps_mode[2];
|
||||
float obj_scale;
|
||||
int xray_mode;
|
||||
int use_follow_path;
|
||||
int follow_mode;
|
||||
|
||||
float gradient_f;
|
||||
float gradient_s[2];
|
||||
|
@ -182,7 +182,7 @@ typedef struct GPENCIL_Storage {
|
|||
|
||||
float gradient_f;
|
||||
float gradient_s[2];
|
||||
int use_follow_path;
|
||||
int follow_mode;
|
||||
|
||||
float mix_stroke_factor;
|
||||
|
||||
|
@ -438,7 +438,7 @@ void DRW_gpencil_get_point_geom(struct GpencilBatchCacheElem *be,
|
|||
struct bGPDstroke *gps,
|
||||
short thickness,
|
||||
const float ink[4],
|
||||
const bool follow);
|
||||
const int follow_mode);
|
||||
void DRW_gpencil_get_stroke_geom(struct GpencilBatchCacheElem *be,
|
||||
struct bGPDstroke *gps,
|
||||
short thickness,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
uniform vec2 Viewport;
|
||||
uniform int xraymode;
|
||||
uniform int use_follow_path;
|
||||
uniform int follow_mode;
|
||||
|
||||
layout(points) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
|
@ -20,6 +20,9 @@ out vec2 mTexCoord;
|
|||
#define M_2PI 6.28318530717958647692 /* 2*pi */
|
||||
#define FALSE 0
|
||||
|
||||
/* keep this definition equals to GP_STYLE_FOLLOW_NONE value */
|
||||
#define NONE 2
|
||||
|
||||
/* project 3d point to 2d on screen space */
|
||||
vec2 toScreenSpace(vec4 vertex)
|
||||
{
|
||||
|
@ -69,11 +72,9 @@ float getAngle(vec2 pt0, vec2 pt1)
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
/* disable, but keep for future follow modes
|
||||
if (use_follow_path == FALSE) {
|
||||
if (follow_mode == NONE) {
|
||||
return 0.0;
|
||||
}
|
||||
*/
|
||||
|
||||
/* default horizontal line (x-axis) in screen space */
|
||||
vec2 v0 = vec2(1.0, 0.0);
|
||||
|
|
|
@ -99,6 +99,9 @@ typedef struct MaterialGPencilStyle {
|
|||
|
||||
/** Factor used to mix texture and stroke color. */
|
||||
float mix_stroke_factor;
|
||||
/** Mode used to follow stroke drawing path by textures */
|
||||
int follow_mode;
|
||||
char _pad[4];
|
||||
} MaterialGPencilStyle;
|
||||
|
||||
/* MaterialGPencilStyle->flag */
|
||||
|
@ -123,8 +126,6 @@ typedef enum eMaterialGPencilStyle_Flag {
|
|||
GP_STYLE_STROKE_SHOW = (1 << 8),
|
||||
/* Fill show main switch */
|
||||
GP_STYLE_FILL_SHOW = (1 << 9),
|
||||
/* Don't rotate dots/boxes */
|
||||
GP_STYLE_COLOR_LOCK_DOTS = (1 << 10),
|
||||
/* mix stroke texture */
|
||||
GP_STYLE_STROKE_TEX_MIX = (1 << 11),
|
||||
} eMaterialGPencilStyle_Flag;
|
||||
|
@ -347,4 +348,10 @@ enum {
|
|||
GP_STYLE_GRADIENT_RADIAL,
|
||||
};
|
||||
|
||||
/* Grease Pencil Follow Drawing Modes */
|
||||
enum {
|
||||
GP_STYLE_FOLLOW_PATH = 0,
|
||||
GP_STYLE_FOLLOW_OBJ,
|
||||
GP_STYLE_FOLLOW_NONE,
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -440,6 +440,13 @@ static void rna_def_material_greasepencil(BlenderRNA *brna)
|
|||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
static EnumPropertyItem follow_draw_items[] = {
|
||||
{GP_STYLE_FOLLOW_PATH, "PATH", 0, "Path", "Follow stroke drawing path and object rotation"},
|
||||
{GP_STYLE_FOLLOW_OBJ, "OBJECT", 0, "Object", "Follow object rotation only"},
|
||||
{GP_STYLE_FOLLOW_NONE, "NONE", 0, "None", "Do not follow drawing path or object rotation"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
};
|
||||
|
||||
srna = RNA_def_struct(brna, "MaterialGPencilStyle", NULL);
|
||||
RNA_def_struct_sdna(srna, "MaterialGPencilStyle");
|
||||
RNA_def_struct_ui_text(srna, "Grease Pencil Color", "");
|
||||
|
@ -611,10 +618,12 @@ static void rna_def_material_greasepencil(BlenderRNA *brna)
|
|||
RNA_def_property_ui_text(prop, "Show Fill", "Show stroke fills of this material");
|
||||
RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_MaterialGpencil_update");
|
||||
|
||||
/* keep Dots and Boxes aligned to screen and not to drawing path */
|
||||
prop = RNA_def_property(srna, "use_follow_path", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GP_STYLE_COLOR_LOCK_DOTS);
|
||||
RNA_def_property_ui_text(prop, "Follow Path", "Keep Dots and Boxes aligned to drawing path");
|
||||
/* Mode to align Dots and Boxes to drawing path and object rotation */
|
||||
prop = RNA_def_property(srna, "use_follow_path", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_bitflag_sdna(prop, NULL, "follow_mode");
|
||||
RNA_def_property_enum_items(prop, follow_draw_items);
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Follow Path", "Rotate Dots and Boxes aligned to drawing path and object rotation");
|
||||
RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_MaterialGpencil_nopreview_update");
|
||||
|
||||
/* pass index for future compositing and editing tools */
|
||||
|
|
Loading…
Reference in New Issue