Commit: c810fdd5df4cfa9eaae3e724d0266e74284313e3
Author: Antonio Vazquez
Date:   Thu Apr 13 12:08:50 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBc810fdd5df4cfa9eaae3e724d0266e74284313e3

WIP: Add basic editing points to strokes

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

M       source/blender/draw/engines/gpencil/gpencil_draw.c
M       source/blender/draw/engines/gpencil/gpencil_mode.c
M       source/blender/draw/engines/gpencil/gpencil_mode.h

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw.c 
b/source/blender/draw/engines/gpencil/gpencil_draw.c
index 4d1d4a9eb44..ccd249695f3 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw.c
@@ -41,6 +41,8 @@
 
 #include "ED_gpencil.h"
 
+#include "UI_resources.h"
+
 /* set stroke point to vbo */
 static void gpencil_set_stroke_point(VertexBuffer *vbo, const bGPDspoint *pt, 
int idx,
                                                    unsigned int pos_id, 
unsigned int color_id,
@@ -362,3 +364,81 @@ Batch *gpencil_get_fill_geom(bGPDstroke *gps, const float 
diff_mat[4][4], const
 
        return Batch_create(PRIM_TRIANGLES, vbo, NULL);
 }
+
+/* Draw selected verts for strokes being edited */
+Batch *gpencil_get_edit_geom(bGPDstroke *gps, const float diff_mat[4][4], 
float alpha, short dflag)
+{
+       /* Get size of verts:
+       * - The selected state needs to be larger than the unselected state so 
that
+       *   they stand out more.
+       * - We use the theme setting for size of the unselected verts
+       */
+       float bsize = UI_GetThemeValuef(TH_GP_VERTEX_SIZE);
+       float vsize;
+       if ((int)bsize > 8) {
+               vsize = 10.0f;
+               bsize = 8.0f;
+       }
+       else {
+               vsize = bsize + 2;
+       }
+
+       /* for now, we assume that the base color of the points is not too 
close to the real color */
+       /* set color using palette */
+       PaletteColor *palcolor = gps->palcolor;
+
+       float selectColor[4];
+       UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor);
+       selectColor[3] = alpha;
+
+       static VertexFormat format = { 0 };
+       static unsigned int pos_id, color_id, size_id;
+       if (format.attrib_ct == 0) {
+               pos_id = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, 
KEEP_FLOAT);
+               color_id = VertexFormat_add_attrib(&format, "color", COMP_F32, 
4, KEEP_FLOAT);
+               size_id = VertexFormat_add_attrib(&format, "size", COMP_F32, 1, 
KEEP_FLOAT);
+       }
+
+       VertexBuffer *vbo = VertexBuffer_create_with_format(&format);
+       VertexBuffer_allocate_data(vbo, gps->totpoints);
+
+       /* Draw start and end point differently if enabled stroke direction 
hint */
+       bool show_direction_hint = (dflag & GP_DATA_SHOW_DIRECTION) && 
(gps->totpoints > 1);
+
+       /* Draw all the stroke points (selected or not) */
+       bGPDspoint *pt = gps->points;
+       float fpt[3];
+       int idx = 0;
+       float fcolor[4];
+       float fsize = 0;
+
+       for (int i = 0; i < gps->totpoints; i++, pt++) {
+               if (show_direction_hint && i == 0) {
+                       /* start point in green bigger */
+                       ARRAY_SET_ITEMS(fcolor, 0.0f, 1.0f, 0.0f, 1.0f);
+                       fsize = vsize + 4;
+               }
+               else if (show_direction_hint && (i == gps->totpoints - 1)) {
+                       /* end point in red smaller */
+                       ARRAY_SET_ITEMS(fcolor, 1.0f, 0.0f, 0.0f, 1.0f);
+                       fsize = vsize + 1;
+               }
+               else if (pt->flag & GP_SPOINT_SELECT) {
+                       copy_v4_v4(fcolor, selectColor);
+                       fsize = vsize;
+               }
+               else {
+                       copy_v4_v4(fcolor, palcolor->rgb);
+                       fsize = bsize;
+               }
+
+               VertexBuffer_set_attrib(vbo, color_id, idx, fcolor);
+               VertexBuffer_set_attrib(vbo, size_id, idx, &fsize);
+
+               mul_v3_m4v3(fpt, diff_mat, &pt->x);
+               VertexBuffer_set_attrib(vbo, pos_id, idx, fpt);
+               ++idx;
+       }
+
+       return Batch_create(PRIM_POINTS, vbo, NULL);
+}
diff --git a/source/blender/draw/engines/gpencil/gpencil_mode.c 
b/source/blender/draw/engines/gpencil/gpencil_mode.c
index 4b8d272bd10..9ef1e2ad6ed 100644
--- a/source/blender/draw/engines/gpencil/gpencil_mode.c
+++ b/source/blender/draw/engines/gpencil/gpencil_mode.c
@@ -90,6 +90,7 @@ typedef struct g_data{
        int t_flip;
        int t_mix;
        int fill_style;
+       DRWShadingGroup *shgrps_volumetric;
 } g_data; /* Transient data */
 
 static struct {
@@ -182,6 +183,16 @@ static DRWShadingGroup 
*GPENCIL_shgroup_stroke_create(GPENCIL_Data *vedata, DRWP
        return grp;
 }
 
+/* create shading group for volumetric */
+static DRWShadingGroup *GPENCIL_shgroup_volumetric_create(GPENCIL_Data 
*vedata, DRWPass *pass)
+{
+       GPENCIL_TextureList *txl = ((GPENCIL_Data *)vedata)->txl;
+       GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+
+       DRWShadingGroup *grp = DRW_shgroup_create(e_data.gpencil_volumetric_sh, 
pass);
+
+       return grp;
+}
 
 static void GPENCIL_cache_init(void *vedata)
 {
@@ -207,6 +218,9 @@ static void GPENCIL_cache_init(void *vedata)
                memset(stl->storage->shgrps_fill, 0, sizeof(DRWShadingGroup *) 
* MAX_GPENCIL_MAT);
                memset(stl->storage->shgrps_stroke, 0, sizeof(DRWShadingGroup 
*) * MAX_GPENCIL_MAT);
                memset(stl->storage->materials, 0, sizeof(PaletteColor *) * 
MAX_GPENCIL_MAT);
+
+               /* create static shading groups */
+               stl->g_data->shgrps_volumetric = 
GPENCIL_shgroup_volumetric_create(vedata, psl->pass);
        }
 }
 
