| #1916 | GPv3 and Curves API Familiarization Notes
|
| #1917 | So you want to do some operations to the GP3/Curves data, here's a typical function that a
GP3 operator would call:
static int grease_pencil_do_whatever(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
Object *object = CTX_data_active_object(C);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
How to get "drawings" for us to edit under GPv3 and iterate over each "drawing":
const Array<MutableDrawingInfo> drawings = retrieve_editable_drawings(*scene, grease_pencil);
threading::parallel_for_each(drawings, [&](const MutableDrawingInfo &info) {
IndexMaskMemory memory;
const IndexMask strokes = ed::greasepencil::retrieve_editable_and_selected_strokes(
*object, info.drawing, memory);
if (strokes.is_empty()) {
return;
}
Get a curves container to work on inside this drawing... By using &curves it allows us to later just directly assign a new one. So this way we could create new curves easier.
Essentially we don't "edit" the curve, but creates a new one, and there are utility functions in Curves to allow easy transferring of old data.
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
And choose to work with "Select Domain"... (Like whether you select strokes or points)
const bke::AttrDomain selection_domain = ED_grease_pencil_selection_domain_get(
scene->toolsettings);
if (selection_domain == bke::AttrDomain::Curve) {
curves.remove_curves(elements, {});
}
else if (selection_domain == bke::AttrDomain::Point) {
curves = remove_points_and_split(curves, elements);
}
// Curves etc...
Array<bool> points_to_delete(curves.points_num()); // 1d array
const int total_points = points_to_delete.as_span().count(false);
This is how we iterate over curves...
for (const int curve_i : curves.curves_range()) {
const IndexRange points = points_by_curve[curve_i];
const Span<bool> curve_points_to_delete = points_to_delete.as_span().slice(points);
const bool curve_cyclic = src_cyclic[curve_i];
//...
}
}); // End parallel iteration over stroke.
Create a new curves "container", this is where we actually create new stuff and then we put in data... If we have counts for individual curves, counts can be accumulated into new offsets with convenience functions.
bke::CurvesGeometry dst_curves(total_points, total_curves);
MutableSpan<int> new_curve_offsets = dst_curves.offsets_for_write();
array_utils::copy(dst_curve_counts.as_span(), new_curve_offsets.drop_back(1));
offset_indices::accumulate_counts_to_offsets(new_curve_offsets);
bke::MutableAttributeAccessor dst_attributes = dst_curves.attributes_for_write();
const bke::AttributeAccessor src_attributes = curves.attributes();
Copy from dst-src matching pairs if data is modified from previous curves.
/* Transfer curve attributes. */
gather_attributes(
src_attributes, bke::AttrDomain::Curve, {}, {"cyclic"}, dst_to_src_curve, dst_attributes);
array_utils::copy(dst_cyclic.as_span(), dst_curves.cyclic_for_write());
}
Other points
- Individual elements delivered by
Span and Array etc can all be accessed with []. So MutableSpan some=other; some[index]=thing; is (should be?) valid.
info.drawings.radii is different from radius attribute under Curves . GP3 uses radii .
|
| #1918 | Need Clarification
How is GP3 modifier gonna be integrated, where to start? Will it be put alongside a generic modifier for easier management and code path?
- Answer: Will be included into the main modifier folder, will have special flags indicating modifier being available to GP3.
In the case of subdiv, should this become a generic curve function or just for GP3? (there is now, but doesn't support selected portion)
Which parts currently are safe to touch/add/modify? Doesn't seem to be anything there needs to be modified.
- Why there's
blender::bke::greasepencil::Layer and ::GreasePencilFrame ?
- Should we keep old DNA and RNA in place?
|
| #1920 | Array to VArray conversion
Use
Array<int> cuts_array(curves.curve_num,cuts);
VArray<int> vcuts=VArray<int>::ForContainer(std::move(cuts_array));
Or
VArray<int>::ForSpan(cuts_array.as_span())
|
| #1927 | Missing GPencil 3.0 API
- BKE_gpencil_frame_active_set
|
| #1932 | Some notes
GP3 Draw while sculpting? |