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
This commit is contained in:
parent
3de3c3c23a
commit
2acebcae24
|
@ -154,17 +154,6 @@ bool BKE_gpencil_merge_materials(struct Object *ob,
|
|||
/* statistics functions */
|
||||
void BKE_gpencil_stats_update(struct bGPdata *gpd);
|
||||
|
||||
/* Utilities for creating and populating GP strokes */
|
||||
/* - Number of values defining each point in the built-in data
|
||||
* buffers for primitives (e.g. 2D Monkey)
|
||||
*/
|
||||
#define GP_PRIM_DATABUF_SIZE 5
|
||||
|
||||
void BKE_gpencil_stroke_add_points(struct bGPDstroke *gps,
|
||||
const float *array,
|
||||
const int totpoints,
|
||||
const float mat[4][4]);
|
||||
|
||||
struct bGPDstroke *BKE_gpencil_stroke_new(int mat_idx, int totpoints, short thickness);
|
||||
struct bGPDstroke *BKE_gpencil_stroke_add(
|
||||
struct bGPDframe *gpf, int mat_idx, int totpoints, short thickness, const bool insert_at_head);
|
||||
|
|
|
@ -805,32 +805,6 @@ bGPdata *BKE_gpencil_data_addnew(Main *bmain, const char name[])
|
|||
/* Primitive Creation */
|
||||
/* Utilities for easier bulk-creation of geometry */
|
||||
|
||||
/**
|
||||
* Populate stroke with point data from data buffers.
|
||||
* \param gps: Grease pencil stroke
|
||||
* \param array: Flat array of point data values. Each entry has #GP_PRIM_DATABUF_SIZE values.
|
||||
* \param totpoints: Total of points
|
||||
* \param mat: 4x4 transform matrix to transform points into the right coordinate space.
|
||||
*/
|
||||
void BKE_gpencil_stroke_add_points(bGPDstroke *gps,
|
||||
const float *array,
|
||||
const int totpoints,
|
||||
const float mat[4][4])
|
||||
{
|
||||
for (int i = 0; i < totpoints; i++) {
|
||||
bGPDspoint *pt = &gps->points[i];
|
||||
const int x = GP_PRIM_DATABUF_SIZE * i;
|
||||
|
||||
pt->x = array[x];
|
||||
pt->y = array[x + 1];
|
||||
pt->z = array[x + 2];
|
||||
mul_m4_v3(mat, &pt->x);
|
||||
|
||||
pt->pressure = array[x + 3];
|
||||
pt->strength = array[x + 4];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new stroke, with pre-allocated data buffers.
|
||||
* \param mat_idx: Index of the material
|
||||
|
|
|
@ -39,6 +39,32 @@
|
|||
|
||||
#include "ED_gpencil.h"
|
||||
|
||||
/**
|
||||
* Populate stroke with point data from data buffers.
|
||||
* \param gps: Grease pencil stroke
|
||||
* \param array: Flat array of point data values. Each entry has #GP_PRIM_DATABUF_SIZE values.
|
||||
* \param totpoints: Total of points
|
||||
* \param mat: 4x4 transform matrix to transform points into the right coordinate space.
|
||||
*/
|
||||
void ED_gpencil_stroke_init_data(bGPDstroke *gps,
|
||||
const float *array,
|
||||
const int totpoints,
|
||||
const float mat[4][4])
|
||||
{
|
||||
for (int i = 0; i < totpoints; i++) {
|
||||
bGPDspoint *pt = &gps->points[i];
|
||||
const int x = GP_PRIM_DATABUF_SIZE * i;
|
||||
|
||||
pt->x = array[x];
|
||||
pt->y = array[x + 1];
|
||||
pt->z = array[x + 2];
|
||||
mul_m4_v3(mat, &pt->x);
|
||||
|
||||
pt->pressure = array[x + 3];
|
||||
pt->strength = array[x + 4];
|
||||
}
|
||||
}
|
||||
|
||||
/* Definition of the most important info from a color */
|
||||
typedef struct ColorTemplate {
|
||||
const char *name;
|
||||
|
@ -847,115 +873,115 @@ void ED_gpencil_create_monkey(bContext *C, Object *ob, float mat[4][4])
|
|||
|
||||
/* generate strokes */
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin, 270, 75, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data0, 270, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data0, 270, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 33, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data1, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data1, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 18, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data2, 18, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data2, 18, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 64, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data3, 64, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data3, 64, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 33, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data4, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data4, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 64, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data5, 64, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data5, 64, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 33, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data6, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data6, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 18, 40, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data7, 18, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data7, 18, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Eyes, 49, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data8, 49, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data8, 49, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 33, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data9, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data9, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Eyes, 49, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data10, 49, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data10, 49, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 18, 40, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data11, 18, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data11, 18, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 18, 40, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data12, 18, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data12, 18, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data13, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data13, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data14, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data14, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 65, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data15, 65, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data15, 65, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 34, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data16, 34, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data16, 34, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data17, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data17, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 40, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data18, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data18, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 34, 40, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data19, 34, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data19, 34, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data20, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data20, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 64, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data21, 64, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data21, 64, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Pupils, 26, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data22, 26, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data22, 26, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Pupils, 26, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data23, 26, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data23, 26, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data24, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data24, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 18, 40, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data25, 18, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data25, 18, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 18, 40, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data26, 18, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data26, 18, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data27, 33, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data27, 33, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
/* update depsgraph */
|
||||
|
|
|
@ -235,7 +235,7 @@ void ED_gpencil_create_stroke(bContext *C, Object *ob, float mat[4][4])
|
|||
|
||||
/* generate stroke */
|
||||
gps = BKE_gpencil_stroke_add(frame_lines, color_black, 175, 75, false);
|
||||
BKE_gpencil_stroke_add_points(gps, data0, 175, mat);
|
||||
ED_gpencil_stroke_init_data(gps, data0, 175, mat);
|
||||
BKE_gpencil_stroke_geometry_update(gpd, gps);
|
||||
|
||||
/* update depsgraph */
|
||||
|
|
|
@ -251,6 +251,13 @@ void ED_gpencil_brush_draw_eraser(struct Brush *brush, int x, int y);
|
|||
|
||||
/* ----------- Add Primitive Utilities -------------- */
|
||||
|
||||
/* Number of values defining each point in the built-in data buffers for primitives. */
|
||||
#define GP_PRIM_DATABUF_SIZE 5
|
||||
void ED_gpencil_stroke_init_data(struct bGPDstroke *gps,
|
||||
const float *array,
|
||||
const int totpoints,
|
||||
const float mat[4][4]);
|
||||
|
||||
void ED_gpencil_create_blank(struct bContext *C, struct Object *ob, float mat[4][4]);
|
||||
void ED_gpencil_create_monkey(struct bContext *C, struct Object *ob, float mat[4][4]);
|
||||
void ED_gpencil_create_stroke(struct bContext *C, struct Object *ob, float mat[4][4]);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue