GPv3: Python: Add curve_offsets API

This adds the `curve_offsets` collection property.
The curve offsets can be used to get the points that belong
to a curve. They are the offset indices of the first point of
each curve. The first offset is always zero and the last offset
is the total number of points in the drawing.
This commit is contained in:
Falk David
2024-07-27 00:02:55 +02:00
parent edcc438f5f
commit f256b9daf7

View File

@@ -27,6 +27,7 @@
# include <fmt/format.h>
# include "BKE_attribute.hh"
# include "BKE_curves.hh"
# include "BKE_grease_pencil.hh"
# include "BLI_math_matrix.hh"
@@ -76,6 +77,38 @@ static int rna_Drawing_user_count_get(PointerRNA *ptr)
return drawing->wrap().user_count();
}
static int rna_GreasePencilDrawing_curve_offset_data_length(PointerRNA *ptr)
{
const GreasePencilDrawing *drawing = static_cast<GreasePencilDrawing *>(ptr->data);
return drawing->geometry.curve_num + 1;
}
static void rna_GreasePencilDrawing_curve_offset_data_begin(CollectionPropertyIterator *iter,
PointerRNA *ptr)
{
GreasePencilDrawing *drawing = static_cast<GreasePencilDrawing *>(ptr->data);
rna_iterator_array_begin(iter,
drawing->geometry.wrap().offsets_for_write().data(),
sizeof(int),
drawing->geometry.curve_num + 1,
false,
nullptr);
}
static bool rna_GreasePencilDrawing_curve_offset_data_lookup_int(PointerRNA *ptr,
int index,
PointerRNA *r_ptr)
{
GreasePencilDrawing *drawing = static_cast<GreasePencilDrawing *>(ptr->data);
if (index < 0 || index >= drawing->geometry.curve_num + 1) {
return false;
}
r_ptr->owner_id = ptr->owner_id;
r_ptr->type = &RNA_IntAttributeValue;
r_ptr->data = &drawing->geometry.wrap().offsets_for_write()[index];
return true;
}
static void rna_GreasePencilLayer_frames_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
using namespace blender::bke::greasepencil;
@@ -467,6 +500,23 @@ static void rna_def_grease_pencil_drawing(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "User Count", "The number of keyframes this drawing is used by");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_grease_pencil_update");
/* Curve offsets. */
prop = RNA_def_property(srna, "curve_offsets", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "IntAttributeValue");
RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE);
RNA_def_property_collection_funcs(prop,
"rna_GreasePencilDrawing_curve_offset_data_begin",
"rna_iterator_array_next",
"rna_iterator_array_end",
"rna_iterator_array_get",
"rna_GreasePencilDrawing_curve_offset_data_length",
"rna_GreasePencilDrawing_curve_offset_data_lookup_int",
nullptr,
nullptr);
RNA_def_parameter_clear_flags(prop, PROP_EDITABLE, ParameterFlag(0));
RNA_def_property_ui_text(prop, "Curve Offsets", "Offset indices of the first point of each curve");
RNA_def_property_update(prop, 0, "rna_grease_pencil_update");
RNA_api_grease_pencil_drawing(srna);
/* Attributes. */