@@ -231,6 +245,7 @@ static void GPENCIL_cache_populate(void *vedata, Object *ob)
        DRWShadingGroup *strokegrp;
        const bContext *C = DRW_get_context();
        Scene *scene = CTX_data_scene(C);
+       ToolSettings *ts = CTX_data_tool_settings(C);
        float diff_mat[4][4];
        float ink[4];
        float tcolor[4];
@@ -288,11 +303,29 @@ static void GPENCIL_cache_populate(void *vedata, Object 
*ob)
                                        struct Batch *stroke_geom = 
gpencil_get_stroke_geom(gps, sthickness, diff_mat, ink);
                                        DRW_shgroup_call_add(strokegrp, 
stroke_geom, ob->obmat);
                                }
+
+                               /* edit points (only in edit mode) */
+                               if ((gpl->flag & GP_LAYER_LOCKED) == 0 && 
(ob->gpd->flag & GP_DATA_STROKE_EDITMODE))
+                               {
+                                       if (gps->flag & GP_STROKE_SELECT) {
+                                               if ((gpl->flag & 
GP_LAYER_UNLOCK_COLOR) || ((gps->palcolor->flag & PC_COLOR_LOCKED) == 0)) {
+                                                       struct Batch *edit_geom 
= gpencil_get_edit_geom(gps, diff_mat, ts->gp_sculpt.alpha, ob->gpd->flag);
+                                                       
DRW_shgroup_call_add(stl->g_data->shgrps_volumetric, edit_geom,ob->obmat);
+
+                                               }
+                                       }
+                               }
+
                        }
                }
        }
 }
 
+static void GPENCIL_cache_finish(void *vedata)
+{
+       GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+}
+
 static void GPENCIL_draw_scene(void *vedata)
 {
        GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
@@ -318,7 +351,7 @@ DrawEngineType draw_engine_gpencil_type = {
        &GPENCIL_engine_free,
        &GPENCIL_cache_init,
        &GPENCIL_cache_populate,
-       NULL,
+       &GPENCIL_cache_finish,
        NULL,
        &GPENCIL_draw_scene
 };
diff --git a/source/blender/draw/engines/gpencil/gpencil_mode.h 
b/source/blender/draw/engines/gpencil/gpencil_mode.h
index 07bb82b3991..c3dc70923a3 100644
--- a/source/blender/draw/engines/gpencil/gpencil_mode.h
+++ b/source/blender/draw/engines/gpencil/gpencil_mode.h
@@ -30,6 +30,8 @@ struct Batch;
 
 struct Batch *gpencil_get_stroke_geom(struct bGPDstroke *gps, short thickness, 
const float diff_mat[4][4], const float ink[4]);
 struct Batch *gpencil_get_fill_geom(struct bGPDstroke *gps, const float 
diff_mat[4][4], const float color[4]);
+struct Batch *gpencil_get_edit_geom(struct bGPDstroke *gps, const float 
diff_mat[4][4], float alpha, short dflag);
+
 bool gpencil_can_draw_stroke(const struct bGPDstroke *gps);
 
 #endif /* __GPENCIL_MODE_H__ */
\ No newline at end of file

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to