Fix: GPv3: Strokes with hidden materials are editable

Makes it so that strokes and fills of hidden materials are not editable.

Note: this does not make strokes of hidden materials invisible.

Pull Request: https://projects.blender.org/blender/blender/pulls/115777
This commit is contained in:
casey bianco-davis
2023-12-06 10:37:49 +01:00
committed by Falk David
parent 94defad5f1
commit 773d5745e8
@@ -301,14 +301,16 @@ Array<DrawingInfo> retrieve_visible_drawings(const Scene &scene, const GreasePen
return visible_drawings.as_span();
}
static VectorSet<int> get_locked_material_indices(Object &object)
static VectorSet<int> get_editable_material_indices(Object &object)
{
BLI_assert(object.type == OB_GREASE_PENCIL);
VectorSet<int> locked_material_indices;
for (const int mat_i : IndexRange(object.totcol)) {
Material *material = BKE_object_material_get(&object, mat_i + 1);
/* The editable materials are unlocked and not hidden. */
if (material != nullptr && material->gp_style != nullptr &&
(material->gp_style->flag & GP_MATERIAL_LOCKED) != 0)
(material->gp_style->flag & GP_MATERIAL_LOCKED) == 0 &&
(material->gp_style->flag & GP_MATERIAL_HIDE) == 0)
{
locked_material_indices.add(mat_i);
}
@@ -322,8 +324,8 @@ IndexMask retrieve_editable_strokes(Object &object,
{
using namespace blender;
/* Get all the locked material indices */
VectorSet<int> locked_material_indices = get_locked_material_indices(object);
/* Get all the editable material indices */
VectorSet<int> editable_material_indices = get_editable_material_indices(object);
const bke::CurvesGeometry &curves = drawing.strokes();
const IndexRange curves_range = drawing.strokes().curves_range();
@@ -335,7 +337,7 @@ IndexMask retrieve_editable_strokes(Object &object,
return IndexMask::from_predicate(
curves_range, GrainSize(4096), memory, [&](const int64_t curve_i) {
const int material_index = materials[curve_i];
return !locked_material_indices.contains(material_index);
return editable_material_indices.contains(material_index);
});
}
@@ -343,8 +345,8 @@ IndexMask retrieve_editable_points(Object &object,
const bke::greasepencil::Drawing &drawing,
IndexMaskMemory &memory)
{
/* Get all the locked material indices */
VectorSet<int> locked_material_indices = get_locked_material_indices(object);
/* Get all the editable material indices */
VectorSet<int> editable_material_indices = get_editable_material_indices(object);
const bke::CurvesGeometry &curves = drawing.strokes();
const IndexRange points_range = drawing.strokes().points_range();
@@ -357,7 +359,7 @@ IndexMask retrieve_editable_points(Object &object,
return IndexMask::from_predicate(
points_range, GrainSize(4096), memory, [&](const int64_t point_i) {
const int material_index = materials[point_i];
return !locked_material_indices.contains(material_index);
return editable_material_indices.contains(material_index);
});
}
@@ -381,9 +383,6 @@ IndexMask retrieve_editable_and_selected_strokes(Object &object,
{
using namespace blender;
/* Get all the locked material indices */
VectorSet<int> locked_material_indices = get_locked_material_indices(object);
const bke::CurvesGeometry &curves = drawing.strokes();
const IndexRange curves_range = drawing.strokes().curves_range();
@@ -403,9 +402,6 @@ IndexMask retrieve_editable_and_selected_points(Object &object,
const bke::greasepencil::Drawing &drawing,
IndexMaskMemory &memory)
{
/* Get all the locked material indices */
VectorSet<int> locked_material_indices = get_locked_material_indices(object);
const bke::CurvesGeometry &curves = drawing.strokes();
const IndexRange points_range = drawing.strokes().points_range();