Initial Grease Pencil 3.0 stage #106848

Merged
Falk David merged 224 commits from filedescriptor/blender:grease-pencil-v3 into main 2023-05-30 11:14:22 +02:00
2 changed files with 7 additions and 10 deletions
Showing only changes of commit 1861d9716b - Show all commits

View File

@ -538,7 +538,7 @@ void LayerGroup::foreach_children_pre_order(TreeNodeIterFn function)
void LayerGroup::foreach_children_with_index_pre_order(TreeNodeIndexIterFn function)
{
Vector<TreeNode *> children = this->children_in_pre_order();
for (const int64_t i : IndexRange(children.size())) {
for (const int64_t i : children.index_range()) {
function(i, *children[i]);
}
}
@ -1069,15 +1069,15 @@ blender::MutableSpan<GreasePencilDrawingBase *> GreasePencil::drawings_for_write
this->drawing_array_size};
}
void GreasePencil::add_empty_drawings(int n)
void GreasePencil::add_empty_drawings(const int add_size)
{
using namespace blender;
BLI_assert(n > 0);
BLI_assert(add_size > 0);
const int prev_size = this->drawings().size();

int n -> const int add_size

`int n` -> `const int add_size`
grow_array<GreasePencilDrawingBase *>(&this->drawing_array, &this->drawing_array_size, add_size);
MutableSpan<GreasePencilDrawingBase *> new_drawings = this->drawings_for_write().drop_front(
prev_size);
for (const int i : IndexRange(new_drawings.size())) {
for (const int i : new_drawings.index_range()) {
new_drawings[i] = reinterpret_cast<GreasePencilDrawingBase *>(
MEM_new<GreasePencilDrawing>(__func__));
new_drawings[i]->user_count = 0;
@ -1087,7 +1087,7 @@ void GreasePencil::add_empty_drawings(int n)
}
}
void GreasePencil::remove_drawing(int index_to_remove)
void GreasePencil::remove_drawing(const int index_to_remove)
{
using namespace blender::bke::greasepencil;
/* In order to not change the indices of the drawings, we do the following to the drawing to be
@ -1226,10 +1226,7 @@ void GreasePencil::read_drawing_array(BlendDataReader *reader)
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(drawing_base);
drawing->geometry.wrap().blend_read(*reader);
/* Initialize runtime data. */
drawing->geometry.runtime = MEM_new<blender::bke::CurvesGeometryRuntime>(__func__);
drawing->geometry.wrap().update_curve_types();
drawing->runtime = MEM_new<blender::bke::GreasePencilDrawingRuntime>(__func__);
drawing->runtime->triangles_cache.tag_dirty();
break;
}
case GP_DRAWING_REFERENCE: {
@ -1277,7 +1274,7 @@ void GreasePencil::free_drawing_array()
drawing->geometry.wrap().~CurvesGeometry();
MEM_delete(drawing->runtime);
drawing->runtime = nullptr;
MEM_freeN(drawing);
MEM_delete(drawing);
break;
}
case GP_DRAWING_REFERENCE: {

View File

@ -448,7 +448,7 @@ typedef struct GreasePencil {
#ifdef __cplusplus
blender::Span<GreasePencilDrawingBase *> drawings() const;

It probably shouldn't be possible to get a span of non-const pointers from a const GreasePencil:

Span<const GreasePencilDrawingBase *>

It probably shouldn't be possible to get a span of non-const pointers from a const `GreasePencil`: `Span<const GreasePencilDrawingBase *>`
blender::MutableSpan<GreasePencilDrawingBase *> drawings_for_write();
void add_empty_drawings(int n);
void add_empty_drawings(int add_size);
void remove_drawing(int index);

This sort of API function (dealing with one index at a time) can be a bit dangerous since it can easily lead to quadratic behavior if it's called many times. I wonder if a remove_drawings(IndexMask drawings_to_remove) function would work a bit better

This sort of API function (dealing with one index at a time) can be a bit dangerous since it can easily lead to quadratic behavior if it's called many times. I wonder if a `remove_drawings(IndexMask drawings_to_remove)` function would work a bit better
void foreach_visible_drawing(int frame,
blender::FunctionRef<void(GreasePencilDrawing &)> function);