diff options
author | Hans Goudey <h.goudey@me.com> | 2021-07-14 17:11:41 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-07-14 17:11:41 +0300 |
commit | 2acebcae24a6cb7cc5dcef6ddc437396e129da46 (patch) | |
tree | 1c902c7ee3dbaf1f3b4bde813e397047cfa0d90f /source/blender/gpencil_modifiers | |
parent | 3de3c3c23a930943086ab9719f0abe5c069cc4b5 (diff) |
Cleanup: Avoid duplication in line art stroke generation
The BKE_gpencil_stroke_add_points API function worked well for
creating the primitives in the add object menu, but it expected a
specific data format that doesn't make sense in a dynamic context.
As evidence of that we can see the way source data was duplicated
in the line art file just to use this API function.
This commit solves that problem in two ways:
- Clean up the line art function (this should make it faster too).
- Move/rename the function so its intended use is more clear.
Differential Revision: https://developer.blender.org/D11909
Diffstat (limited to 'source/blender/gpencil_modifiers')
-rw-r--r-- | source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c index cddf3b7cfb5..9899d889c56 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c @@ -4217,9 +4217,6 @@ static void lineart_gpencil_generate(LineartCache *cache, /* (!orig_col && !orig_ob) means the whole scene is selected. */ - float mat[4][4]; - unit_m4(mat); - int enabled_types = cache->rb_edge_types; bool invert_input = modifier_flags & LRT_GPENCIL_INVERT_SOURCE_VGROUP; bool match_output = modifier_flags & LRT_GPENCIL_MATCH_OUTPUT_VGROUP; @@ -4271,29 +4268,20 @@ static void lineart_gpencil_generate(LineartCache *cache, /* Preserved: If we ever do asynchronous generation, this picked flag should be set here. */ // ec->picked = 1; - int array_idx = 0; - int count = MOD_lineart_chain_count(ec); + const int count = MOD_lineart_chain_count(ec); bGPDstroke *gps = BKE_gpencil_stroke_add(gpf, color_idx, count, thickness, false); - float *stroke_data = MEM_callocN(sizeof(float) * count * GP_PRIM_DATABUF_SIZE, - "line art add stroke"); - - LISTBASE_FOREACH (LineartEdgeChainItem *, eci, &ec->chain) { - stroke_data[array_idx] = eci->gpos[0]; - stroke_data[array_idx + 1] = eci->gpos[1]; - stroke_data[array_idx + 2] = eci->gpos[2]; - mul_m4_v3(gp_obmat_inverse, &stroke_data[array_idx]); - stroke_data[array_idx + 3] = 1; /* thickness. */ - stroke_data[array_idx + 4] = opacity; /* hardness?. */ - array_idx += 5; + int i; + LISTBASE_FOREACH_INDEX (LineartEdgeChainItem *, eci, &ec->chain, i) { + bGPDspoint *point = &gps->points[i]; + mul_v3_m4v3(&point->x, gp_obmat_inverse, eci->gpos); + point->pressure = 1.0f; + point->strength = opacity; } - BKE_gpencil_stroke_add_points(gps, stroke_data, count, mat); BKE_gpencil_dvert_ensure(gps); gps->mat_nr = max_ii(material_nr, 0); - MEM_freeN(stroke_data); - if (source_vgname && vgname) { Object *eval_ob = DEG_get_evaluated_object(depsgraph, ec->object_ref); int gpdg = -1; |