GPv3: Change "use_locked_material" option

This option is meant to ignore any material locking when it
comes to editing strokes that might use locked materials.

There were some issues with the current implementation.
* The name did not reflect what it was supposed to do, so it
   was renamed to `ignore_locked_materials`.
* The description of the option has been updated to better
   reflect the behavior.
* Some util functions have been refactored

Pull Request: https://projects.blender.org/blender/blender/pulls/127423
This commit is contained in:
Falk David
2024-09-12 14:20:16 +02:00
committed by Falk David
parent 3417934eff
commit c07c9d5729
5 changed files with 31 additions and 27 deletions

View File

@@ -197,7 +197,7 @@ class GREASE_PENCIL_MT_grease_pencil_add_layer_extra(Menu):
layout.prop(grease_pencil, "use_autolock_layers", text="Autolock Inactive Layers")
if layer:
layout.prop(layer, "use_locked_material")
layout.prop(layer, "ignore_locked_materials")
layout.separator()
layout.operator("grease_pencil.layer_duplicate_object", text="Copy Layer to Selected").only_active = True

View File

@@ -198,7 +198,7 @@ class Layer;
void set_selected(bool selected); \
bool use_onion_skinning() const; \
bool use_masks() const; \
bool use_locked_material() const; \
bool ignore_locked_materials() const; \
bool is_child_of(const LayerGroup &group) const;
/* Implements the forwarding of the methods defined by #TREENODE_COMMON_METHODS. */
@@ -247,9 +247,9 @@ class Layer;
{ \
return this->as_node().use_masks(); \
} \
inline bool class_name::use_locked_material() const \
inline bool class_name::ignore_locked_materials() const \
{ \
return this->as_node().use_locked_material(); \
return this->as_node().ignore_locked_materials(); \
} \
inline bool class_name::is_child_of(const LayerGroup &group) const \
{ \
@@ -802,9 +802,9 @@ inline bool TreeNode::use_masks() const
return ((this->flag & GP_LAYER_TREE_NODE_HIDE_MASKS) == 0) &&
(!this->parent_group() || this->parent_group()->as_node().use_masks());
}
inline bool TreeNode::use_locked_material() const
inline bool TreeNode::ignore_locked_materials() const
{
return (this->flag & GP_LAYER_TREE_NODE_USE_LOCKED_MATERIAL) != 0;
return (this->flag & GP_LAYER_TREE_NODE_IGNORE_LOCKED_MATERIALS) != 0;
}
inline bool TreeNode::is_child_of(const LayerGroup &group) const
{

View File

@@ -900,12 +900,20 @@ IndexMask retrieve_editable_strokes(Object &object,
{
using namespace blender;
const bke::CurvesGeometry &curves = drawing.strokes();
const IndexRange curves_range = drawing.strokes().curves_range();
const IndexRange curves_range = curves.curves_range();
if (object.totcol == 0) {
return IndexMask(curves_range);
}
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object.data);
const bke::greasepencil::Layer &layer = *grease_pencil.layers()[layer_index];
/* If we're not using material locking, the entire curves range is editable. */
if (layer.ignore_locked_materials()) {
return IndexMask(curves_range);
}
/* Get all the editable material indices */
VectorSet<int> editable_material_indices = get_editable_material_indices(object);
if (editable_material_indices.is_empty()) {
@@ -913,9 +921,6 @@ IndexMask retrieve_editable_strokes(Object &object,
}
const bke::AttributeAccessor attributes = curves.attributes();
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object.data);
const bke::greasepencil::Layer &layer = *grease_pencil.layers()[layer_index];
const VArray<int> materials = *attributes.lookup<int>("material_index", bke::AttrDomain::Curve);
if (!materials) {
/* If the attribute does not exist then the default is the first material. */
@@ -927,10 +932,7 @@ IndexMask retrieve_editable_strokes(Object &object,
/* Get all the strokes that have their material unlocked. */
return IndexMask::from_predicate(
curves_range, GrainSize(4096), memory, [&](const int64_t curve_i) {
const int material_index = materials[curve_i];
/* The stroke is editable if the material is editable. If the material is not editable,
* then the stroke is only editable if the layer disables the locked material option. */
return editable_material_indices.contains(material_index) || layer.use_locked_material();
return editable_material_indices.contains(materials[curve_i]);
});
}
@@ -1009,23 +1011,28 @@ IndexMask retrieve_editable_points(Object &object,
IndexMaskMemory &memory)
{
const bke::CurvesGeometry &curves = drawing.strokes();
const IndexRange points_range = drawing.strokes().points_range();
const IndexRange points_range = curves.points_range();
if (object.totcol == 0) {
return IndexMask(points_range);
}
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object.data);
const bke::greasepencil::Layer &layer = *grease_pencil.layers()[layer_index];
/* If we're not using material locking, the entire points range is editable. */
if (layer.ignore_locked_materials()) {
return IndexMask(points_range);
}
/* Get all the editable material indices */
VectorSet<int> editable_material_indices = get_editable_material_indices(object);
if (editable_material_indices.is_empty()) {
return {};
}
const bke::AttributeAccessor attributes = curves.attributes();
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object.data);
const bke::greasepencil::Layer &layer = *grease_pencil.layers()[layer_index];
/* Propagate the material index to the points. */
const bke::AttributeAccessor attributes = curves.attributes();
const VArray<int> materials = *attributes.lookup<int>("material_index", bke::AttrDomain::Point);
if (!materials) {
/* If the attribute does not exist then the default is the first material. */
@@ -1037,10 +1044,7 @@ IndexMask retrieve_editable_points(Object &object,
/* Get all the points that are part of a stroke with an unlocked material. */
return IndexMask::from_predicate(
points_range, GrainSize(4096), memory, [&](const int64_t point_i) {
const int material_index = materials[point_i];
/* The stroke is editable if the material is editable. If the material is not editable,
* then the stroke is only editable if the layer disables the locked material option. */
return editable_material_indices.contains(material_index) || layer.use_locked_material();
return editable_material_indices.contains(materials[point_i]);
});
}

View File

@@ -241,7 +241,7 @@ typedef enum GreasePencilLayerTreeNodeFlag {
GP_LAYER_TREE_NODE_EXPANDED = (1 << 6),
GP_LAYER_TREE_NODE_HIDE_MASKS = (1 << 7),
GP_LAYER_TREE_NODE_DISABLE_MASKS_IN_VIEWLAYER = (1 << 8),
GP_LAYER_TREE_NODE_USE_LOCKED_MATERIAL = (1 << 9),
GP_LAYER_TREE_NODE_IGNORE_LOCKED_MATERIALS = (1 << 9),
} GreasePencilLayerTreeNodeFlag;
struct GreasePencilLayerTreeGroup;

View File

@@ -849,12 +849,12 @@ static void rna_def_grease_pencil_layer(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Blend Mode", "Blend mode");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_grease_pencil_update");
prop = RNA_def_property(srna, "use_locked_material", PROP_BOOLEAN, PROP_NONE);
prop = RNA_def_property(srna, "ignore_locked_materials", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(
prop, "GreasePencilLayerTreeNode", "flag", GP_LAYER_TREE_NODE_USE_LOCKED_MATERIAL);
prop, "GreasePencilLayerTreeNode", "flag", GP_LAYER_TREE_NODE_IGNORE_LOCKED_MATERIALS);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_ui_text(
prop, "Use Locked Materials Editing", "Allow editing locked materials in the layer");
prop, "Ignore Material Locking", "Allow editing strokes even if they use locked materials");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, nullptr);
/* Local transformation matrix. */
prop = RNA_def_property(srna, "matrix_local", PROP_FLOAT, PROP_MATRIX);