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
3 changed files with 48 additions and 13 deletions
Showing only changes of commit 93f1282d12 - Show all commits

View File

@ -23,7 +23,8 @@ class LayerGroup;
class Layer;
filedescriptor marked this conversation as resolved Outdated

Decide on the namespace here. Should it maybe be just gp?

Decide on the namespace here. Should it maybe be just `gp`?
class TreeNode : public ::GreasePencilLayerTreeNode {
using ItemIterFn = FunctionRef<void(TreeNode &)>;
using TreeNodeIterFn = FunctionRef<void(TreeNode &)>;
using LayerIterFn = FunctionRef<void(Layer &)>;
protected:
Vector<std::unique_ptr<TreeNode>> children_;
@ -160,22 +161,22 @@ class TreeNode : public ::GreasePencilLayerTreeNode {
return PreOrderRange(this);
}

Put out of line.

Put out of line.
void foreach_children_pre_order(ItemIterFn function)
void foreach_children_pre_order(TreeNodeIterFn function)
{
for (auto &child : children_) {

The function is "is_locked" and the comment says "return if it is locked". This sort of comment doesn't add anything IMO, just wastes space. If there is a comment, maybe it should use a different word besides "locked" to describe the state. Or there doesn't need to be a comment at all.

The function is "is_locked" and the comment says "return if it is locked". This sort of comment doesn't add anything IMO, just wastes space. If there is a comment, maybe it should use a different word besides "locked" to describe the state. Or there doesn't need to be a comment at all.
child->foreach_children_pre_order_recursive_(function);
}
}
void foreach_leaf_pre_order(ItemIterFn function)
void foreach_layer_pre_order(LayerIterFn function)
{
for (auto &child : children_) {
child->foreach_leaf_pre_order_recursive_(function);
child->foreach_layer_pre_order_recursive_(function);
}
}
private:
void foreach_children_pre_order_recursive_(ItemIterFn function)
void foreach_children_pre_order_recursive_(TreeNodeIterFn function)
{
function(*this);
for (auto &child : children_) {
@ -183,13 +184,13 @@ class TreeNode : public ::GreasePencilLayerTreeNode {
}
}
void foreach_leaf_pre_order_recursive_(ItemIterFn function)
void foreach_layer_pre_order_recursive_(LayerIterFn function)
{
if (children_.size() == 0) {
function(*this);
if (this->is_layer()) {
function(this->as_layer());
}
for (auto &child : children_) {
child->foreach_children_pre_order_recursive_(function);
child->foreach_layer_pre_order_recursive_(function);
filedescriptor marked this conversation as resolved Outdated

Would be good to know why this is commented out, or it should be cleaned up before merge in main.

Would be good to know why this is commented out, or it should be cleaned up before merge in main.
}
}
};
@ -249,6 +250,11 @@ class Layer : public TreeNode, ::GreasePencilLayer {
return this != &other;
}
const Map<int, int> &frames()
{
return frames_;
}
bool insert_frame(int frame_number, int index)
{
return frames_.add(frame_number, index);

View File

@ -299,7 +299,26 @@ Layer &TreeNode::as_layer()
} // namespace blender::bke::gpencil
// Span<GreasePencilDrawingOrReference> blender::bke::GreasePencil::drawings() const
// {
// return Span<GreasePencilDrawingOrReference>{this->drawing_array, this->drawing_array_size};
// }
blender::Span<GreasePencilDrawingOrReference *> GreasePencil::drawings() const
{
return blender::Span<GreasePencilDrawingOrReference *>{this->drawing_array,
filedescriptor marked this conversation as resolved Outdated

Make sure to not overwrite min and max but account any value already present. E.g. use math::min_max(...).

Make sure to not overwrite `min` and `max` but account any value already present. E.g. use `math::min_max(...)`.
this->drawing_array_size};
}
void GreasePencil::foreach_visible_drawing(
int frame,
blender::FunctionRef<void(GreasePencilDrawing &, blender::bke::gpencil::Layer &)> function)
{
blender::Span<GreasePencilDrawingOrReference *> drawings = this->drawings();
this->runtime->root_group().foreach_layer_pre_order([&](blender::bke::gpencil::Layer &layer) {
if (layer.frames().contains(frame)) {
int index = layer.frames().lookup(frame);
GreasePencilDrawingOrReference *drawing_or_reference = drawings[index];
if (drawing_or_reference->type == GREASE_PENCIL_DRAWING) {
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(
drawing_or_reference);
function(*drawing, layer);
}
}
});
}

View File

@ -10,10 +10,14 @@
#include "DNA_curves_types.h"
#ifdef __cplusplus
# include "BLI_function_ref.hh"
# include "BLI_map.hh"
# include "BLI_span.hh"
namespace blender::bke {
class GreasePencilRuntime;
namespace gpencil {
class Layer;
}
} // namespace blender::bke
using GreasePencilRuntimeHandle = blender::bke::GreasePencilRuntime;
#else
@ -153,6 +157,12 @@ typedef struct GreasePencil {
int drawing_array_size;
char _pad[4];
#ifdef __cplusplus
blender::Span<GreasePencilDrawingOrReference *> drawings() const;
void foreach_visible_drawing(
int frame,
blender::FunctionRef<void(GreasePencilDrawing &, blender::bke::gpencil::Layer &)> function);
#endif
/* Only used for storage in the .blend file. */
GreasePencilLayerTreeStorage layer_tree_storage;