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 20 additions and 29 deletions
Showing only changes of commit 9b2fb10049 - Show all commits

View File

@ -39,7 +39,7 @@ class TreeNode : public ::GreasePencilLayerTreeNode, NonMovable {
virtual ~TreeNode();
private:
std::unique_ptr<LayerGroup> parent_ = nullptr;
LayerGroup *parent_ = nullptr;
Vector<std::unique_ptr<TreeNode>> children_;
public:

View File

@ -472,7 +472,7 @@ LayerGroup::LayerGroup(const LayerGroup &other) : TreeNode(other)
else if (elem.get()->is_layer()) {
this->children_.append(std::make_unique<Layer>(elem.get()->as_layer()));
}
this->children_.last().get()->parent_.reset(this);
this->children_.last().get()->parent_ = this;
}
this->tag_children_cache_dirty();
}
@ -480,29 +480,29 @@ LayerGroup::LayerGroup(const LayerGroup &other) : TreeNode(other)
void LayerGroup::add_group(LayerGroup &group)
{
this->children_.append(std::make_unique<LayerGroup>(group));
this->children_.last().get()->parent_.reset(this);
this->children_.last().get()->parent_ = this;
this->tag_children_cache_dirty();
}
void LayerGroup::add_group(LayerGroup &&group)
{
this->children_.append(std::make_unique<LayerGroup>(group));
this->children_.last().get()->parent_.reset(this);
this->children_.last().get()->parent_ = this;
this->tag_children_cache_dirty();
}
Layer &LayerGroup::add_layer(Layer &layer)
{
children_.append(std::make_unique<Layer>(layer));
this->children_.last().get()->parent_.reset(this);
this->children_.append(std::make_unique<Layer>(layer));
this->children_.last().get()->parent_ = this;
this->tag_children_cache_dirty();
return children_.last().get()->as_layer_for_write();
}
Layer &LayerGroup::add_layer(Layer &&layer)
{
children_.append(std::make_unique<Layer>(std::move(layer)));
this->children_.last().get()->parent_.reset(this);
this->children_.append(std::make_unique<Layer>(std::move(layer)));
this->children_.last().get()->parent_ = this;
this->tag_children_cache_dirty();
return children_.last().get()->as_layer_for_write();
}
@ -580,19 +580,15 @@ void LayerGroup::ensure_children_cache() const
this->children_cache_.clear_and_shrink();
this->layer_cache_.clear_and_shrink();
Stack<TreeNode *> stack;
for (auto it = this->children_.rbegin(); it != this->children_.rend(); it++) {
stack.push((*it).get());
}
while (!stack.is_empty()) {
TreeNode *next_node = stack.pop();
for (auto &it : this->children_) {
TreeNode *next_node = it.get();
this->children_cache_.append(next_node);
if (next_node->is_layer()) {
this->layer_cache_.append(&next_node->as_layer_for_write());
}
else if (next_node->is_group()) {
for (auto it = next_node->children_.rbegin(); it != next_node->children_.rend(); it++) {
stack.push((*it).get());
for (TreeNode *node : next_node->as_group_for_write().children_for_write()) {
this->children_cache_.append(node);
}
}
}
@ -603,7 +599,7 @@ void LayerGroup::tag_children_cache_dirty() const
{
this->children_cache_mutex_.tag_dirty();
if (this->parent_) {
this->parent_.get()->tag_children_cache_dirty();
this->parent_->tag_children_cache_dirty();
}
}

View File

@ -67,8 +67,6 @@ TEST(greasepencil, save_layer_tree_to_storage)
grease_pencil.runtime = MEM_new<blender::bke::GreasePencilRuntime>(__func__);
grease_pencil.load_layer_tree_from_storage();
grease_pencil.print_layer_tree();
Span<const TreeNode *> children = grease_pencil.root_group().children();
for (const int i : children.index_range()) {
const TreeNode &child = *children[i];
@ -151,17 +149,14 @@ TEST(greasepencil, remove_drawing)
static int expected_frames_size[] = {2, 0};
static int expected_frames_pairs_layer0[][2] = {{0, 0}, {20, 1}};
Span<const Layer *> layers = grease_pencil.layers();
for (const int layer_i : IndexRange(layers.size())) {
const Layer &layer = *layers[layer_i];
EXPECT_EQ(layer.frames().size(), expected_frames_size[layer_i]);
if (layer_i == 0) {
for (const int i : IndexRange(2)) {
EXPECT_EQ(layer.frames().lookup(expected_frames_pairs_layer0[i][0]).drawing_index,
expected_frames_pairs_layer0[i][1]);
}
}
}
EXPECT_EQ(layers[0]->frames().size(), expected_frames_size[0]);
EXPECT_EQ(layers[1]->frames().size(), expected_frames_size[1]);
EXPECT_EQ(layers[0]->frames().lookup(expected_frames_pairs_layer0[0][0]).drawing_index,
expected_frames_pairs_layer0[0][1]);
EXPECT_EQ(layers[0]->frames().lookup(expected_frames_pairs_layer0[1][0]).drawing_index,
expected_frames_pairs_layer0[1][1]);
}
/* --------------------------------------------------------------------------------------------- */