Grease Pencil: Add layer channel color property

This adds a `channel_color` property to layers.
The color is stored in the tree nodes.
It's currently used by the dopesheet for the channel colors.

Resolves #130370.

Pull Request: https://projects.blender.org/blender/blender/pulls/130512
This commit is contained in:
Pratik Borhade
2024-12-09 14:11:29 +01:00
committed by Falk David
parent b6e1afb6e1
commit 03b2fc744e
6 changed files with 51 additions and 6 deletions

View File

@@ -146,6 +146,19 @@ class GreasePencil_LayerRelationsPanel:
col.prop(layer, "use_viewlayer_masks")
class GreasePencil_LayerDisplayPanel:
bl_label = "Display"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
grease_pencil = context.grease_pencil
layer = grease_pencil.layers.active
layout.prop(layer, "channel_color", text="Channel Color")
class GREASE_PENCIL_MT_layer_mask_add(Menu):
bl_label = "Add Mask"
@@ -315,6 +328,12 @@ class DATA_PT_grease_pencil_layer_relations(LayerDataButtonsPanel, GreasePencil_
bl_options = {'DEFAULT_CLOSED'}
class DATA_PT_grease_pencil_layer_display(LayerDataButtonsPanel, GreasePencil_LayerDisplayPanel, Panel):
bl_label = "Display"
bl_parent_id = "DATA_PT_grease_pencil_layers"
bl_options = {'DEFAULT_CLOSED'}
class DATA_PT_grease_pencil_onion_skinning(DataButtonsPanel, Panel):
bl_label = "Onion Skinning"
@@ -473,6 +492,7 @@ classes = (
DATA_PT_grease_pencil_layer_transform,
DATA_PT_grease_pencil_layer_adjustments,
DATA_PT_grease_pencil_layer_relations,
DATA_PT_grease_pencil_layer_display,
DATA_PT_grease_pencil_onion_skinning,
DATA_PT_grease_pencil_onion_skinning_custom_colors,
DATA_PT_grease_pencil_onion_skinning_display,

View File

@@ -14,6 +14,7 @@ from bl_ui.properties_data_grease_pencil import (
GreasePencil_LayerTransformPanel,
GreasePencil_LayerRelationsPanel,
GreasePencil_LayerAdjustmentsPanel,
GreasePencil_LayerDisplayPanel,
)
from rna_prop_ui import PropertyPanel
@@ -965,6 +966,15 @@ class DOPESHEET_PT_grease_pencil_layer_adjustments(
bl_options = {'DEFAULT_CLOSED'}
class DOPESHEET_PT_grease_pencil_layer_display(
GreasePencilLayersDopeSheetPanel,
GreasePencil_LayerDisplayPanel,
Panel):
bl_label = "Display"
bl_parent_id = "DOPESHEET_PT_grease_pencil_mode"
bl_options = {'DEFAULT_CLOSED'}
classes = (
DOPESHEET_HT_header,
DOPESHEET_PT_proportional_edit,
@@ -992,6 +1002,7 @@ classes = (
DOPESHEET_PT_grease_pencil_layer_transform,
DOPESHEET_PT_grease_pencil_layer_adjustments,
DOPESHEET_PT_grease_pencil_layer_relations,
DOPESHEET_PT_grease_pencil_layer_display,
)
if __name__ == "__main__": # only for live edit.

View File

@@ -959,7 +959,7 @@ TreeNode::TreeNode(const TreeNode &other) : TreeNode(GreasePencilLayerTreeNodeTy
{
this->GreasePencilLayerTreeNode::name = BLI_strdup_null(other.GreasePencilLayerTreeNode::name);
this->flag = other.flag;
copy_v3_v3_uchar(this->color, other.color);
copy_v3_v3(this->color, other.color);
}
TreeNode::~TreeNode()
@@ -1946,7 +1946,7 @@ void BKE_grease_pencil_copy_layer_parameters(const blender::bke::greasepencil::L
{
using namespace blender::bke::greasepencil;
dst.as_node().flag = src.as_node().flag;
copy_v3_v3_uchar(dst.as_node().color, src.as_node().color);
copy_v3_v3(dst.as_node().color, src.as_node().color);
dst.blend_mode = src.blend_mode;
dst.opacity = src.opacity;
@@ -1973,7 +1973,7 @@ void BKE_grease_pencil_copy_layer_group_parameters(
{
using namespace blender::bke::greasepencil;
dst.as_node().flag = src.as_node().flag;
copy_v3_v3_uchar(dst.as_node().color, src.as_node().color);
copy_v3_v3(dst.as_node().color, src.as_node().color);
dst.color_tag = src.color_tag;
}

View File

@@ -3903,6 +3903,14 @@ static void *layer_setting_ptr(bAnimListElem *ale,
return GET_ACF_FLAG_PTR(layer->base.flag, r_type);
}
static bool layer_channel_color(const bAnimListElem *ale, uint8_t r_color[3])
{
using namespace bke::greasepencil;
GreasePencilLayerTreeNode &layer = *static_cast<GreasePencilLayerTreeNode *>(ale->data);
rgb_float_to_uchar(r_color, layer.color);
return true;
}
static int layer_group_icon(bAnimListElem *ale)
{
using namespace bke::greasepencil;
@@ -3985,7 +3993,7 @@ static bAnimChannelType ACF_GPL = {
/*channel_role*/ ACHANNEL_ROLE_CHANNEL,
/*get_backdrop_color*/ acf_generic_channel_color,
/*get_channel_color*/ nullptr,
/*get_channel_color*/ greasepencil::layer_channel_color,
/*draw_backdrop*/ acf_generic_channel_backdrop,
/*get_indent_level*/ acf_generic_indentation_flexible,
/*get_offset*/ greasepencil::layer_offset,

View File

@@ -259,10 +259,11 @@ typedef struct GreasePencilLayerTreeNode {
* Indicates the type of struct this element is.
*/
int8_t type;
char _pad[7];
/**
* Color tag.
* Channel color for dopesheet.
*/
uint8_t color[3];
float color[3];
/**
* Flag. Used to set e.g. the selection, visibility, ... status.
* See `GreasePencilLayerTreeNodeFlag`.

View File

@@ -1097,6 +1097,11 @@ static void rna_def_grease_pencil_layer(BlenderRNA *brna)
RNA_def_property_ui_text(
prop, "Parent Layer Group", "The parent layer group this layer is part of");
prop = RNA_def_property(srna, "channel_color", PROP_FLOAT, PROP_COLOR);
RNA_def_property_float_sdna(prop, "GreasePencilLayerTreeNode", "color");
RNA_def_property_array(prop, 3);
RNA_def_property_update(prop, NC_GPENCIL | NA_EDITED, nullptr);
RNA_api_grease_pencil_layer(srna);
}