GPv3: Add Compound Shapes Rendering (i.e. Hole rendering) #12

Closed
casey-bianco-davis wants to merge 8 commits from GPv3-Compound-Shapes-2 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
6 changed files with 15 additions and 20 deletions
Showing only changes of commit 54f486be67 - Show all commits

View File

@ -87,7 +87,7 @@ class Drawing : public ::GreasePencilDrawing {
const bke::CurvesGeometry &strokes() const; const bke::CurvesGeometry &strokes() const;
bke::CurvesGeometry &strokes_for_write(); bke::CurvesGeometry &strokes_for_write();
Array<IndexMask> get_shapes_index_masks(IndexMaskMemory &memory) const; Vector<IndexMask> get_shapes_index_masks(IndexMaskMemory &memory) const;
/** /**
* The triangles for all the fills in the geometry. * The triangles for all the fills in the geometry.

View File

@ -367,32 +367,27 @@ Drawing::~Drawing()
this->runtime = nullptr; this->runtime = nullptr;
} }
Array<IndexMask> Drawing::get_shapes_index_masks(IndexMaskMemory &memory) const Vector<IndexMask> Drawing::get_shapes_index_masks(IndexMaskMemory &memory) const
{ {
const CurvesGeometry &curves = this->strokes(); const CurvesGeometry &curves = this->strokes();
const bke::AttributeAccessor attributes = curves.attributes(); const bke::AttributeAccessor attributes = curves.attributes();
const int num_curves = curves.curves_num();
const VArray<int> shape_ids = *attributes.lookup<int>("shape_id", bke::AttrDomain::Curve); const VArray<int> shape_ids = *attributes.lookup<int>("shape_id", bke::AttrDomain::Curve);
if (!shape_ids) { if (!shape_ids) {
/* If the attribute does not exist then the default is each shape containing one curve. */ /* If the attribute does not exist then the default is each shape containing one curve. */
Array<IndexMask> data(num_curves); Vector<IndexMask> shapes;
IndexMask::from_groups<int>( for (const int i : curves.curves_range()) {
IndexMask(num_curves), memory, [&](const int i) { return i; }, data); shapes.append(IndexRange::from_single(i));
return data;
} }
const int max_shape_id = *std::max_element(shape_ids.get_internal_span().begin(), return shapes;
shape_ids.get_internal_span().end()); }
Array<IndexMask> data(max_shape_id + 1); VectorSet<int> shape_indexing;
IndexMask::from_groups<int>( const Vector<IndexMask> shapes = IndexMask::from_group_ids(shape_ids, memory, shape_indexing);
IndexRange(num_curves), memory, [&](const int i) { return shape_ids[i]; }, data);
return data; return shapes;
} }
static bool check_self_intersections(Span<float2> projverts) static bool check_self_intersections(Span<float2> projverts)
@ -530,7 +525,7 @@ Span<Vector<uint3>> Drawing::triangles() const
const Array<int> point_to_curve_map = curves.point_to_curve_map(); const Array<int> point_to_curve_map = curves.point_to_curve_map();
IndexMaskMemory memory; IndexMaskMemory memory;
const Array<IndexMask> groups = this->get_shapes_index_masks(memory); const Vector<IndexMask> groups = this->get_shapes_index_masks(memory);
r_data.resize(groups.size() + 1); r_data.resize(groups.size() + 1);
MutableSpan<Vector<uint3>> strokes_triangles = r_data.as_mutable_span(); MutableSpan<Vector<uint3>> strokes_triangles = r_data.as_mutable_span();

View File

@ -725,7 +725,7 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
IndexMaskMemory memory; IndexMaskMemory memory;
const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes( const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes(
*ob, info.drawing, memory); *ob, info.drawing, memory);
const Array<IndexMask> groups = info.drawing.get_shapes_index_masks(memory); const Vector<IndexMask> groups = info.drawing.get_shapes_index_masks(memory);
/* Precompute all the triangle and vertex counts. /* Precompute all the triangle and vertex counts.
* In case the drawing should not be rendered, we need to compute the offset where the next * In case the drawing should not be rendered, we need to compute the offset where the next

View File

@ -89,7 +89,7 @@ class GreasePencil {
IndexMaskMemory memory; IndexMaskMemory memory;
const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes( const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes(
*ob, info.drawing, memory); *ob, info.drawing, memory);
const Array<IndexMask> groups = info.drawing.get_shapes_index_masks(memory); const Vector<IndexMask> groups = info.drawing.get_shapes_index_masks(memory);
const Span<Vector<uint3>> triangles = info.drawing.triangles(); const Span<Vector<uint3>> triangles = info.drawing.triangles();

View File

@ -323,7 +323,7 @@ static void OVERLAY_outline_grease_pencil(OVERLAY_PrivateData *pd, Scene *scene,
IndexMaskMemory memory; IndexMaskMemory memory;
const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes( const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes(
*ob, info.drawing, memory); *ob, info.drawing, memory);
const Array<IndexMask> groups = info.drawing.get_shapes_index_masks(memory); const Vector<IndexMask> groups = info.drawing.get_shapes_index_masks(memory);
const Span<Vector<uint3>> triangles = info.drawing.triangles(); const Span<Vector<uint3>> triangles = info.drawing.triangles();

View File

@ -1194,7 +1194,7 @@ static void grease_pencil_geom_batch_ensure(Object &object,
GPU_indexbuf_add_tri_verts(&ibo, v_mat + 2, v_mat + 1, v_mat + 3); GPU_indexbuf_add_tri_verts(&ibo, v_mat + 2, v_mat + 1, v_mat + 3);
}; };
const Array<IndexMask> groups = info.drawing.get_shapes_index_masks(memory); const Vector<IndexMask> groups = info.drawing.get_shapes_index_masks(memory);
const Array<int> point_to_curve_map = curves.point_to_curve_map(); const Array<int> point_to_curve_map = curves.point_to_curve_map();
auto point_to_id = [&](uint32_t p) { auto point_to_id = [&](uint32_t p) {