[Bf-blender-cvs] [2bcc5f8bdef] greasepencil-object: Draw real stroke while using a primitive
Antonioya
noreply at git.blender.org
Thu Dec 6 13:14:08 CET 2018
Commit: 2bcc5f8bdef7e811a53cf100adaf8dde695c055d
Author: Antonioya
Date: Thu Dec 6 13:13:47 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB2bcc5f8bdef7e811a53cf100adaf8dde695c055d
Draw real stroke while using a primitive
===================================================================
M source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_primitive.c
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index eaae8033b8b..9fe45bbaec0 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -1173,7 +1173,7 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, void *vedata, T
/* Check if may need to draw the active stroke cache, only if this layer is the active layer
* that is being edited. (Stroke buffer is currently stored in gp-data)
*/
- if (ED_gpencil_session_active() && (gpd->runtime.sbuffer_size > 0)) {
+ if (gpd->runtime.sbuffer_size > 0) {
if ((gpd->runtime.sbuffer_sflag & GP_STROKE_ERASER) == 0) {
/* It should also be noted that sbuffer contains temporary point types
* i.e. tGPspoints NOT bGPDspoints
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 6d05afa0e8d..6b269b865cd 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -138,6 +138,7 @@ typedef struct tGPDinterpolate {
/* Temporary primitive operation data */
typedef struct tGPDprimitive {
+ struct Main *bmain; /* main database pointer */
struct Depsgraph *depsgraph;
struct wmWindow *win; /* window where painting originated */
struct Scene *scene; /* current scene from context */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index a2239e0191e..72f4d5bed34 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -113,6 +113,55 @@ static void gp_session_validatebuffer(tGPDprimitive *p)
gpd->runtime.sbuffer_sflag |= GP_STROKE_3DSPACE;
}
+static void gp_init_colors(tGPDprimitive *p)
+{
+ bGPdata *gpd = p->gpd;
+ Brush *brush = p->brush;
+
+ Material *ma = NULL;
+ MaterialGPencilStyle *gp_style = NULL;
+
+ /* use brush material */
+ ma = BKE_gpencil_get_material_from_brush(brush);
+
+ /* if no brush defaults, get material and color info
+ * NOTE: Ensures that everything we need will exist...
+ */
+ if ((ma == NULL) || (ma->gp_style == NULL)) {
+ BKE_gpencil_material_ensure(p->bmain, p->ob);
+
+ /* assign always the first material to the brush */
+ p->mat = give_current_material(p->ob, 1);
+ brush->gpencil_settings->material = p->mat;
+ }
+ else {
+ p->mat = ma;
+ }
+
+ /* check if the material is already on object material slots and add it if missing */
+ if (BKE_gpencil_get_material_index(p->ob, p->mat) == 0) {
+ BKE_object_material_slot_add(p->bmain, p->ob);
+ assign_material(p->bmain, p->ob, ma, p->ob->totcol, BKE_MAT_ASSIGN_USERPREF);
+ }
+
+ /* assign color information to temp data */
+ gp_style = p->mat->gp_style;
+ if (gp_style) {
+
+ /* set colors */
+ copy_v4_v4(gpd->runtime.scolor, gp_style->stroke_rgba);
+ copy_v4_v4(gpd->runtime.sfill, gp_style->fill_rgba);
+ /* add some alpha to make easy the filling without hide strokes */
+ if (gpd->runtime.sfill[3] > 0.8f) {
+ gpd->runtime.sfill[3] = 0.8f;
+ }
+
+ gpd->runtime.mode = (short)gp_style->mode;
+ gpd->runtime.bstroke_style = gp_style->stroke_style;
+ gpd->runtime.bfill_style = gp_style->fill_style;
+ }
+}
+
/* Poll callback for primitive operators */
static bool gpencil_primitive_add_poll(bContext *C)
{
@@ -404,7 +453,7 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
/* convert screen-coordinates to 3D coordinates */
gp_session_validatebuffer(tgpi);
-
+ gp_init_colors(tgpi);
for (int i = 0; i < gps->totpoints; i++) {
bGPDspoint *pt = &gps->points[i];
@@ -414,8 +463,8 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
tGPspoint *tpt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size);
tpt->x = p2d->x;
tpt->y = p2d->y;
- tpt->pressure = p2d->pressure;
- tpt->strength = p2d->strength;
+ tpt->pressure = 1.0f;
+ tpt->strength = 1.0f;
tpt->time = p2d->time;
tpt->uv_fac = p2d->uv_fac;
tpt->uv_rot = p2d->uv_rot;
@@ -547,6 +596,7 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
op->customdata = tgpi;
/* set current scene and window info */
+ tgpi->bmain = CTX_data_main(C);
tgpi->scene = scene;
tgpi->ob = CTX_data_active_object(C);
tgpi->sa = CTX_wm_area(C);
More information about the Bf-blender-cvs
mailing list