GPv3: UI and RNA for layer blending mode #110179
|
@ -594,7 +594,6 @@ Layer::Layer()
|
|||
this->frames_storage.values = nullptr;
|
||||
this->frames_storage.flag = 0;
|
||||
|
||||
// this->blend_mode = GP_LAYER_BLEND_NONE;
|
||||
this->opacity = 1.0f;
|
||||
|
||||
BLI_listbase_clear(&this->masks);
|
||||
|
@ -615,7 +614,6 @@ 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->opacity = other.opacity;
|
||||
|
||||
this->runtime->frames_ = other.runtime->frames_;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "BKE_attribute.hh"
|
||||
#include "BKE_grease_pencil.hh"
|
||||
#include "DRW_gpu_wrapper.hh"
|
||||
#include "DRW_render.h"
|
||||
|
@ -30,9 +31,7 @@ class LayerModule {
|
|||
layers_buf_.clear();
|
||||
}
|
||||
|
||||
void sync(const Object * /*object*/,
|
||||
const bke::greasepencil::Layer &layer,
|
||||
bool &do_layer_blending)
|
||||
void sync(const Object *object, const bke::greasepencil::Layer &layer, bool &do_layer_blending)
|
||||
{
|
||||
/* TODO(fclem): All of this is placeholder. */
|
||||
gpLayer gp_layer;
|
||||
|
@ -41,14 +40,21 @@ 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.opacity = layer.opacity;
|
||||
const GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
|
||||
|
||||
if (layer.opacity != 1.0f) {
|
||||
const int64_t layer_index = grease_pencil.layers().first_index(&layer);
|
||||
const bke::AttributeAccessor attributes = grease_pencil.attributes();
|
||||
|
||||
const VArray<int> blend_mode = *attributes.lookup_or_default<int>(
|
||||
"blend_mode", ATTR_DOMAIN_LAYER, GP_LAYER_BLEND_NONE);
|
||||
|
||||
gp_layer.blend_mode = blend_mode[layer_index];
|
||||
if (gp_layer.blend_mode != GP_LAYER_BLEND_NONE) {
|
||||
do_layer_blending = true;
|
||||
}
|
||||
|
||||
if (layer.blend_mode != GP_LAYER_BLEND_NONE) {
|
||||
gp_layer.opacity = layer.opacity;
|
||||
if (gp_layer.opacity != 1.0f) {
|
||||
do_layer_blending = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,17 +37,6 @@ 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;
|
||||
|
@ -59,20 +48,19 @@ static int grease_pencil_layer_add_exec(bContext *C, wmOperator *op)
|
|||
char *new_layer_name = RNA_string_get_alloc(
|
||||
op->ptr, "new_layer_name", nullptr, 0, &new_layer_name_length);
|
||||
|
||||
Layer &new_layer = grease_pencil.add_layer(new_layer_name);
|
||||
if (grease_pencil.has_active_layer()) {
|
||||
Layer &new_layer = grease_pencil.add_layer(new_layer_name);
|
||||
grease_pencil.move_node_after(new_layer.as_node(),
|
||||
grease_pencil.get_active_layer_for_write()->as_node());
|
||||
grease_pencil.set_active_layer(&new_layer);
|
||||
grease_pencil.insert_blank_frame(new_layer, scene->r.cfra, 0, BEZT_KEYTYPE_KEYFRAME);
|
||||
}
|
||||
else {
|
||||
Layer &new_layer = grease_pencil.add_layer(new_layer_name);
|
||||
grease_pencil.set_active_layer(&new_layer);
|
||||
grease_pencil.insert_blank_frame(new_layer, scene->r.cfra, 0, BEZT_KEYTYPE_KEYFRAME);
|
||||
}
|
||||
|
||||
const int active_index = get_active_layer_index(grease_pencil);
|
||||
const int64_t layer_index = grease_pencil.layers().first_index(&new_layer);
|
||||
|
||||
bke::MutableAttributeAccessor attributes = grease_pencil.attributes_for_write();
|
||||
|
||||
|
@ -85,7 +73,7 @@ static int grease_pencil_layer_add_exec(bContext *C, wmOperator *op)
|
|||
}
|
||||
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));
|
||||
GMutableSpan new_data = attribute.span.slice(IndexRange(layer_index, 1));
|
||||
type.fill_assign_n(type.default_value(), new_data.data(), new_data.size());
|
||||
attribute.finish();
|
||||
return true;
|
||||
|
|
|
@ -36,8 +36,6 @@ static const EnumPropertyItem rna_enum_layer_blend_modes_items[] = {
|
|||
|
||||
# include "DEG_depsgraph.hh"
|
||||
|
||||
//# include "WM_api.hh"
|
||||
|
||||
static GreasePencil *rna_grease_pencil(const PointerRNA *ptr)
|
||||
{
|
||||
return reinterpret_cast<GreasePencil *>(ptr->owner_id);
|
||||
|
@ -185,30 +183,18 @@ 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 int64_t layer_index = grease_pencil.layers().first_index(grease_pencil.get_active_layer());
|
||||
|
||||
const bke::AttributeAccessor attributes = grease_pencil.attributes();
|
||||
const VArray<int> blend_mode = *attributes.lookup_or_default<int>(
|
||||
"blend_mode", ATTR_DOMAIN_LAYER, int(GP_LAYER_BLEND_NONE));
|
||||
"blend_mode", ATTR_DOMAIN_LAYER, GP_LAYER_BLEND_NONE);
|
||||
|
||||
return blend_mode[active_index];
|
||||
return blend_mode[layer_index];
|
||||
}
|
||||
|
||||
static void rna_GreasePencilLayer_blend_mode_set(PointerRNA *ptr, int value)
|
||||
|
@ -217,11 +203,11 @@ static void rna_GreasePencilLayer_blend_mode_set(PointerRNA *ptr, int value)
|
|||
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);
|
||||
const int64_t layer_index = grease_pencil.layers().first_index(grease_pencil.get_active_layer());
|
||||
|
||||
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.span[layer_index] = value;
|
||||
blend_mode.finish();
|
||||
|
||||
return;
|
||||
|
@ -280,12 +266,6 @@ static void rna_def_grease_pencil_layer(BlenderRNA *brna)
|
|||
"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");
|
||||
|
||||
|
|
Loading…
Reference in New Issue