GPencil: Add Sample parameter to Convert curve

This allows to resample the stroke to avoid too dense geometry.
This commit is contained in:
2020-08-12 12:35:52 +02:00
parent 9abdafe840
commit 504c257dae
4 changed files with 24 additions and 7 deletions

View File

@@ -38,7 +38,8 @@ void BKE_gpencil_convert_curve(struct Main *bmain,
const bool gpencil_lines, const bool gpencil_lines,
const bool use_collections, const bool use_collections,
const bool only_stroke, const bool only_stroke,
const float scale_thickness); const float scale_thickness,
const float sample);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -173,6 +173,7 @@ static void gpencil_convert_spline(Main *bmain,
const bool gpencil_lines, const bool gpencil_lines,
const bool only_stroke, const bool only_stroke,
const float scale_thickness, const float scale_thickness,
const float sample,
bGPDframe *gpf, bGPDframe *gpf,
Nurb *nu) Nurb *nu)
{ {
@@ -392,6 +393,9 @@ static void gpencil_convert_spline(Main *bmain,
if ((cyclic) && (!do_stroke)) { if ((cyclic) && (!do_stroke)) {
BKE_gpencil_stroke_close(gps); BKE_gpencil_stroke_close(gps);
} }
if (sample > 0.0f) {
BKE_gpencil_stroke_sample(gps, sample, false);
}
/* Recalc fill geometry. */ /* Recalc fill geometry. */
BKE_gpencil_stroke_geometry_update(gps); BKE_gpencil_stroke_geometry_update(gps);
@@ -408,6 +412,7 @@ static void gpencil_convert_spline(Main *bmain,
* \param use_collections: Create layers using collection names. * \param use_collections: Create layers using collection names.
* \param only_stroke: The material must be only stroke without fill. * \param only_stroke: The material must be only stroke without fill.
* \param scale_thickness: Scale thickness factor. * \param scale_thickness: Scale thickness factor.
* \param sample: Sample distance, zero to disable.
*/ */
void BKE_gpencil_convert_curve(Main *bmain, void BKE_gpencil_convert_curve(Main *bmain,
Scene *scene, Scene *scene,
@@ -416,7 +421,8 @@ void BKE_gpencil_convert_curve(Main *bmain,
const bool gpencil_lines, const bool gpencil_lines,
const bool use_collections, const bool use_collections,
const bool only_stroke, const bool only_stroke,
const float scale_thickness) const float scale_thickness,
const float sample)
{ {
if (ELEM(NULL, ob_gp, ob_cu) || (ob_gp->type != OB_GPENCIL) || (ob_gp->data == NULL)) { if (ELEM(NULL, ob_gp, ob_cu) || (ob_gp->type != OB_GPENCIL) || (ob_gp->data == NULL)) {
return; return;
@@ -455,7 +461,7 @@ void BKE_gpencil_convert_curve(Main *bmain,
/* Read all splines of the curve and create a stroke for each. */ /* Read all splines of the curve and create a stroke for each. */
LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) { LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
gpencil_convert_spline( gpencil_convert_spline(
bmain, ob_gp, ob_cu, gpencil_lines, only_stroke, scale_thickness, gpf, nu); bmain, ob_gp, ob_cu, gpencil_lines, only_stroke, scale_thickness, sample, gpf, nu);
} }
/* Tag for recalculation */ /* Tag for recalculation */

View File

@@ -2647,7 +2647,7 @@ static int object_convert_exec(bContext *C, wmOperator *op)
ob_gpencil = ED_gpencil_add_object(C, ob->loc, local_view_bits); ob_gpencil = ED_gpencil_add_object(C, ob->loc, local_view_bits);
copy_v3_v3(ob_gpencil->rot, ob->rot); copy_v3_v3(ob_gpencil->rot, ob->rot);
copy_v3_v3(ob_gpencil->scale, ob->scale); copy_v3_v3(ob_gpencil->scale, ob->scale);
BKE_gpencil_convert_curve(bmain, scene, ob_gpencil, ob, false, false, true, 1.0f); BKE_gpencil_convert_curve(bmain, scene, ob_gpencil, ob, false, false, true, 1.0f, 0.0f);
gpencilConverted = true; gpencilConverted = true;
} }
} }

View File

@@ -715,7 +715,8 @@ bool rna_Object_generate_gpencil_strokes(Object *ob,
Object *ob_gpencil, Object *ob_gpencil,
bool gpencil_lines, bool gpencil_lines,
bool use_collections, bool use_collections,
float scale_thickness) float scale_thickness,
float sample)
{ {
if (ob->type != OB_CURVE) { if (ob->type != OB_CURVE) {
BKE_reportf(reports, BKE_reportf(reports,
@@ -727,8 +728,15 @@ bool rna_Object_generate_gpencil_strokes(Object *ob,
Main *bmain = CTX_data_main(C); Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C); Scene *scene = CTX_data_scene(C);
BKE_gpencil_convert_curve( BKE_gpencil_convert_curve(bmain,
bmain, scene, ob_gpencil, ob, gpencil_lines, use_collections, false, scale_thickness); scene,
ob_gpencil,
ob,
gpencil_lines,
use_collections,
false,
scale_thickness,
sample);
WM_main_add_notifier(NC_GPENCIL | ND_DATA, NULL); WM_main_add_notifier(NC_GPENCIL | ND_DATA, NULL);
@@ -1202,6 +1210,8 @@ void RNA_api_object(StructRNA *srna)
parm = RNA_def_boolean(func, "use_collections", true, "", "Use Collections"); parm = RNA_def_boolean(func, "use_collections", true, "", "Use Collections");
parm = RNA_def_float( parm = RNA_def_float(
func, "scale_thickness", 1.0f, 0.0f, FLT_MAX, "", "Thickness scaling factor", 0.0f, 100.0f); func, "scale_thickness", 1.0f, 0.0f, FLT_MAX, "", "Thickness scaling factor", 0.0f, 100.0f);
parm = RNA_def_float(
func, "sample", 0.0f, 0.0f, FLT_MAX, "", "Sample distance, zero to disable", 0.0f, 100.0f);
parm = RNA_def_boolean(func, "result", 0, "", "Result"); parm = RNA_def_boolean(func, "result", 0, "", "Result");
RNA_def_function_return(func, parm); RNA_def_function_return(func, parm);
} }