GPv3: Add layer 'pass_index' attribute.

Add this data as a layer attribute. It's usage was already implemented
by the modifier filtering generic code, but data itself did not yet
exist in GPv3 data.

Also add RNA accessors and handle it in conversion code.

Pull Request: https://projects.blender.org/blender/blender/pulls/118495
This commit is contained in:
Bastien Montagne
2024-02-22 14:53:48 +01:00
committed by Bastien Montagne
parent e3b9ccc7b2
commit f15f57c5ea
4 changed files with 56 additions and 1 deletions

View File

@@ -143,6 +143,11 @@ class DATA_PT_grease_pencil_layer_relations(LayerDataButtonsPanel, Panel):
row = layout.row(align=True)
row.prop_search(layer, "parent_bone", layer.parent.data, "bones", text="Bone")
layout.separator()
col = layout.row(align=True)
col.prop(layer, "pass_index")
classes = (
DATA_PT_context_grease_pencil,

View File

@@ -458,6 +458,18 @@ void legacy_gpencil_to_grease_pencil(Main &bmain, GreasePencil &grease_pencil, b
/* TODO: Update drawing user counts. */
}
/* Second loop, to write to layer attributes after all layers were created. */
MutableAttributeAccessor layer_attributes = grease_pencil.attributes_for_write();
SpanAttributeWriter<int> layer_passes = layer_attributes.lookup_or_add_for_write_span<int>(
"pass_index", bke::AttrDomain::Layer);
layer_idx = 0;
LISTBASE_FOREACH_INDEX (bGPDlayer *, gpl, &gpd.layers, layer_idx) {
layer_passes.span[layer_idx] = int(gpl->pass_index);
}
layer_passes.finish();
/* Copy vertex group names and settings. */
BKE_defgroup_copy_list(&grease_pencil.vertex_group_names, &gpd.vertex_group_names);
grease_pencil.vertex_group_active_index = gpd.vertex_group_active_index;

View File

@@ -22,6 +22,7 @@
# include <fmt/format.h>
# include "BKE_attribute.hh"
# include "BKE_grease_pencil.hh"
# include "BLI_span.hh"
@@ -135,6 +136,34 @@ static void rna_GreasePencilLayer_name_set(PointerRNA *ptr, const char *value)
grease_pencil->rename_node(layer->wrap().as_node(), value);
}
static int rna_GreasePencilLayer_pass_index_get(PointerRNA *ptr)
{
using namespace blender;
const GreasePencil &grease_pencil = *rna_grease_pencil(ptr);
const bke::greasepencil::Layer &layer =
static_cast<const GreasePencilLayer *>(ptr->data)->wrap();
const int layer_idx = *grease_pencil.get_layer_index(layer);
const VArray layer_passes = *grease_pencil.attributes().lookup_or_default<int>(
"pass_index", bke::AttrDomain::Layer, 0);
return layer_passes[layer_idx];
}
static void rna_GreasePencilLayer_pass_index_set(PointerRNA *ptr, int value)
{
using namespace blender;
GreasePencil &grease_pencil = *rna_grease_pencil(ptr);
const bke::greasepencil::Layer &layer =
static_cast<const GreasePencilLayer *>(ptr->data)->wrap();
const int layer_idx = *grease_pencil.get_layer_index(layer);
bke::SpanAttributeWriter<int> layer_passes =
grease_pencil.attributes_for_write().lookup_or_add_for_write_span<int>(
"pass_index", bke::AttrDomain::Layer);
layer_passes.span[layer_idx] = std::max(0, value);
layer_passes.finish();
}
static PointerRNA rna_GreasePencil_active_layer_get(PointerRNA *ptr)
{
GreasePencil *grease_pencil = rna_grease_pencil(ptr);
@@ -253,6 +282,15 @@ static void rna_def_grease_pencil_layer(BlenderRNA *brna)
prop, "Onion Skinning", "Display onion skins before and after the current frame");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_grease_pencil_update");
/* pass index for compositing and modifiers */
prop = RNA_def_property(srna, "pass_index", PROP_INT, PROP_UNSIGNED);
RNA_def_property_ui_text(prop, "Pass Index", "Index number for the \"Layer Index\" pass");
RNA_def_property_int_funcs(prop,
"rna_GreasePencilLayer_pass_index_get",
"rna_GreasePencilLayer_pass_index_set",
nullptr);
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_grease_pencil_update");
prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Object");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);

View File

@@ -204,7 +204,7 @@ static IndexMask get_filtered_layer_mask(const GreasePencil &grease_pencil,
bke::AttributeAccessor layer_attributes = grease_pencil.attributes();
const Span<const Layer *> layers = grease_pencil.layers();
const VArray<int> layer_passes =
layer_attributes.lookup_or_default<int>("pass", bke::AttrDomain::Layer, 0).varray;
layer_attributes.lookup_or_default<int>("pass_index", bke::AttrDomain::Layer, 0).varray;
IndexMask result = IndexMask::from_predicate(
full_mask, GrainSize(4096), memory, [&](const int64_t layer_i) {