GPencil: Add "Convert Text to Gpencil"

Currently when you try to convert a Text-object to Grease pencil from the Object-menu or via the operator in some other way, the Text-object is only converted to a Curve.

This commit converts that curve to a Grease pencil object.

Differential Revision: https://developer.blender.org/D11117
This commit is contained in:
Antonio Vazquez 2021-04-29 17:45:46 +02:00 committed by Antonio Vazquez
parent c9d1143b33
commit 41820e8a8e
1 changed files with 22 additions and 0 deletions

View File

@ -2628,6 +2628,7 @@ static int object_convert_exec(bContext *C, wmOperator *op)
int a, mballConverted = 0;
bool gpencilConverted = false;
bool gpencilCurveConverted = false;
/* don't forget multiple users! */
@ -2912,6 +2913,16 @@ static int object_convert_exec(bContext *C, wmOperator *op)
/* meshes doesn't use displist */
BKE_object_free_curve_cache(newob);
}
else if (target == OB_GPENCIL) {
ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0;
Object *ob_gpencil = ED_gpencil_add_object(C, newob->loc, local_view_bits);
copy_v3_v3(ob_gpencil->rot, newob->rot);
copy_v3_v3(ob_gpencil->scale, newob->scale);
BKE_gpencil_convert_curve(bmain, scene, ob_gpencil, newob, false, 1.0f, 0.0f);
gpencilConverted = true;
gpencilCurveConverted = true;
basen = NULL;
}
}
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
ob->flag |= OB_DONE;
@ -3093,6 +3104,17 @@ static int object_convert_exec(bContext *C, wmOperator *op)
FOREACH_SCENE_OBJECT_END;
}
}
else {
/* Remove Text curves converted to Grease Pencil object to avoid duplicated curves. */
if (gpencilCurveConverted) {
FOREACH_SCENE_OBJECT_BEGIN (scene, ob_delete) {
if (ELEM(ob_delete->type, OB_CURVE) && (ob_delete->flag & OB_DONE)) {
ED_object_base_free_and_unlink(bmain, scene, ob_delete);
}
}
FOREACH_SCENE_OBJECT_END;
}
}
// XXX ED_object_editmode_enter(C, 0);
// XXX exit_editmode(C, EM_FREEDATA|); /* freedata, but no undo */