diff options
author | Antonioya <blendergit@gmail.com> | 2019-01-11 21:15:23 +0300 |
---|---|---|
committer | Antonioya <blendergit@gmail.com> | 2019-01-11 21:21:56 +0300 |
commit | bb9c9d0eaaab836b8f20ab7b2228795f607b823a (patch) | |
tree | 8fd6ebad4084c66e6d1a49849ed6b9dbbc126d22 /source/blender/draw/engines/gpencil | |
parent | 6dbfd7f6d6bc9bea9556861eba682a3126b5ed40 (diff) |
GP: New Cutter, Constraints and Segment selection
This commit groups a set of new tools that were tested in grease pencil object branch before moving to master. We decide to do all the development in a separated branch because it could break master during days or weeks before the new tools were ready to deploy.
The commit includes:
- New Cutter tool to trim strokes and help cleaning up drawings.
- New set of constraints and guides to draw different types of shapes. All the credits for this development goes to Charlie Jolly (@charlie), thanks for your help!
- Segment selection mode to select strokes between intersections.
- New operator to change strokes cap mode.
- New option to display only keyframed frames. This option is very important when fill strokes with color.
- Multiple small fixes and tweaks.
Thanks to @pepeland and @mendio for their ideas, tests, reviews and support.
Note: Still pending the final icons for Cutter in Toolbar and Segment Selection in Topbar. @billreynish could help us here?
Diffstat (limited to 'source/blender/draw/engines/gpencil')
4 files changed, 69 insertions, 14 deletions
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 beb9f3ee847..b7207b6af65 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c +++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c @@ -390,6 +390,14 @@ GPUBatch *DRW_gpencil_get_buffer_ctrlpoint_geom(bGPdata *gpd) bGPDcontrolpoint *cps = gpd->runtime.cp_points; int totpoints = gpd->runtime.tot_cp_points; + const DRWContextState *draw_ctx = DRW_context_state_get(); + Scene *scene = draw_ctx->scene; + ToolSettings *ts = scene->toolsettings; + + if (ts->gp_sculpt.guide.use_guide) { + totpoints++; + } + static GPUVertFormat format = { 0 }; static uint pos_id, color_id, size_id; if (format.attr_len == 0) { @@ -415,6 +423,27 @@ GPUBatch *DRW_gpencil_get_buffer_ctrlpoint_geom(bGPdata *gpd) idx++; } + if (ts->gp_sculpt.guide.use_guide) { + float size = 10 * 0.8f; + float color[4]; + float position[3]; + if (ts->gp_sculpt.guide.reference_point == GP_GUIDE_REF_CUSTOM) { + UI_GetThemeColor4fv(TH_GIZMO_PRIMARY, color); + copy_v3_v3(position, ts->gp_sculpt.guide.location); + } + else if (ts->gp_sculpt.guide.reference_point == GP_GUIDE_REF_OBJECT && ts->gp_sculpt.guide.reference_object != NULL) { + UI_GetThemeColor4fv(TH_GIZMO_SECONDARY, color); + copy_v3_v3(position, ts->gp_sculpt.guide.reference_object->loc); + } + else { + UI_GetThemeColor4fv(TH_REDALERT, color); + copy_v3_v3(position, scene->cursor.location); + } + GPU_vertbuf_attr_set(vbo, pos_id, idx, position); + GPU_vertbuf_attr_set(vbo, size_id, idx, &size); + GPU_vertbuf_attr_set(vbo, color_id, idx, color); + } + return GPU_batch_create_ex(GPU_PRIM_POINTS, vbo, NULL, GPU_BATCH_OWNS_VBO); } diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c index 2e9a212170c..f925f9fb506 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c +++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c @@ -357,7 +357,7 @@ bool DRW_gpencil_onion_active(bGPdata *gpd) /* create shading group for strokes */ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create( GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob, - bGPdata *gpd, MaterialGPencilStyle *gp_style, int id, bool onion) + bGPdata *gpd, bGPDstroke *gps, MaterialGPencilStyle *gp_style, int id, bool onion) { GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl; const float *viewport_size = DRW_viewport_size_get(); @@ -391,6 +391,10 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create( } DRW_shgroup_uniform_int(grp, "color_type", &stl->shgroups[id].color_type, 1); DRW_shgroup_uniform_float(grp, "pixfactor", &gpd->pixfactor, 1); + + stl->shgroups[id].caps_mode[0] = gps->caps[0]; + stl->shgroups[id].caps_mode[1] = gps->caps[1]; + DRW_shgroup_uniform_int(grp, "caps_mode", &stl->shgroups[id].caps_mode[0], 2); } else { stl->storage->obj_scale = 1.0f; @@ -405,6 +409,8 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create( else { DRW_shgroup_uniform_float(grp, "pixfactor", &stl->storage->pixfactor, 1); } + const int zero[2] = { 0, 0 }; + DRW_shgroup_uniform_int(grp, "caps_mode", &zero[0], 2); } if ((gpd) && (id > -1)) { @@ -1177,7 +1183,8 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, void *vedata, T if (gpd->runtime.sbuffer_size > 1) { if ((gp_style) && (gp_style->mode == GP_STYLE_MODE_LINE)) { stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create( - e_data, vedata, psl->drawing_pass, e_data->gpencil_stroke_sh, NULL, gpd, gp_style, -1, false); + e_data, vedata, psl->drawing_pass, e_data->gpencil_stroke_sh, NULL, + gpd, NULL, gp_style, -1, false); } else { stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_point_create( @@ -1240,13 +1247,14 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, void *vedata, T } } - /* control points */ - if ((overlay) && (gpd->runtime.tot_cp_points > 0) && - ((gpd->runtime.sbuffer_sflag & GP_STROKE_ERASER) == 0) && - ((v3d->gizmo_flag & V3D_GIZMO_HIDE) == 0) && - ((v3d->gizmo_flag & V3D_GIZMO_HIDE_TOOL) == 0)) - { + /* control points for primitives and speed guide */ + const bool is_cppoint = (gpd->runtime.tot_cp_points > 0); + const bool is_speed_guide = (ts->gp_sculpt.guide.use_guide && (draw_ctx->object_mode == OB_MODE_PAINT_GPENCIL)); + const bool is_show_gizmo = (((v3d->gizmo_flag & V3D_GIZMO_HIDE) == 0) && ((v3d->gizmo_flag & V3D_GIZMO_HIDE_TOOL) == 0)); + if ((overlay) && (is_cppoint || is_speed_guide) && (is_show_gizmo) && + ((gpd->runtime.sbuffer_sflag & GP_STROKE_ERASER) == 0)) + { DRWShadingGroup *shgrp = DRW_shgroup_create( e_data->gpencil_edit_point_sh, psl->drawing_pass); const float *viewport_size = DRW_viewport_size_get(); @@ -1357,7 +1365,7 @@ static void DRW_gpencil_shgroups_create( shgrp = DRW_gpencil_shgroup_stroke_create( e_data, vedata, psl->stroke_pass, e_data->gpencil_stroke_sh, - ob, gpd, gp_style, stl->storage->shgroup_id, elm->onion); + ob, gpd, gps, gp_style, stl->storage->shgroup_id, elm->onion); DRW_shgroup_call_range_add( shgrp, cache->b_stroke.batch, @@ -1472,7 +1480,7 @@ void DRW_gpencil_populate_multiedit( ToolSettings *ts = scene->toolsettings; /* check if playing animation */ - bool playing = stl->storage->is_playing; + const bool playing = stl->storage->is_playing; /* calc max size of VBOs */ gpencil_calc_vertex(stl, cache_ob, cache, gpd, cfra_eval); @@ -1541,7 +1549,7 @@ void DRW_gpencil_populate_datablock( bGPDlayer *gpl_active = BKE_gpencil_layer_getactive(gpd); /* check if playing animation */ - bool playing = stl->storage->is_playing; + const bool playing = stl->storage->is_playing; GpencilBatchCache *cache = gpencil_batch_cache_get(ob, cfra_eval); @@ -1567,6 +1575,10 @@ void DRW_gpencil_populate_datablock( continue; } + const bool is_solomode = GPENCIL_PAINT_MODE(gpd) && + (!playing) && (!stl->storage->is_render) && + (gpl->flag & GP_LAYER_SOLO_MODE); + /* filter view layer to gp layers in the same view layer (for compo) */ if ((stl->storage->is_render) && (gpl->viewlayername[0] != '\0')) { if (!STREQ(view_layer->name, gpl->viewlayername)) { @@ -1586,6 +1598,11 @@ void DRW_gpencil_populate_datablock( if (gpf == NULL) continue; + /* if solo mode, display only frames with keyframe in the current frame */ + if ((is_solomode) && (gpf->framenum != remap_cfra)) { + continue; + } + opacity = gpl->opacity; /* if pose mode, maybe the overlay to fade geometry is enabled */ if ((draw_ctx->obact) && (draw_ctx->object_mode == OB_MODE_POSE) && diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h index 6f2b40136ca..c560321df9f 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.h +++ b/source/blender/draw/engines/gpencil/gpencil_engine.h @@ -114,6 +114,7 @@ typedef struct GPENCIL_shgroup { int texture_clamp; int fill_style; int keep_size; + int caps_mode[2]; float obj_scale; } GPENCIL_shgroup; @@ -364,7 +365,8 @@ typedef struct GpencilBatchCache { /* general drawing functions */ struct DRWShadingGroup *DRW_gpencil_shgroup_stroke_create( struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct DRWPass *pass, struct GPUShader *shader, - struct Object *ob, struct bGPdata *gpd, struct MaterialGPencilStyle *gp_style, int id, bool onion); + struct Object *ob, struct bGPdata *gpd, struct bGPDstroke *gps, + struct MaterialGPencilStyle *gp_style, int id, bool onion); void DRW_gpencil_populate_datablock( struct GPENCIL_e_data *e_data, void *vedata, struct Object *ob, struct tGPencilObjectCache *cache_ob); diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl index c2a5f6b0b84..ad85046487b 100644 --- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl +++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_geom.glsl @@ -2,6 +2,7 @@ uniform mat4 ModelViewProjectionMatrix; uniform vec2 Viewport; uniform int xraymode; uniform int color_type; +uniform int caps_mode[2]; layout(lines_adjacency) in; layout(triangle_strip, max_vertices = 13) out; @@ -23,6 +24,8 @@ out vec2 uvfac; #define GPENCIL_COLOR_TEXTURE 1 #define GPENCIL_COLOR_PATTERN 2 +#define GPENCIL_FLATCAP 1 + /* project 3d point to 2d on screen space */ vec2 toScreenSpace(vec4 vertex) { @@ -159,7 +162,9 @@ void main(void) } /* generate the start endcap */ - if (is_equal(P0,P2) && (color_type == GPENCIL_COLOR_SOLID)){ + if ((caps_mode[0] != GPENCIL_FLATCAP) && is_equal(P0,P2) && + (color_type == GPENCIL_COLOR_SOLID)) + { vec4 cap_color = finalColor[1]; mTexCoord = vec2(2.0, 1.0); @@ -205,7 +210,9 @@ void main(void) EmitVertex(); /* generate the end endcap */ - if (is_equal(P1,P3) && (color_type == GPENCIL_COLOR_SOLID) && (finaluvdata[2].x > 0)){ + if ((caps_mode[1] != GPENCIL_FLATCAP) && is_equal(P1,P3) && + (color_type == GPENCIL_COLOR_SOLID) && (finaluvdata[2].x > 0)) + { vec4 cap_color = finalColor[2]; mTexCoord = vec2(finaluvdata[2].x, 2.0); |