diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2020-03-09 18:27:24 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2020-03-09 18:27:24 +0300 |
commit | 29f3af95272590d26f610ae828b2eeee89c82a00 (patch) | |
tree | a696a58a2561c48f7ec6166e369e22081e0a64d8 /source/blender/editors/gpencil/gpencil_convert.c | |
parent | dcb93126876879d969a30a7865700abd072066f8 (diff) |
GPencil: Refactor of Draw Engine, Vertex Paint and all internal functions
This commit is a full refactor of the grease pencil modules including Draw Engine, Modifiers, VFX, depsgraph update, improvements in operators and conversion of Sculpt and Weight paint tools to real brushes.
Also, a huge code cleanup has been done at all levels.
Thanks to @fclem for his work and yo @pepeland and @mendio for the testing and help in the development.
Differential Revision: https://developer.blender.org/D6293
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_convert.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_convert.c | 104 |
1 files changed, 96 insertions, 8 deletions
diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c index 255f17f13cc..934466475a5 100644 --- a/source/blender/editors/gpencil/gpencil_convert.c +++ b/source/blender/editors/gpencil/gpencil_convert.c @@ -152,7 +152,7 @@ static const EnumPropertyItem *rna_GPConvert_mode_items(bContext *UNUSED(C), * - assumes that the active space is the 3D-View */ static void gp_strokepoint_convertcoords(bContext *C, - bGPdata *gpd, + bGPdata *UNUSED(gpd), bGPDlayer *gpl, bGPDstroke *gps, bGPDspoint *source_pt, @@ -174,7 +174,7 @@ static void gp_strokepoint_convertcoords(bContext *C, /* apply parent transform */ float fpt[3]; - ED_gpencil_parent_location(depsgraph, obact, gpd, gpl, diff_mat); + BKE_gpencil_parent_matrix_get(depsgraph, obact, gpl, diff_mat); mul_v3_m4v3(fpt, diff_mat, &source_pt->x); copy_v3_v3(&pt->x, fpt); @@ -1270,7 +1270,7 @@ static void gp_layer_to_curve(bContext *C, Collection *collection = CTX_data_collection(C); Scene *scene = CTX_data_scene(C); - bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV); + bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_USE_PREV); bGPDstroke *gps, *prev_gps = NULL; Object *ob; Curve *cu; @@ -1410,7 +1410,7 @@ static bool gp_convert_check_has_valid_timing(bContext *C, bGPDlayer *gpl, wmOpe int i; bool valid = true; - if (!gpl || !(gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV)) || + if (!gpl || !(gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_USE_PREV)) || !(gps = gpf->strokes.first)) { return false; } @@ -1476,8 +1476,8 @@ static bool gp_convert_poll(bContext *C) /* only if the current view is 3D View, if there's valid data (i.e. at least one stroke!), * and if we are not in edit mode! */ - return ((sa && sa->spacetype == SPACE_VIEW3D) && (gpl = BKE_gpencil_layer_getactive(gpd)) && - (gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV)) && + return ((sa && sa->spacetype == SPACE_VIEW3D) && (gpl = BKE_gpencil_layer_active_get(gpd)) && + (gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_USE_PREV)) && (gpf->strokes.first) && (!GPENCIL_ANY_EDIT_MODE(gpd))); } @@ -1487,7 +1487,7 @@ static int gp_convert_layer_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); bGPdata *gpd = (bGPdata *)ob->data; - bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); + bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd); Scene *scene = CTX_data_scene(C); const int mode = RNA_enum_get(op->ptr, "type"); const bool norm_weights = RNA_boolean_get(op->ptr, "use_normalize_weights"); @@ -1751,4 +1751,92 @@ void GPENCIL_OT_convert(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } -/* ************************************************ */ +/* Generate Grease Pencil from Image. */ +static bool image_to_gpencil_poll(bContext *C) +{ + SpaceLink *sl = CTX_wm_space_data(C); + if (sl->spacetype == SPACE_IMAGE) { + return true; + } + + return false; +} + +static int image_to_gpencil_exec(bContext *C, wmOperator *op) +{ + const float size = RNA_float_get(op->ptr, "size"); + const bool is_mask = RNA_boolean_get(op->ptr, "mask"); + + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + SpaceImage *sima = CTX_wm_space_image(C); + bool done = false; + + if (sima->image == NULL) { + return OPERATOR_CANCELLED; + } + + /* Create Object. */ + const float *cur = scene->cursor.location; + ushort local_view_bits = 0; + Object *ob = ED_gpencil_add_object(C, cur, local_view_bits); + DEG_relations_tag_update(bmain); /* added object */ + + /* Create material slot. */ + Material *ma = BKE_gpencil_object_material_new(bmain, ob, "Image Material", NULL); + MaterialGPencilStyle *gp_style = ma->gp_style; + gp_style->mode = GP_MATERIAL_MODE_SQUARE; + + /* Add layer and frame. */ + bGPdata *gpd = (bGPdata *)ob->data; + bGPDlayer *gpl = BKE_gpencil_layer_addnew(gpd, "Image Layer", true); + bGPDframe *gpf = BKE_gpencil_frame_addnew(gpl, CFRA); + done = BKE_gpencil_from_image(sima, gpf, size, is_mask); + + if (done) { + /* Delete any selected point. */ + LISTBASE_FOREACH_MUTABLE (bGPDstroke *, gps, &gpf->strokes) { + gp_stroke_delete_tagged_points(gpf, gps, gps->next, GP_SPOINT_SELECT, false, 0); + } + + BKE_reportf(op->reports, RPT_INFO, "Object created"); + } + + return OPERATOR_FINISHED; +} + +void GPENCIL_OT_image_to_grease_pencil(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name = "Generate Grease Pencil Object using image as source"; + ot->idname = "GPENCIL_OT_image_to_grease_pencil"; + ot->description = "Generate a Grease Pencil Object using Image as source"; + + /* api callbacks */ + ot->exec = image_to_gpencil_exec; + ot->poll = image_to_gpencil_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + ot->prop = RNA_def_float(ot->srna, + "size", + 0.005f, + 0.0001f, + 10.0f, + "Point Size", + "Size used for graese pencil points", + 0.001f, + 1.0f); + RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean(ot->srna, + "mask", + false, + "Generate Mask", + "Create an inverted image for masking using alpha channel"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); +} |