GPv3: Refactor root_group to be a pointer in DNA #110007
|
@ -523,6 +523,15 @@ inline const blender::bke::greasepencil::LayerGroup &GreasePencilLayerTreeGroup:
|
|||
return *reinterpret_cast<const blender::bke::greasepencil::LayerGroup *>(this);
|
||||
}
|
||||
|
||||
inline const blender::bke::greasepencil::LayerGroup &GreasePencil::root_group() const
|
||||
{
|
||||
return this->root_group_ptr->wrap();
|
||||
}
|
||||
inline blender::bke::greasepencil::LayerGroup &GreasePencil::root_group()
|
||||
{
|
||||
return this->root_group_ptr->wrap();
|
||||
}
|
||||
|
||||
inline bool GreasePencil::has_active_layer() const
|
||||
{
|
||||
return (this->active_layer != nullptr);
|
||||
|
|
|
@ -54,7 +54,7 @@ static void grease_pencil_init_data(ID *id)
|
|||
GreasePencil *grease_pencil = reinterpret_cast<GreasePencil *>(id);
|
||||
grease_pencil->runtime = MEM_new<GreasePencilRuntime>(__func__);
|
||||
|
||||
new (&grease_pencil->root_group) greasepencil::LayerGroup();
|
||||
grease_pencil->root_group_ptr = MEM_new<greasepencil::LayerGroup>(__func__);
|
||||
grease_pencil->active_layer = nullptr;
|
||||
grease_pencil->flag |= GREASE_PENCIL_ANIM_CHANNEL_EXPANDED;
|
||||
}
|
||||
|
@ -99,8 +99,8 @@ static void grease_pencil_copy_data(Main * /*bmain*/,
|
|||
}
|
||||
|
||||
/* Duplicate layer tree. */
|
||||
new (&grease_pencil_dst->root_group)
|
||||
bke::greasepencil::LayerGroup(grease_pencil_src->root_group.wrap());
|
||||
grease_pencil_dst->root_group_ptr = MEM_new<bke::greasepencil::LayerGroup>(
|
||||
__func__, grease_pencil_src->root_group());
|
||||
|
||||
/* Set active layer. */
|
||||
if (grease_pencil_src->has_active_layer()) {
|
||||
|
@ -120,7 +120,7 @@ static void grease_pencil_free_data(ID *id)
|
|||
MEM_SAFE_FREE(grease_pencil->material_array);
|
||||
|
||||
grease_pencil->free_drawing_array();
|
||||
grease_pencil->root_group.wrap().~LayerGroup();
|
||||
MEM_delete(&grease_pencil->root_group());
|
||||
|
||||
BKE_grease_pencil_batch_cache_free(grease_pencil);
|
||||
|
||||
|
@ -179,8 +179,6 @@ static void grease_pencil_blend_read_data(BlendDataReader *reader, ID *id)
|
|||
grease_pencil->read_drawing_array(reader);
|
||||
/* Read layer tree. */
|
||||
grease_pencil->read_layer_tree(reader);
|
||||
/* Read active layer. */
|
||||
BLO_read_data_address(reader, reinterpret_cast<void **>(&grease_pencil->active_layer));
|
||||
|
||||
/* Read materials. */
|
||||
BLO_read_pointer_array(reader, reinterpret_cast<void **>(&grease_pencil->material_array));
|
||||
|
@ -1411,31 +1409,31 @@ std::optional<blender::Bounds<blender::float3>> GreasePencil::bounds_min_max() c
|
|||
blender::Span<const blender::bke::greasepencil::TreeNode *> GreasePencil::nodes() const
|
||||
{
|
||||
BLI_assert(this->runtime != nullptr);
|
||||
return this->root_group.wrap().nodes();
|
||||
return this->root_group().nodes();
|
||||
}
|
||||
|
||||
blender::Span<const blender::bke::greasepencil::Layer *> GreasePencil::layers() const
|
||||
{
|
||||
BLI_assert(this->runtime != nullptr);
|
||||
return this->root_group.wrap().layers();
|
||||
return this->root_group().layers();
|
||||
}
|
||||
|
||||
blender::Span<blender::bke::greasepencil::Layer *> GreasePencil::layers_for_write()
|
||||
{
|
||||
BLI_assert(this->runtime != nullptr);
|
||||
return this->root_group.wrap().layers_for_write();
|
||||
return this->root_group().layers_for_write();
|
||||
}
|
||||
|
||||
blender::Span<const blender::bke::greasepencil::LayerGroup *> GreasePencil::groups() const
|
||||
{
|
||||
BLI_assert(this->runtime != nullptr);
|
||||
return this->root_group.wrap().groups();
|
||||
return this->root_group().groups();
|
||||
}
|
||||
|
||||
blender::Span<blender::bke::greasepencil::LayerGroup *> GreasePencil::groups_for_write()
|
||||
{
|
||||
BLI_assert(this->runtime != nullptr);
|
||||
return this->root_group.wrap().groups_for_write();
|
||||
return this->root_group().groups_for_write();
|
||||
}
|
||||
|
||||
const blender::bke::greasepencil::Layer *GreasePencil::get_active_layer() const
|
||||
|
@ -1511,7 +1509,7 @@ blender::bke::greasepencil::Layer &GreasePencil::add_layer_after(
|
|||
|
||||
blender::bke::greasepencil::Layer &GreasePencil::add_layer(const blender::StringRefNull name)
|
||||
{
|
||||
return this->add_layer(this->root_group.wrap(), name);
|
||||
return this->add_layer(this->root_group(), name);
|
||||
}
|
||||
|
||||
blender::bke::greasepencil::LayerGroup &GreasePencil::add_layer_group(
|
||||
|
@ -1539,31 +1537,31 @@ blender::bke::greasepencil::LayerGroup &GreasePencil::add_layer_group_after(
|
|||
blender::bke::greasepencil::LayerGroup &GreasePencil::add_layer_group(
|
||||
const blender::StringRefNull name)
|
||||
{
|
||||
return this->add_layer_group(this->root_group.wrap(), name);
|
||||
return this->add_layer_group(this->root_group(), name);
|
||||
}
|
||||
|
||||
const blender::bke::greasepencil::Layer *GreasePencil::find_layer_by_name(
|
||||
const blender::StringRefNull name) const
|
||||
{
|
||||
return this->root_group.wrap().find_layer_by_name(name);
|
||||
return this->root_group().find_layer_by_name(name);
|
||||
}
|
||||
|
||||
blender::bke::greasepencil::Layer *GreasePencil::find_layer_by_name(
|
||||
const blender::StringRefNull name)
|
||||
{
|
||||
return this->root_group.wrap().find_layer_by_name(name);
|
||||
return this->root_group().find_layer_by_name(name);
|
||||
}
|
||||
|
||||
const blender::bke::greasepencil::LayerGroup *GreasePencil::find_group_by_name(
|
||||
blender::StringRefNull name) const
|
||||
{
|
||||
return this->root_group.wrap().find_group_by_name(name);
|
||||
return this->root_group().find_group_by_name(name);
|
||||
}
|
||||
|
||||
blender::bke::greasepencil::LayerGroup *GreasePencil::find_group_by_name(
|
||||
blender::StringRefNull name)
|
||||
{
|
||||
return this->root_group.wrap().find_group_by_name(name);
|
||||
return this->root_group().find_group_by_name(name);
|
||||
}
|
||||
|
||||
void GreasePencil::rename_layer(blender::bke::greasepencil::Layer &layer,
|
||||
|
@ -1631,7 +1629,7 @@ void GreasePencil::remove_layer(blender::bke::greasepencil::Layer &layer)
|
|||
void GreasePencil::print_layer_tree()
|
||||
{
|
||||
using namespace blender::bke::greasepencil;
|
||||
this->root_group.wrap().print_nodes("Layer Tree:");
|
||||
this->root_group().print_nodes("Layer Tree:");
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
@ -1771,7 +1769,19 @@ static void read_layer_tree_group(BlendDataReader *reader,
|
|||
|
||||
void GreasePencil::read_layer_tree(BlendDataReader *reader)
|
||||
{
|
||||
read_layer_tree_group(reader, &this->root_group, nullptr);
|
||||
/* Read root group. */
|
||||
BLO_read_data_address(reader, &this->root_group_ptr);
|
||||
/* This shouldn't normally happen, but for files that were created before the root group became a
|
||||
* pointer, this address will not exist. In this case, we clear the pointer to the active layer
|
||||
* and create an empty root group to avoid crashes. */
|
||||
if (this->root_group_ptr == nullptr) {
|
||||
this->root_group_ptr = MEM_new<blender::bke::greasepencil::LayerGroup>(__func__);
|
||||
this->active_layer = nullptr;
|
||||
return;
|
||||
}
|
||||
/* Read active layer. */
|
||||
BLO_read_data_address(reader, &this->active_layer);
|
||||
read_layer_tree_group(reader, this->root_group_ptr, nullptr);
|
||||
}
|
||||
|
||||
static void write_layer(BlendWriter *writer, GreasePencilLayer *node)
|
||||
|
@ -1833,7 +1843,7 @@ static void write_layer_tree_group(BlendWriter *writer, GreasePencilLayerTreeGro
|
|||
|
||||
void GreasePencil::write_layer_tree(BlendWriter *writer)
|
||||
{
|
||||
write_layer_tree_group(writer, &this->root_group);
|
||||
write_layer_tree_group(writer, this->root_group_ptr);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
|
|
@ -184,11 +184,10 @@ void legacy_gpencil_to_grease_pencil(Main &bmain, GreasePencil &grease_pencil, b
|
|||
MEM_cnew_array<GreasePencilDrawing *>(num_drawings, __func__));
|
||||
|
||||
int i = 0, layer_idx = 0;
|
||||
LayerGroup &root_group = grease_pencil.root_group.wrap();
|
||||
LISTBASE_FOREACH_INDEX (bGPDlayer *, gpl, &gpd.layers, layer_idx) {
|
||||
/* Create a new layer. */
|
||||
Layer &new_layer = grease_pencil.add_layer(
|
||||
root_group, StringRefNull(gpl->info, BLI_strnlen(gpl->info, 128)));
|
||||
grease_pencil.root_group(), StringRefNull(gpl->info, BLI_strnlen(gpl->info, 128)));
|
||||
|
||||
/* Flags. */
|
||||
SET_FLAG_FROM_TEST(new_layer.base.flag, (gpl->flag & GP_LAYER_HIDE), GP_LAYER_TREE_NODE_HIDE);
|
||||
|
|
|
@ -39,7 +39,7 @@ TEST(greasepencil, create_grease_pencil_id)
|
|||
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(BKE_id_new(ctx.bmain, ID_GP, "GP"));
|
||||
EXPECT_EQ(grease_pencil.drawings().size(), 0);
|
||||
EXPECT_EQ(grease_pencil.root_group.wrap().num_nodes_total(), 0);
|
||||
EXPECT_EQ(grease_pencil.root_group().num_nodes_total(), 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -63,8 +63,8 @@ TEST(greasepencil, remove_drawing)
|
|||
grease_pencil.drawings_for_write()[1]);
|
||||
drawing->geometry.wrap().resize(0, 10);
|
||||
|
||||
Layer &layer1 = grease_pencil.root_group.wrap().add_layer("Layer1");
|
||||
Layer &layer2 = grease_pencil.root_group.wrap().add_layer("Layer2");
|
||||
Layer &layer1 = grease_pencil.root_group().add_layer("Layer1");
|
||||
Layer &layer2 = grease_pencil.root_group().add_layer("Layer2");
|
||||
|
||||
layer1.add_frame(0, 0);
|
||||
layer1.add_frame(10, 1);
|
||||
|
|
|
@ -1199,7 +1199,7 @@ void create_blank(Main &bmain, Object &object, const int frame_number)
|
|||
int material_index = add_material_from_template(bmain, object, gp_stroke_material_black);
|
||||
object.actcol = material_index + 1;
|
||||
|
||||
Layer &new_layer = grease_pencil.add_layer(grease_pencil.root_group.wrap(), "GP_Layer");
|
||||
Layer &new_layer = grease_pencil.add_layer("GP_Layer");
|
||||
grease_pencil.set_active_layer(&new_layer);
|
||||
grease_pencil.insert_blank_frame(new_layer, frame_number, 0, BEZT_KEYTYPE_KEYFRAME);
|
||||
}
|
||||
|
@ -1218,8 +1218,8 @@ void create_stroke(Main &bmain, Object &object, float4x4 matrix, const int frame
|
|||
add_material_from_template(bmain, object, gp_fill_material_grey);
|
||||
object.actcol = material_index + 1;
|
||||
|
||||
Layer &layer_lines = grease_pencil.add_layer(grease_pencil.root_group.wrap(), "Lines");
|
||||
Layer &layer_color = grease_pencil.add_layer(grease_pencil.root_group.wrap(), "Color");
|
||||
Layer &layer_lines = grease_pencil.add_layer("Lines");
|
||||
Layer &layer_color = grease_pencil.add_layer("Color");
|
||||
grease_pencil.set_active_layer(&layer_lines);
|
||||
|
||||
grease_pencil.insert_blank_frame(layer_lines, frame_number, 0, BEZT_KEYTYPE_KEYFRAME);
|
||||
|
@ -1279,8 +1279,8 @@ void create_suzanne(Main &bmain, Object &object, float4x4 matrix, const int fram
|
|||
color_skin_shadow,
|
||||
});
|
||||
|
||||
Layer &layer_fills = grease_pencil.add_layer(grease_pencil.root_group.wrap(), "Fills");
|
||||
Layer &layer_lines = grease_pencil.add_layer(grease_pencil.root_group.wrap(), "Lines");
|
||||
Layer &layer_fills = grease_pencil.add_layer("Fills");
|
||||
Layer &layer_lines = grease_pencil.add_layer("Lines");
|
||||
grease_pencil.set_active_layer(&layer_lines);
|
||||
|
||||
grease_pencil.insert_blank_frame(layer_lines, frame_number, 0, BEZT_KEYTYPE_KEYFRAME);
|
||||
|
|
|
@ -322,7 +322,7 @@ void LayerTreeView::build_tree()
|
|||
{
|
||||
using namespace blender::bke::greasepencil;
|
||||
LISTBASE_FOREACH_BACKWARD (
|
||||
GreasePencilLayerTreeNode *, node, &this->grease_pencil_.root_group.children)
|
||||
GreasePencilLayerTreeNode *, node, &this->grease_pencil_.root_group_ptr->children)
|
||||
{
|
||||
this->build_tree_node_recursive(*this, node->wrap());
|
||||
}
|
||||
|
|
|
@ -400,7 +400,7 @@ typedef struct GreasePencil {
|
|||
char _pad[4];
|
||||
|
||||
/* Root group of the layer tree. */
|
||||
GreasePencilLayerTreeGroup root_group;
|
||||
GreasePencilLayerTreeGroup *root_group_ptr;
|
||||
|
||||
/**
|
||||
* Pointer to the active layer. Can be NULL.
|
||||
|
@ -436,6 +436,10 @@ typedef struct GreasePencil {
|
|||
void read_layer_tree(BlendDataReader *reader);
|
||||
void write_layer_tree(BlendWriter *writer);
|
||||
|
||||
/* Root group. */
|
||||
const blender::bke::greasepencil::LayerGroup &root_group() const;
|
||||
blender::bke::greasepencil::LayerGroup &root_group();
|
||||
|
||||
/* Drawings read/write access. */
|
||||
blender::Span<GreasePencilDrawingBase *> drawings() const;
|
||||
blender::MutableSpan<GreasePencilDrawingBase *> drawings_for_write();
|
||||
|
|
Loading…
Reference in New Issue