Initial Grease Pencil 3.0 stage #106848
|
@ -46,8 +46,8 @@ void legacy_gpencil_frame_to_grease_pencil_drawing(GreasePencilDrawing &drawing,
|
||||||
"radius", ATTR_DOMAIN_POINT);
|
"radius", ATTR_DOMAIN_POINT);
|
||||||
SpanAttributeWriter<float> opacities = attributes.lookup_or_add_for_write_span<float>(
|
SpanAttributeWriter<float> opacities = attributes.lookup_or_add_for_write_span<float>(
|
||||||
"opacity", ATTR_DOMAIN_POINT);
|
"opacity", ATTR_DOMAIN_POINT);
|
||||||
SpanAttributeWriter<float> deltatimes = attributes.lookup_or_add_for_write_span<float>(
|
SpanAttributeWriter<float> delta_times = attributes.lookup_or_add_for_write_span<float>(
|
||||||
"deltatime", ATTR_DOMAIN_POINT);
|
"delta_time", ATTR_DOMAIN_POINT);
|
||||||
SpanAttributeWriter<float> rotations = attributes.lookup_or_add_for_write_span<float>(
|
SpanAttributeWriter<float> rotations = attributes.lookup_or_add_for_write_span<float>(
|
||||||
"rotation", ATTR_DOMAIN_POINT);
|
"rotation", ATTR_DOMAIN_POINT);
|
||||||
SpanAttributeWriter<ColorGeometry4f> vertex_colors =
|
SpanAttributeWriter<ColorGeometry4f> vertex_colors =
|
||||||
|
@ -56,9 +56,28 @@ void legacy_gpencil_frame_to_grease_pencil_drawing(GreasePencilDrawing &drawing,
|
||||||
".selection", ATTR_DOMAIN_POINT);
|
".selection", ATTR_DOMAIN_POINT);
|
||||||
|
|
||||||
/* Curve Attributes. */
|
/* Curve Attributes. */
|
||||||
SpanAttributeWriter<bool> curve_cyclic = attributes.lookup_or_add_for_write_span<bool>(
|
SpanAttributeWriter<bool> stroke_cyclic = attributes.lookup_or_add_for_write_span<bool>(
|
||||||
"cyclic", ATTR_DOMAIN_CURVE);
|
"cyclic", ATTR_DOMAIN_CURVE);
|
||||||
SpanAttributeWriter<int> curve_materials = attributes.lookup_or_add_for_write_span<int>(
|
/* TODO: This should be a `double` attribute. */
|
||||||
|
SpanAttributeWriter<float> stroke_init_times = attributes.lookup_or_add_for_write_span<float>(
|
||||||
|
"init_time", ATTR_DOMAIN_CURVE);
|
||||||
|
SpanAttributeWriter<int8_t> stroke_start_caps = attributes.lookup_or_add_for_write_span<int8_t>(
|
||||||
|
"start_cap", ATTR_DOMAIN_CURVE);
|
||||||
|
SpanAttributeWriter<int8_t> stroke_end_caps = attributes.lookup_or_add_for_write_span<int8_t>(
|
||||||
|
"end_cap", ATTR_DOMAIN_CURVE);
|
||||||
|
SpanAttributeWriter<float> stroke_hardnesses = attributes.lookup_or_add_for_write_span<float>(
|
||||||
|
"hardness", ATTR_DOMAIN_CURVE);
|
||||||
|
SpanAttributeWriter<float> stroke_point_aspect_ratios =
|
||||||
|
attributes.lookup_or_add_for_write_span<float>("point_aspect_ratio", ATTR_DOMAIN_CURVE);
|
||||||
|
SpanAttributeWriter<float2> stroke_fill_translations =
|
||||||
|
attributes.lookup_or_add_for_write_span<float2>("fill_translation", ATTR_DOMAIN_CURVE);
|
||||||
|
SpanAttributeWriter<float> stroke_fill_rotations =
|
||||||
|
attributes.lookup_or_add_for_write_span<float>("fill_rotation", ATTR_DOMAIN_CURVE);
|
||||||
|
SpanAttributeWriter<float2> stroke_fill_scales = attributes.lookup_or_add_for_write_span<float2>(
|
||||||
|
"fill_scale", ATTR_DOMAIN_CURVE);
|
||||||
|
SpanAttributeWriter<ColorGeometry4f> stroke_fill_colors =
|
||||||
|
attributes.lookup_or_add_for_write_span<ColorGeometry4f>("fill_color", ATTR_DOMAIN_CURVE);
|
||||||
|
SpanAttributeWriter<int> stroke_materials = attributes.lookup_or_add_for_write_span<int>(
|
||||||
"material_index", ATTR_DOMAIN_CURVE);
|
"material_index", ATTR_DOMAIN_CURVE);
|
||||||
|
|
||||||
int stroke_i = 0;
|
int stroke_i = 0;
|
||||||
|
@ -66,8 +85,19 @@ void legacy_gpencil_frame_to_grease_pencil_drawing(GreasePencilDrawing &drawing,
|
||||||
/* TODO: check if gps->editcurve is not nullptr and parse bezier curve instead. */
|
/* TODO: check if gps->editcurve is not nullptr and parse bezier curve instead. */
|
||||||
|
|
||||||
/* Write curve attributes. */
|
/* Write curve attributes. */
|
||||||
curve_cyclic.span[stroke_i] = (gps->flag & GP_STROKE_CYCLIC) != 0;
|
stroke_cyclic.span[stroke_i] = (gps->flag & GP_STROKE_CYCLIC) != 0;
|
||||||
curve_materials.span[stroke_i] = gps->mat_nr;
|
/* TODO: This should be a `double` attribute. */
|
||||||
|
stroke_init_times.span[stroke_i] = static_cast<float>(gps->inittime);
|
||||||
|
stroke_start_caps.span[stroke_i] = static_cast<int8_t>(gps->caps[0]);
|
||||||
|
stroke_end_caps.span[stroke_i] = static_cast<int8_t>(gps->caps[1]);
|
||||||
|
stroke_hardnesses.span[stroke_i] = gps->hardeness;
|
||||||
|
stroke_point_aspect_ratios.span[stroke_i] = gps->aspect_ratio[0] /
|
||||||
|
max_ff(gps->aspect_ratio[1], 1e-8);
|
||||||
|
stroke_fill_translations.span[stroke_i] = float2(gps->uv_translation);
|
||||||
|
stroke_fill_rotations.span[stroke_i] = gps->uv_rotation;
|
||||||
|
stroke_fill_scales.span[stroke_i] = float2(gps->uv_scale);
|
||||||
|
stroke_fill_colors.span[stroke_i] = ColorGeometry4f(gps->vert_color_fill);
|
||||||
|
stroke_materials.span[stroke_i] = gps->mat_nr;
|
||||||
|
|
||||||
/* Write point attributes. */
|
/* Write point attributes. */
|
||||||
IndexRange stroke_points_range = points_by_curve[stroke_i];
|
IndexRange stroke_points_range = points_by_curve[stroke_i];
|
||||||
|
@ -79,7 +109,7 @@ void legacy_gpencil_frame_to_grease_pencil_drawing(GreasePencilDrawing &drawing,
|
||||||
MutableSpan<float3> stroke_positions = positions.slice(stroke_points_range);
|
MutableSpan<float3> stroke_positions = positions.slice(stroke_points_range);
|
||||||
MutableSpan<float> stroke_radii = radii.span.slice(stroke_points_range);
|
MutableSpan<float> stroke_radii = radii.span.slice(stroke_points_range);
|
||||||
MutableSpan<float> stroke_opacities = opacities.span.slice(stroke_points_range);
|
MutableSpan<float> stroke_opacities = opacities.span.slice(stroke_points_range);
|
||||||
MutableSpan<float> stroke_deltatimes = deltatimes.span.slice(stroke_points_range);
|
MutableSpan<float> stroke_deltatimes = delta_times.span.slice(stroke_points_range);
|
||||||
MutableSpan<float> stroke_rotations = rotations.span.slice(stroke_points_range);
|
MutableSpan<float> stroke_rotations = rotations.span.slice(stroke_points_range);
|
||||||
MutableSpan<ColorGeometry4f> stroke_vertex_colors = vertex_colors.span.slice(
|
MutableSpan<ColorGeometry4f> stroke_vertex_colors = vertex_colors.span.slice(
|
||||||
stroke_points_range);
|
stroke_points_range);
|
||||||
|
@ -114,13 +144,22 @@ void legacy_gpencil_frame_to_grease_pencil_drawing(GreasePencilDrawing &drawing,
|
||||||
|
|
||||||
radii.finish();
|
radii.finish();
|
||||||
opacities.finish();
|
opacities.finish();
|
||||||
deltatimes.finish();
|
delta_times.finish();
|
||||||
rotations.finish();
|
rotations.finish();
|
||||||
vertex_colors.finish();
|
vertex_colors.finish();
|
||||||
selection.finish();
|
selection.finish();
|
||||||
|
|
||||||
curve_cyclic.finish();
|
stroke_cyclic.finish();
|
||||||
curve_materials.finish();
|
stroke_init_times.finish();
|
||||||
|
stroke_start_caps.finish();
|
||||||
|
|||||||
|
stroke_end_caps.finish();
|
||||||
|
stroke_hardnesses.finish();
|
||||||
|
stroke_point_aspect_ratios.finish();
|
||||||
|
stroke_fill_translations.finish();
|
||||||
|
stroke_fill_rotations.finish();
|
||||||
|
stroke_fill_scales.finish();
|
||||||
|
stroke_fill_colors.finish();
|
||||||
|
stroke_materials.finish();
|
||||||
|
|
||||||
curves.tag_topology_changed();
|
curves.tag_topology_changed();
|
||||||
|
|
||||||
|
|
|
@ -275,6 +275,10 @@ static void grease_pencil_batches_ensure(GreasePencil &grease_pencil, int cfra)
|
||||||
"radius", ATTR_DOMAIN_POINT, 1.0f);
|
"radius", ATTR_DOMAIN_POINT, 1.0f);
|
||||||
const VArray<float> opacities = attributes.lookup_or_default<float>(
|
const VArray<float> opacities = attributes.lookup_or_default<float>(
|
||||||
"opacity", ATTR_DOMAIN_POINT, 1.0f);
|
"opacity", ATTR_DOMAIN_POINT, 1.0f);
|
||||||
|
const VArray<int8_t> start_caps = attributes.lookup_or_default<int8_t>(
|
||||||
|
"start_cap", ATTR_DOMAIN_CURVE, 0);
|
||||||
|
const VArray<int8_t> end_caps = attributes.lookup_or_default<int8_t>(
|
||||||
|
"end_cap", ATTR_DOMAIN_CURVE, 0);
|
||||||
const VArray<int> materials = attributes.lookup_or_default<int>(
|
const VArray<int> materials = attributes.lookup_or_default<int>(
|
||||||
"material_index", ATTR_DOMAIN_CURVE, -1);
|
"material_index", ATTR_DOMAIN_CURVE, -1);
|
||||||
const Span<uint3> triangles = drawing.triangles();
|
const Span<uint3> triangles = drawing.triangles();
|
||||||
|
@ -285,13 +289,16 @@ static void grease_pencil_batches_ensure(GreasePencil &grease_pencil, int cfra)
|
||||||
|
|
||||||
auto populate_point = [&](IndexRange verts_range,
|
auto populate_point = [&](IndexRange verts_range,
|
||||||
int curve_i,
|
int curve_i,
|
||||||
|
int8_t start_cap,
|
||||||
|
int8_t end_cap,
|
||||||
int point_i,
|
int point_i,
|
||||||
int idx,
|
int idx,
|
||||||
GreasePencilStrokeVert &s_vert,
|
GreasePencilStrokeVert &s_vert,
|
||||||
GreasePencilColorVert &c_vert) {
|
GreasePencilColorVert &c_vert) {
|
||||||
copy_v3_v3(s_vert.pos, positions[point_i]);
|
copy_v3_v3(s_vert.pos, positions[point_i]);
|
||||||
s_vert.radius = radii[point_i];
|
s_vert.radius = radii[point_i] * ((end_cap == GP_STROKE_CAP_TYPE_ROUND) ? 1.0f : -1.0f);
|
||||||
s_vert.opacity = opacities[point_i];
|
s_vert.opacity = opacities[point_i] *
|
||||||
|
((start_cap == GP_STROKE_CAP_TYPE_ROUND) ? 1.0f : -1.0f);
|
||||||
s_vert.point_id = verts_range[idx];
|
s_vert.point_id = verts_range[idx];
|
||||||
s_vert.stroke_id = verts_range.first();
|
s_vert.stroke_id = verts_range.first();
|
||||||
s_vert.mat = materials[curve_i] % GPENCIL_MATERIAL_BUFFER_LEN;
|
s_vert.mat = materials[curve_i] % GPENCIL_MATERIAL_BUFFER_LEN;
|
||||||
|
@ -306,8 +313,6 @@ static void grease_pencil_batches_ensure(GreasePencil &grease_pencil, int cfra)
|
||||||
/* TODO */
|
/* TODO */
|
||||||
copy_v4_v4(c_vert.vcol, float4(0.0f, 0.0f, 0.0f, 0.0f));
|
copy_v4_v4(c_vert.vcol, float4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||||
copy_v4_v4(c_vert.fcol, float4(0.0f, 0.0f, 0.0f, 0.0f));
|
copy_v4_v4(c_vert.fcol, float4(0.0f, 0.0f, 0.0f, 0.0f));
|
||||||
|
|
||||||
/* TODO */
|
|
||||||
c_vert.fcol[3] = (int(c_vert.fcol[3] * 10000.0f) * 10.0f) + 1.0f;
|
c_vert.fcol[3] = (int(c_vert.fcol[3] * 10000.0f) * 10.0f) + 1.0f;
|
||||||
|
|
||||||
int v_mat = (verts_range[idx] << GP_VERTEX_ID_SHIFT) | GP_IS_STROKE_VERTEX_BIT;
|
int v_mat = (verts_range[idx] << GP_VERTEX_ID_SHIFT) | GP_IS_STROKE_VERTEX_BIT;
|
||||||
|
@ -343,12 +348,26 @@ static void grease_pencil_batches_ensure(GreasePencil &grease_pencil, int cfra)
|
||||||
/* Write all the point attributes to the vertex buffers. Create a quad for each point. */
|
/* Write all the point attributes to the vertex buffers. Create a quad for each point. */
|
||||||
for (const int i : IndexRange(points.size())) {
|
for (const int i : IndexRange(points.size())) {
|
||||||
const int idx = i + 1;
|
const int idx = i + 1;
|
||||||
populate_point(verts_range, curve_i, points[i], idx, verts_slice[idx], cols_slice[idx]);
|
populate_point(verts_range,
|
||||||
|
curve_i,
|
||||||
|
start_caps[curve_i],
|
||||||
|
end_caps[curve_i],
|
||||||
|
points[i],
|
||||||
|
idx,
|
||||||
|
verts_slice[idx],
|
||||||
|
cols_slice[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_cyclic) {
|
if (is_cyclic) {
|
||||||
const int idx = points.size() + 1;
|
const int idx = points.size() + 1;
|
||||||
populate_point(verts_range, curve_i, points[0], idx, verts_slice[idx], cols_slice[idx]);
|
populate_point(verts_range,
|
||||||
|
curve_i,
|
||||||
|
start_caps[curve_i],
|
||||||
|
end_caps[curve_i],
|
||||||
|
points[0],
|
||||||
|
idx,
|
||||||
|
verts_slice[idx],
|
||||||
|
cols_slice[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Last vertex is not drawn. */
|
/* Last vertex is not drawn. */
|
||||||
|
|
|
@ -39,6 +39,13 @@ struct GreasePencil;
|
||||||
struct BlendDataReader;
|
struct BlendDataReader;
|
||||||
struct BlendWriter;
|
struct BlendWriter;
|
||||||
|
|
||||||
|
typedef enum GreasePencilStrokeCapType {
|
||||||
|
GP_STROKE_CAP_TYPE_ROUND = 0,
|
||||||
|
GP_STROKE_CAP_TYPE_FLAT = 1,
|
||||||
|
/* Keep last. */
|
||||||
|
GP_STROKE_CAP_TYPE_MAX,
|
||||||
|
} GreasePencilStrokeCapType;
|
||||||
|
|
||||||
typedef enum GreasePencilDrawingType {
|
typedef enum GreasePencilDrawingType {
|
||||||
GREASE_PENCIL_DRAWING = 0,
|
GREASE_PENCIL_DRAWING = 0,
|
||||||
GREASE_PENCIL_DRAWING_REFERENCE = 1,
|
GREASE_PENCIL_DRAWING_REFERENCE = 1,
|
||||||
|
|
Loading…
Reference in New Issue
I thought we had some RAII helper which does
finish()
at the end of the scope.Or maybe it was just an idea to have one? Maybe Jacques of Hans remember better :)
Right now regular we do this manually, but true, this could be better to use
BLI_SCOPED_DEFER
.We don't really want to do non-trivial work in a class's destructor. It's also helpful to make this explicit, since sometimes it matters when it happens.
I don't really understand it, and can't say I'm sold on the motivation.
But in any case, at this point the discussion does not affect the PR, so lets consider it resolved here, and any followup we can do in the chat instead.