GPv3: UI and RNA for layer blending mode #110179
|
@ -594,7 +594,7 @@ Layer::Layer()
|
|||
this->frames_storage.values = nullptr;
|
||||
this->frames_storage.flag = 0;
|
||||
|
||||
this->blend_mode = GP_LAYER_BLEND_NONE;
|
||||
// this->blend_mode = GP_LAYER_BLEND_NONE;
|
||||
this->opacity = 1.0f;
|
||||
|
||||
BLI_listbase_clear(&this->masks);
|
||||
|
@ -615,7 +615,7 @@ Layer::Layer(const Layer &other) : Layer()
|
|||
|
||||
/* Note: We do not duplicate the frame storage since it is only needed for writing. */
|
||||
|
||||
this->blend_mode = other.blend_mode;
|
||||
// this->blend_mode = other.blend_mode;
|
||||
this->opacity = other.opacity;
|
||||
|
||||
this->runtime->frames_ = other.runtime->frames_;
|
||||
|
|
|
@ -41,7 +41,7 @@ class LayerModule {
|
|||
gp_layer.tint = float4(1.0f, 1.0f, 1.0f, 0.0f);
|
||||
gp_layer.stroke_index_offset = 0.0f;
|
||||
|
||||
gp_layer.blend_mode = layer.blend_mode;
|
||||
// gp_layer.blend_mode = layer.blend_mode;
|
||||
gp_layer.opacity = layer.opacity;
|
||||
|
||||
if (layer.opacity != 1.0f) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "DEG_depsgraph.hh"
|
||||
|
||||
#include "ED_curves.hh"
|
||||
#include "ED_grease_pencil.hh"
|
||||
|
||||
#include "RNA_access.hh"
|
||||
|
@ -36,6 +37,17 @@ void select_layer_channel(GreasePencil &grease_pencil, bke::greasepencil::Layer
|
|||
}
|
||||
}
|
||||
|
||||
static int get_active_layer_index(const GreasePencil &grease_pencil)
|
||||
{
|
||||
for (const int layer_index : grease_pencil.layers().index_range()) {
|
||||
if (grease_pencil.is_layer_active(grease_pencil.layers()[layer_index])) {
|
||||
return layer_index;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int grease_pencil_layer_add_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
using namespace blender::bke::greasepencil;
|
||||
|
@ -60,6 +72,25 @@ static int grease_pencil_layer_add_exec(bContext *C, wmOperator *op)
|
|||
grease_pencil.insert_blank_frame(new_layer, scene->r.cfra, 0, BEZT_KEYTYPE_KEYFRAME);
|
||||
}
|
||||
|
||||
const int active_index = get_active_layer_index(grease_pencil);
|
||||
|
||||
bke::MutableAttributeAccessor attributes = grease_pencil.attributes_for_write();
|
||||
|
||||
/* Initialize the rest of the attributes with default values. */
|
||||
Set<std::string> attributes_to_skip{{"Name"}};
|
||||
attributes.for_all(
|
||||
[&](const bke::AttributeIDRef &id, const bke::AttributeMetaData /*meta_data*/) {
|
||||
if (attributes_to_skip.contains(id.name())) {
|
||||
return true;
|
||||
}
|
||||
bke::GSpanAttributeWriter attribute = attributes.lookup_for_write_span(id);
|
||||
const CPPType &type = attribute.span.type();
|
||||
GMutableSpan new_data = attribute.span.slice(IndexRange(active_index, 1));
|
||||
type.fill_assign_n(type.default_value(), new_data.data(), new_data.size());
|
||||
attribute.finish();
|
||||
return true;
|
||||
});
|
||||
|
||||
MEM_SAFE_FREE(new_layer_name);
|
||||
|
||||
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
|
||||
|
|
|
@ -29,12 +29,15 @@ static const EnumPropertyItem rna_enum_layer_blend_modes_items[] = {
|
|||
|
||||
#ifdef RNA_RUNTIME
|
||||
|
||||
# include "BKE_attribute.hh"
|
||||
# include "BKE_grease_pencil.hh"
|
||||
|
||||
# include "BLI_span.hh"
|
||||
|
||||
# include "DEG_depsgraph.hh"
|
||||
|
||||
//# include "WM_api.hh"
|
||||
|
||||
static GreasePencil *rna_grease_pencil(const PointerRNA *ptr)
|
||||
{
|
||||
return reinterpret_cast<GreasePencil *>(ptr->owner_id);
|
||||
|
@ -182,6 +185,48 @@ static int rna_iterator_grease_pencil_layer_groups_length(PointerRNA *ptr)
|
|||
return grease_pencil->layer_groups().size();
|
||||
}
|
||||
|
||||
static int get_active_layer_index(const GreasePencil &grease_pencil)
|
||||
{
|
||||
for (const int layer_index : grease_pencil.layers().index_range()) {
|
||||
if (grease_pencil.is_layer_active(grease_pencil.layers()[layer_index])) {
|
||||
return layer_index;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rna_GreasePencilLayer_blend_mode_get(PointerRNA *ptr)
|
||||
{
|
||||
using namespace blender;
|
||||
GreasePencil &grease_pencil = *rna_grease_pencil(ptr);
|
||||
|
||||
const int active_index = get_active_layer_index(grease_pencil);
|
||||
|
||||
bke::MutableAttributeAccessor attributes = grease_pencil.attributes_for_write();
|
||||
|
||||
const VArray<int> blend_mode = *attributes.lookup_or_default<int>(
|
||||
"blend_mode", ATTR_DOMAIN_LAYER, int(GP_LAYER_BLEND_NONE));
|
||||
|
||||
return blend_mode[active_index];
|
||||
}
|
||||
|
||||
static void rna_GreasePencilLayer_blend_mode_set(PointerRNA *ptr, int value)
|
||||
{
|
||||
using namespace blender;
|
||||
GreasePencil &grease_pencil = *rna_grease_pencil(ptr);
|
||||
bke::MutableAttributeAccessor attributes = grease_pencil.attributes_for_write();
|
||||
|
||||
const int active_index = get_active_layer_index(grease_pencil);
|
||||
|
||||
bke::SpanAttributeWriter<int> blend_mode = attributes.lookup_or_add_for_write_span<int>(
|
||||
"blend_mode", ATTR_DOMAIN_LAYER);
|
||||
blend_mode.span[active_index] = value;
|
||||
blend_mode.finish();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void rna_def_grease_pencil_layer(BlenderRNA *brna)
|
||||
|
@ -231,8 +276,19 @@ static void rna_def_grease_pencil_layer(BlenderRNA *brna)
|
|||
prop = RNA_def_property(srna, "blend_mode", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, nullptr, "blend_mode");
|
||||
RNA_def_property_enum_items(prop, rna_enum_layer_blend_modes_items);
|
||||
RNA_def_property_enum_funcs(prop,
|
||||
"rna_GreasePencilLayer_blend_mode_get",
|
||||
"rna_GreasePencilLayer_blend_mode_set",
|
||||
nullptr);
|
||||
/*
|
||||
RNA_def_property_enum_funcs(prop,
|
||||
"rna_GreasePencilLayer_blend_mode_get",
|
||||
"rna_GreasePencilLayer_blend_mode_set",
|
||||
"rna_GreasePencilLayer_blend_mode_itemf");
|
||||
*/
|
||||
RNA_def_property_ui_text(prop, "Blend Mode", "Blend mode");
|
||||
|
||||
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_grease_pencil_update");
|
||||
|
||||
/* Onion Skinning. */
|
||||
prop = RNA_def_property(srna, "use_onion_skinning", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(
|
||||
|
|
Loading…
Reference in New Issue