Cleanup: GPv3: Return reference from GreasePencil::layer() functions

Since we only assert and never return `nullptr`, it's better to just return a reference.
The access into the span already asserts anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/128025
This commit is contained in:
Falk David
2024-09-23 13:54:02 +02:00
committed by Falk David
parent c07b89b329
commit 3c8d4becc8
52 changed files with 92 additions and 96 deletions

View File

@@ -1000,15 +1000,13 @@ inline GreasePencilDrawingBase *GreasePencil::drawing(const int64_t index)
return this->drawings()[index];
}
inline const blender::bke::greasepencil::Layer *GreasePencil::layer(const int64_t index) const
inline const blender::bke::greasepencil::Layer &GreasePencil::layer(const int64_t index) const
{
BLI_assert(index >= 0 && index < this->layers().size());
return this->layers()[index];
return *this->layers()[index];
}
inline blender::bke::greasepencil::Layer *GreasePencil::layer(const int64_t index)
inline blender::bke::greasepencil::Layer &GreasePencil::layer(const int64_t index)
{
BLI_assert(index >= 0 && index < this->layers().size());
return this->layers_for_write()[index];
return *this->layers_for_write()[index];
}
inline const blender::bke::greasepencil::LayerGroup &GreasePencil::root_group() const

View File

@@ -799,11 +799,10 @@ static GreasePencil *try_load_grease_pencil(const DictionaryValue &io_geometry,
}
for (const int layer_i : IndexRange(layers_num)) {
greasepencil::Layer *layer = grease_pencil->layer(layer_i);
BLI_assert(layer);
layer->opacity = layer_opacities[layer_i];
layer->blend_mode = layer_blend_modes[layer_i];
layer->set_local_transform(layer_transforms[layer_i]);
greasepencil::Layer &layer = grease_pencil->layer(layer_i);
layer.opacity = layer_opacities[layer_i];
layer.blend_mode = layer_blend_modes[layer_i];
layer.set_local_transform(layer_transforms[layer_i]);
}
if (const io::serialize::ArrayValue *io_materials = io_grease_pencil->lookup_array("materials"))

View File

@@ -633,7 +633,7 @@ GeometryDeformation get_evaluated_grease_pencil_drawing_deformation(const Object
const GreasePencil &grease_pencil_orig = *static_cast<const GreasePencil *>(ob_orig.data);
const Span<const bke::greasepencil::Layer *> layers_orig = grease_pencil_orig.layers();
const bke::greasepencil::Layer &layer_orig = *grease_pencil_orig.layer(layer_index);
const bke::greasepencil::Layer &layer_orig = grease_pencil_orig.layer(layer_index);
const bke::greasepencil::Drawing *drawing_orig = grease_pencil_orig.get_drawing_at(layer_orig,
frame);
if (drawing_orig == nullptr) {

View File

@@ -103,7 +103,7 @@ static void remember_deformed_grease_pencil_if_necessary(const GreasePencil *gre
*edit_component.grease_pencil_edit_hints_->drawing_hints;
for (const int layer_index : layers.index_range()) {
const greasepencil::Drawing *drawing = grease_pencil->get_eval_drawing(
*grease_pencil->layer(layer_index));
grease_pencil->layer(layer_index));
const greasepencil::Layer &orig_layer = *orig_layers[layer_index];
const greasepencil::Drawing *orig_drawing = orig_grease_pencil.get_drawing_at(
orig_layer, grease_pencil->runtime->eval_frame);

View File

@@ -43,7 +43,7 @@ GVArray GreasePencilLayerFieldContext::get_varray_for_input(const fn::FieldInput
&field_input))
{
if (const bke::greasepencil::Drawing *drawing = this->grease_pencil().get_eval_drawing(
*this->grease_pencil().layer(this->layer_index())))
this->grease_pencil().layer(this->layer_index())))
{
if (drawing->strokes().attributes().domain_supported(this->domain())) {
const CurvesFieldContext context{drawing->strokes(), this->domain()};
@@ -174,7 +174,7 @@ std::optional<AttributeAccessor> GeometryFieldContext::attributes() const
return grease_pencil->attributes();
}
if (const greasepencil::Drawing *drawing = grease_pencil->get_eval_drawing(
*grease_pencil->layer(grease_pencil_layer_index_)))
grease_pencil->layer(grease_pencil_layer_index_)))
{
return drawing->strokes().attributes();
}
@@ -216,7 +216,7 @@ const greasepencil::Drawing *GeometryFieldContext::grease_pencil_layer_drawing()
return nullptr;
}
return this->grease_pencil()->get_eval_drawing(
*this->grease_pencil()->layer(this->grease_pencil_layer_index_));
this->grease_pencil()->layer(this->grease_pencil_layer_index_));
}
const CurvesGeometry *GeometryFieldContext::curves_or_strokes() const
{
@@ -902,7 +902,7 @@ bool try_capture_fields_on_geometry(GeometryComponent &component,
threading::parallel_for(grease_pencil->layers().index_range(), 8, [&](const IndexRange range) {
for (const int layer_index : range) {
if (greasepencil::Drawing *drawing = grease_pencil->get_eval_drawing(
*grease_pencil->layer(layer_index)))
grease_pencil->layer(layer_index)))
{
const GeometryFieldContext field_context{*grease_pencil, domain, layer_index};
const bool success = try_capture_fields_on_geometry(

View File

@@ -1975,7 +1975,7 @@ int BKE_grease_pencil_stroke_point_count(const GreasePencil &grease_pencil)
int total_points = 0;
for (const int layer_i : grease_pencil.layers().index_range()) {
const bke::greasepencil::Layer &layer = *grease_pencil.layer(layer_i);
const bke::greasepencil::Layer &layer = grease_pencil.layer(layer_i);
const Map<bke::greasepencil::FramesMapKeyT, GreasePencilFrame> frames = layer.frames();
frames.foreach_item(
[&](const bke::greasepencil::FramesMapKeyT /*key*/, const GreasePencilFrame frame) {
@@ -1999,7 +1999,7 @@ void BKE_grease_pencil_point_coords_get(const GreasePencil &grease_pencil,
using namespace blender;
for (const int layer_i : grease_pencil.layers().index_range()) {
const bke::greasepencil::Layer &layer = *grease_pencil.layer(layer_i);
const bke::greasepencil::Layer &layer = grease_pencil.layer(layer_i);
const float4x4 layer_to_object = layer.local_transform();
const Map<bke::greasepencil::FramesMapKeyT, GreasePencilFrame> frames = layer.frames();
frames.foreach_item(
@@ -2029,7 +2029,7 @@ void BKE_grease_pencil_point_coords_apply(GreasePencil &grease_pencil,
using namespace blender;
for (const int layer_i : grease_pencil.layers().index_range()) {
bke::greasepencil::Layer &layer = *grease_pencil.layer(layer_i);
bke::greasepencil::Layer &layer = grease_pencil.layer(layer_i);
const float4x4 layer_to_object = layer.local_transform();
const float4x4 object_to_layer = math::invert(layer_to_object);
const Map<bke::greasepencil::FramesMapKeyT, GreasePencilFrame> frames = layer.frames();
@@ -2062,7 +2062,7 @@ void BKE_grease_pencil_point_coords_apply_with_mat4(GreasePencil &grease_pencil,
const float scalef = mat4_to_scale(mat.ptr());
for (const int layer_i : grease_pencil.layers().index_range()) {
bke::greasepencil::Layer &layer = *grease_pencil.layer(layer_i);
bke::greasepencil::Layer &layer = grease_pencil.layer(layer_i);
const float4x4 layer_to_object = layer.local_transform();
const float4x4 object_to_layer = math::invert(layer_to_object);
const Map<bke::greasepencil::FramesMapKeyT, GreasePencilFrame> frames = layer.frames();

View File

@@ -1119,7 +1119,7 @@ static void grease_pencil_geom_batch_ensure(Object &object,
/* Fill buffers with data. */
for (const int drawing_i : drawings.index_range()) {
const ed::greasepencil::DrawingInfo &info = drawings[drawing_i];
const Layer &layer = *grease_pencil.layer(info.layer_index);
const Layer &layer = grease_pencil.layer(info.layer_index);
const float4x4 layer_space_to_object_space = layer.to_object_space(object);
const float4x4 object_space_to_layer_space = math::invert(layer_space_to_object_space);
const bke::CurvesGeometry &curves = info.drawing.strokes();

View File

@@ -1864,7 +1864,7 @@ static bke::greasepencil::Layer &find_or_create_layer_in_dst_by_name(
using namespace bke::greasepencil;
/* This assumes that the index is valid. Will cause an assert if it is not. */
const Layer &layer_src = *grease_pencil_src.layer(layer_index);
const Layer &layer_src = grease_pencil_src.layer(layer_index);
if (TreeNode *node = grease_pencil_dst.find_node_by_name(layer_src.name())) {
return node->as_layer();
}
@@ -1959,8 +1959,8 @@ static bool grease_pencil_separate_layer(bContext &C,
/* Create a new object for each layer. */
for (const int layer_i : grease_pencil_src.layers().index_range()) {
Layer *layer_src = grease_pencil_src.layer(layer_i);
if (layer_src->is_selected() || layer_src->is_locked()) {
Layer &layer_src = grease_pencil_src.layer(layer_i);
if (layer_src.is_selected() || layer_src.is_locked()) {
continue;
}
@@ -1972,7 +1972,7 @@ static bool grease_pencil_separate_layer(bContext &C,
/* Iterate through all the drawings at current frame. */
const Vector<MutableDrawingInfo> drawings_src = retrieve_editable_drawings_from_layer(
scene, grease_pencil_src, *layer_src);
scene, grease_pencil_src, layer_src);
for (const MutableDrawingInfo &info : drawings_src) {
bke::CurvesGeometry &curves_src = info.drawing.strokes_for_write();
IndexMaskMemory memory;
@@ -2768,7 +2768,7 @@ static int grease_pencil_reproject_exec(bContext *C, wmOperator *op)
return;
}
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
const DrawingPlacement drawing_placement(
scene, *region, *v3d, *object, &layer, mode, offset, view_depths);
@@ -2922,7 +2922,7 @@ static int grease_pencil_snap_to_grid_exec(bContext *C, wmOperator * /*op*/)
IndexMaskMemory memory;
const IndexMask selected_points = ed::curves::retrieve_selected_points(curves, memory);
const Layer &layer = *grease_pencil.layer(drawing_info.layer_index);
const Layer &layer = grease_pencil.layer(drawing_info.layer_index);
const float4x4 layer_to_world = layer.to_world_space(object);
const float4x4 world_to_layer = math::invert(layer_to_world);
@@ -2983,7 +2983,7 @@ static int grease_pencil_snap_to_cursor_exec(bContext *C, wmOperator *op)
const IndexMask selected_points = ed::curves::retrieve_selected_points(curves,
selected_points_memory);
const Layer &layer = *grease_pencil.layer(drawing_info.layer_index);
const Layer &layer = grease_pencil.layer(drawing_info.layer_index);
const float4x4 layer_to_world = layer.to_world_space(object);
const float4x4 world_to_layer = math::invert(layer_to_world);
const float3 cursor_layer = math::transform_point(world_to_layer, cursor_world);
@@ -3073,7 +3073,7 @@ static bool grease_pencil_snap_compute_centroid(const Scene &scene,
const IndexMask selected_points = ed::curves::retrieve_selected_points(curves,
selected_points_memory);
const Layer &layer = *grease_pencil.layer(drawing_info.layer_index);
const Layer &layer = grease_pencil.layer(drawing_info.layer_index);
const float4x4 layer_to_world = layer.to_world_space(object);
Span<float3> positions = curves.positions();

View File

@@ -1361,7 +1361,7 @@ Curves2DBVHTree build_curves_2d_bvh_from_visible(const ViewContext &vc,
continue;
}
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
const float4x4 layer_to_world = layer.to_world_space(object);
const float4x4 projection = ED_view3d_ob_project_mat_get_from_obmat(vc.rv3d, layer_to_world);
const bke::CurvesGeometry &curves = info.drawing.strokes();

View File

@@ -216,7 +216,7 @@ static int grease_pencil_layer_active_exec(bContext *C, wmOperator *op)
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
int layer_index = RNA_int_get(op->ptr, "layer");
Layer &layer = *grease_pencil.layer(layer_index);
Layer &layer = grease_pencil.layer(layer_index);
if (grease_pencil.is_layer_active(&layer)) {
return OPERATOR_CANCELLED;
}

View File

@@ -191,7 +191,7 @@ static int stroke_trim_execute(const bContext *C, const Span<int2> mcoords)
const Vector<ed::greasepencil::MutableDrawingInfo> drawings =
ed::greasepencil::retrieve_editable_drawings(*scene, grease_pencil);
threading::parallel_for_each(drawings, [&](const ed::greasepencil::MutableDrawingInfo &info) {
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
const float4x4 layer_to_world = layer.to_world_space(*ob_eval);
const float4x4 projection = ED_view3d_ob_project_mat_get_from_obmat(rv3d, layer_to_world);
if (execute_trim_on_drawing(info.layer_index,

View File

@@ -376,7 +376,7 @@ static int weight_sample_invoke(bContext *C, wmOperator * /*op*/, const wmEvent
ClosestGreasePencilDrawing new_closest = init;
for (const int i : range) {
DrawingInfo info = drawings[i];
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
/* Skip drawing when it doesn't use the active vertex group. */
const int drawing_defgroup_nr = BLI_findstringindex(

View File

@@ -1138,7 +1138,7 @@ static bool apply_grease_pencil_for_modifier(Depsgraph *depsgraph,
/* Convert the layer map into an index mapping. */
Array<int> eval_to_orig_layer_indices_map(grease_pencil_result.layers().size());
for (const int layer_eval_i : grease_pencil_result.layers().index_range()) {
const Layer *layer_eval = grease_pencil_result.layer(layer_eval_i);
const Layer *layer_eval = &grease_pencil_result.layer(layer_eval_i);
const Layer *layer_orig = eval_to_orig_layer_map.lookup(layer_eval);
const int layer_orig_index = *grease_pencil_orig.get_layer_index(*layer_orig);
eval_to_orig_layer_indices_map[layer_eval_i] = layer_orig_index;

View File

@@ -963,7 +963,7 @@ static int apply_objects_internal(bContext *C,
const float scalef = mat4_to_scale(mat);
for (const int layer_i : grease_pencil.layers().index_range()) {
bke::greasepencil::Layer &layer = *grease_pencil.layer(layer_i);
bke::greasepencil::Layer &layer = grease_pencil.layer(layer_i);
const float4x4 layer_to_object = layer.to_object_space(*ob);
const float4x4 object_to_layer = math::invert(layer_to_object);
const Map<bke::greasepencil::FramesMapKeyT, GreasePencilFrame> frames = layer.frames();
@@ -1775,7 +1775,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
int total_points = 0;
for (const int layer_i : grease_pencil.layers().index_range()) {
const bke::greasepencil::Layer &layer = *grease_pencil.layer(layer_i);
const bke::greasepencil::Layer &layer = grease_pencil.layer(layer_i);
const float4x4 layer_to_object = layer.local_transform();
if (!layer.is_visible()) {
continue;
@@ -1800,7 +1800,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
tot_change++;
for (const int layer_i : grease_pencil.layers().index_range()) {
bke::greasepencil::Layer &layer = *grease_pencil.layer(layer_i);
bke::greasepencil::Layer &layer = grease_pencil.layer(layer_i);
const float4x4 layer_to_object = layer.local_transform();
const float4x4 object_to_layer = math::invert(layer_to_object);
const Map<bke::greasepencil::FramesMapKeyT, GreasePencilFrame> frames = layer.frames();

View File

@@ -734,7 +734,7 @@ static void grease_pencil_fill_extension_cut(const bContext &C,
const OffsetIndices points_by_curve = curves.points_by_curve();
const Span<float3> positions = curves.positions();
const VArray<bool> cyclic = curves.cyclic();
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
const float4x4 layer_to_view = view_matrix * layer.to_world_space(object);
for (const int i_curve : curves.curves_range()) {
@@ -970,7 +970,7 @@ static ed::greasepencil::ExtensionData grease_pencil_fill_get_extension_data(
const OffsetIndices points_by_curve = curves.points_by_curve();
const Span<float3> positions = curves.positions();
const VArray<bool> cyclic = curves.cyclic();
const float4x4 layer_to_world = grease_pencil.layer(info.layer_index)->to_world_space(object);
const float4x4 layer_to_world = grease_pencil.layer(info.layer_index).to_world_space(object);
for (const int i_curve : curves.curves_range()) {
const IndexRange points = points_by_curve[i_curve];
@@ -1082,8 +1082,7 @@ static void grease_pencil_fill_overlay_cb(const bContext *C, ARegion * /*region*
const IndexMask curve_mask = info.drawing.strokes().curves_range();
const VArray<ColorGeometry4f> colors = VArray<ColorGeometry4f>::ForSingle(
stroke_curves_color, info.drawing.strokes().points_num());
const float4x4 layer_to_world =
grease_pencil.layer(info.layer_index)->to_world_space(object);
const float4x4 layer_to_world = grease_pencil.layer(info.layer_index).to_world_space(object);
const bool use_xray = false;
const float radius_scale = 1.0f;

View File

@@ -870,7 +870,7 @@ struct EraseOperationExecutor {
const auto execute_eraser_on_drawing = [&](const int layer_index,
const int frame_number,
Drawing &drawing) {
const Layer &layer = *grease_pencil.layer(layer_index);
const Layer &layer = grease_pencil.layer(layer_index);
const bke::CurvesGeometry &src = drawing.strokes();
/* Evaluated geometry. */

View File

@@ -303,13 +303,13 @@ InterpolateOpData *InterpolateOpData::from_operator(const bContext &C, const wmO
grease_pencil.layers().index_range(),
GrainSize(1024),
data->layer_mask_memory,
[&](const int layer_index) { return grease_pencil.layer(layer_index)->is_editable(); });
[&](const int layer_index) { return grease_pencil.layer(layer_index).is_editable(); });
break;
}
data->layer_data.reinitialize(grease_pencil.layers().size());
data->layer_mask.foreach_index([&](const int layer_index) {
const Layer &layer = *grease_pencil.layer(layer_index);
const Layer &layer = grease_pencil.layer(layer_index);
InterpolateOpData::LayerData &layer_data = data->layer_data[layer_index];
/* Pair from/to curves by index. */
@@ -601,7 +601,7 @@ static void grease_pencil_interpolate_update(bContext &C, const wmOperator &op)
const auto flip_mode = InterpolateFlipMode(RNA_enum_get(op.ptr, "flip"));
opdata.layer_mask.foreach_index([&](const int layer_index) {
Layer &layer = *grease_pencil.layer(layer_index);
Layer &layer = grease_pencil.layer(layer_index);
const InterpolateOpData::LayerData &layer_data = opdata.layer_data[layer_index];
/* Drawings must be created on operator invoke. */
@@ -656,7 +656,7 @@ static void grease_pencil_interpolate_restore(bContext &C, wmOperator &op)
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object.data);
opdata.layer_mask.foreach_index([&](const int layer_index) {
Layer &layer = *grease_pencil.layer(layer_index);
Layer &layer = grease_pencil.layer(layer_index);
const InterpolateOpData::LayerData &layer_data = opdata.layer_data[layer_index];
if (layer_data.orig_curves) {
@@ -692,7 +692,7 @@ static bool grease_pencil_interpolate_init(const bContext &C, wmOperator &op)
/* Create target frames. */
data.layer_mask.foreach_index([&](const int layer_index) {
Layer &layer = *grease_pencil.layer(layer_index);
Layer &layer = grease_pencil.layer(layer_index);
InterpolateOpData::LayerData &layer_data = data.layer_data[layer_index];
ensure_drawing_at_exact_frame(grease_pencil, layer, layer_data, current_frame);
@@ -1113,7 +1113,7 @@ static int grease_pencil_interpolate_sequence_exec(bContext *C, wmOperator *op)
BKE_curvemapping_init(ipo_settings.custom_ipo);
opdata.layer_mask.foreach_index([&](const int layer_index) {
Layer &layer = *grease_pencil.layer(layer_index);
Layer &layer = grease_pencil.layer(layer_index);
InterpolateOpData::LayerData &layer_data = opdata.layer_data[layer_index];
std::optional<FramesMapKeyIntervalT> interval = find_frames_interval(

View File

@@ -207,7 +207,7 @@ GreasePencilStrokeParams GreasePencilStrokeParams::from_context(
Object &ob_eval = *DEG_get_evaluated_object(&depsgraph, &object);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object.data);
const bke::greasepencil::Layer &layer = *grease_pencil.layer(layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(layer_index);
return {*scene.toolsettings,
region,
object,
@@ -411,7 +411,7 @@ void GreasePencilStrokeOperationCommon::foreach_editable_drawing(
std::atomic<bool> changed = false;
const Vector<MutableDrawingInfo> drawings = get_drawings_for_painting(C);
threading::parallel_for_each(drawings, [&](const MutableDrawingInfo &info) {
const Layer &layer = *grease_pencil.layer(info.layer_index);
const Layer &layer = grease_pencil.layer(info.layer_index);
DrawingPlacement placement(scene, region, view3d, object_eval, &layer);
if (placement.use_project_to_surface()) {

View File

@@ -87,7 +87,7 @@ void GrabOperation::foreach_grabbed_drawing(
if (data.point_mask.is_empty()) {
return;
}
const Layer &layer = *grease_pencil.layer(data.layer_index);
const Layer &layer = grease_pencil.layer(data.layer_index);
/* If a new frame is created, could be impossible find the stroke. */
bke::greasepencil::Drawing *drawing = grease_pencil.get_drawing_at(layer, data.frame_number);
if (drawing == nullptr) {
@@ -149,7 +149,7 @@ void GrabOperation::on_stroke_begin(const bContext &C, const InputSample &start_
BLI_assert(info.layer_index >= 0);
PointWeights &data = this->drawing_data[i];
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
BLI_assert(grease_pencil.get_drawing_at(layer, info.frame_number) == &info.drawing);
GreasePencilStrokeParams params = {*scene.toolsettings,

View File

@@ -106,7 +106,7 @@ void TintOperation::on_stroke_begin(const bContext &C, const InputSample & /*sta
const int drawing_index = (&drawing_info - drawings_.data());
bke::CurvesGeometry &strokes = drawing_info.drawing.strokes_for_write();
const Layer &layer = *grease_pencil.layer(drawing_info.layer_index);
const Layer &layer = grease_pencil.layer(drawing_info.layer_index);
screen_positions_per_drawing_[drawing_index].reinitialize(strokes.points_num());

View File

@@ -207,7 +207,7 @@ class WeightPaintOperation : public GreasePencilStrokeOperation {
}
/* Convert stroke points to screen space positions. */
const bke::greasepencil::Layer &layer = *this->grease_pencil->layer(
const bke::greasepencil::Layer &layer = this->grease_pencil->layer(
drawing_info.layer_index);
const float4x4 layer_to_world = layer.to_world_space(*ob_eval);
const float4x4 projection = ED_view3d_ob_project_mat_get_from_obmat(rv3d, layer_to_world);

View File

@@ -469,7 +469,7 @@ std::optional<const bke::AttributeAccessor> GeometryDataSource::get_component_at
}
if (layer_index_ >= 0 && layer_index_ < grease_pencil->layers().size()) {
if (const bke::greasepencil::Drawing *drawing = grease_pencil->get_eval_drawing(
*grease_pencil->layer(layer_index_)))
grease_pencil->layer(layer_index_)))
{
return drawing->strokes().attributes();
}

View File

@@ -392,7 +392,7 @@ class GreasePencilLayerCurvesDomainViewItem : public DataSetViewItem {
uiItemL(&row, label_.c_str(), icon);
const bke::greasepencil::Drawing *drawing = grease_pencil_.get_eval_drawing(
*grease_pencil_.layer(layer_index_));
grease_pencil_.layer(layer_index_));
const int count = drawing ? drawing->strokes().attributes().domain_size(domain_) : 0;
draw_count(*this, count);
}

View File

@@ -1200,7 +1200,7 @@ static bool do_lasso_select_grease_pencil(const ViewContext *vc,
const StringRef attribute_name,
IndexMaskMemory &memory) {
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
const bke::crazyspace::GeometryDeformation deformation =
bke::crazyspace::get_evaluated_grease_pencil_drawing_deformation(
ob_eval, *vc->obedit, info.layer_index, info.frame_number);
@@ -3244,7 +3244,7 @@ static bool ed_grease_pencil_select_pick(bContext *C,
ClosestGreasePencilDrawing new_closest = init;
for (const int i : range) {
ed::greasepencil::MutableDrawingInfo info = drawings[i];
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
/* Get deformation by modifiers. */
bke::crazyspace::GeometryDeformation deformation =
bke::crazyspace::get_evaluated_grease_pencil_drawing_deformation(
@@ -4296,7 +4296,7 @@ static bool do_grease_pencil_box_select(const ViewContext *vc,
const StringRef attribute_name,
IndexMaskMemory &memory) {
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
const bke::crazyspace::GeometryDeformation deformation =
bke::crazyspace::get_evaluated_grease_pencil_drawing_deformation(
ob_eval, *vc->obedit, info.layer_index, info.frame_number);
@@ -5160,7 +5160,7 @@ static bool grease_pencil_circle_select(const ViewContext *vc,
const StringRef attribute_name,
IndexMaskMemory &memory) {
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
const bke::crazyspace::GeometryDeformation deformation =
bke::crazyspace::get_evaluated_grease_pencil_drawing_deformation(
ob_eval, *vc->obedit, info.layer_index, info.frame_number);

View File

@@ -1088,7 +1088,7 @@ bool ED_view3d_minmax_verts(const Scene *scene, Object *obedit, float r_min[3],
bke::crazyspace::get_evaluated_grease_pencil_drawing_deformation(
obedit, ob_orig, info.layer_index, info.frame_number);
const bke::greasepencil::Layer &layer = *grease_pencil.layer(info.layer_index);
const bke::greasepencil::Layer &layer = grease_pencil.layer(info.layer_index);
const float4x4 layer_to_world = layer.to_world_space(*obedit);
grease_pencil_bounds = bounds::merge(

View File

@@ -52,7 +52,7 @@ static void createTransGreasePencilVerts(bContext *C, TransInfo *t)
if (blender::animrig::is_autokey_on(scene)) {
for (const int info_i : drawings.index_range()) {
blender::bke::greasepencil::Layer &target_layer = *grease_pencil.layer(
blender::bke::greasepencil::Layer &target_layer = grease_pencil.layer(
drawings[info_i].layer_index);
const int current_frame = scene->r.cfra;
std::optional<int> start_frame = target_layer.start_frame_at(current_frame);

View File

@@ -144,7 +144,7 @@ static std::optional<GreasePencil *> separate_grease_pencil_layer_selection(
GreasePencil *dst_grease_pencil = BKE_grease_pencil_new_nomain();
BKE_grease_pencil_duplicate_drawing_array(&src_grease_pencil, dst_grease_pencil);
selection.foreach_index([&](const int index) {
const bke::greasepencil::Layer &src_layer = *src_grease_pencil.layer(index);
const bke::greasepencil::Layer &src_layer = src_grease_pencil.layer(index);
dst_grease_pencil->duplicate_layer(src_layer);
});
dst_grease_pencil->remove_drawings_with_no_users();
@@ -241,7 +241,7 @@ void separate_geometry(bke::GeometrySet &geometry_set,
else if (ELEM(domain, AttrDomain::Point, AttrDomain::Curve)) {
GreasePencil &grease_pencil = *geometry_set.get_grease_pencil_for_write();
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -90,7 +90,7 @@ static void translate_greasepencil(GreasePencil &grease_pencil, const float3 tra
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Layer &layer = *grease_pencil.layer(layer_index);
Layer &layer = grease_pencil.layer(layer_index);
float4x4 local_transform = layer.local_transform();
local_transform.location() += translation;
layer.set_local_transform(local_transform);
@@ -101,7 +101,7 @@ static void transform_greasepencil(GreasePencil &grease_pencil, const float4x4 &
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Layer &layer = *grease_pencil.layer(layer_index);
Layer &layer = grease_pencil.layer(layer_index);
float4x4 local_transform = layer.local_transform();
local_transform = transform * local_transform;
layer.set_local_transform(local_transform);

View File

@@ -509,8 +509,8 @@ typedef struct GreasePencil {
/* Layers, layer groups and nodes read/write access. */
blender::Span<const blender::bke::greasepencil::Layer *> layers() const;
blender::Span<blender::bke::greasepencil::Layer *> layers_for_write();
const blender::bke::greasepencil::Layer *layer(int64_t index) const;
blender::bke::greasepencil::Layer *layer(int64_t index);
const blender::bke::greasepencil::Layer &layer(int64_t index) const;
blender::bke::greasepencil::Layer &layer(int64_t index);
blender::Span<const blender::bke::greasepencil::LayerGroup *> layer_groups() const;
blender::Span<blender::bke::greasepencil::LayerGroup *> layer_groups_for_write();

View File

@@ -258,7 +258,7 @@ static void modify_geometry_set(ModifierData *md,
const Vector<LayerDrawingInfo> drawings = modifier::greasepencil::get_drawing_infos_by_layer(
grease_pencil, layer_mask, frame);
threading::parallel_for_each(drawings, [&](const LayerDrawingInfo &info) {
const Layer &layer = *grease_pencil.layer(info.layer_index);
const Layer &layer = grease_pencil.layer(info.layer_index);
const float4x4 viewmat = viewinv * layer.to_world_space(*ctx->object);
modify_drawing(omd, *ctx, *info.drawing, viewmat);
});

View File

@@ -325,7 +325,7 @@ Vector<bke::greasepencil::Drawing *> get_drawings_for_write(GreasePencil &grease
using namespace blender::bke::greasepencil;
VectorSet<Drawing *> drawings;
layer_mask.foreach_index([&](const int64_t layer_i) {
const Layer &layer = *grease_pencil.layer(layer_i);
const Layer &layer = grease_pencil.layer(layer_i);
/* Set of owned drawings, ignore drawing references to other data blocks. */
if (Drawing *drawing = grease_pencil.get_drawing_at(layer, frame)) {
drawings.add(drawing);
@@ -342,7 +342,7 @@ Vector<LayerDrawingInfo> get_drawing_infos_by_layer(GreasePencil &grease_pencil,
Set<Drawing *> drawings;
Vector<LayerDrawingInfo> drawing_infos;
layer_mask.foreach_index([&](const int64_t layer_i) {
const Layer &layer = *grease_pencil.layer(layer_i);
const Layer &layer = grease_pencil.layer(layer_i);
Drawing *drawing = grease_pencil.get_drawing_at(layer, frame);
if (drawing == nullptr) {
return;
@@ -364,7 +364,7 @@ Vector<FrameDrawingInfo> get_drawing_infos_by_frame(GreasePencil &grease_pencil,
Set<Drawing *> drawings;
Vector<FrameDrawingInfo> drawing_infos;
layer_mask.foreach_index([&](const int64_t layer_i) {
const Layer &layer = *grease_pencil.layer(layer_i);
const Layer &layer = grease_pencil.layer(layer_i);
const std::optional<int> start_frame = layer.start_frame_at(frame);
if (!start_frame) {
return;

View File

@@ -215,7 +215,7 @@ static void convex_hull_grease_pencil(GeometrySet &geometry_set)
Array<Mesh *> mesh_by_layer(grease_pencil.layers().size(), nullptr);
for (const int layer_index : grease_pencil.layers().index_range()) {
const Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
const Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -266,7 +266,7 @@ static void curve_fill_calculate(GeometrySet &geometry_set,
const GreasePencil &grease_pencil = *geometry_set.get_grease_pencil();
Vector<Mesh *> mesh_by_layer(grease_pencil.layers().size(), nullptr);
for (const int layer_index : grease_pencil.layers().index_range()) {
const Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
const Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -99,7 +99,7 @@ static void fillet_grease_pencil(GreasePencil &grease_pencil,
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -41,7 +41,7 @@ static void node_geo_exec(GeoNodeExecParams params)
using namespace bke::greasepencil;
const GreasePencil &grease_pencil = *geometry_set.get_grease_pencil();
for (const int layer_index : grease_pencil.layers().index_range()) {
const Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
const Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -84,7 +84,7 @@ static void node_geo_exec(GeoNodeExecParams params)
if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil->layers().index_range()) {
Drawing *drawing = grease_pencil->get_eval_drawing(*grease_pencil->layer(layer_index));
Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
if (drawing == nullptr) {
continue;
@@ -116,7 +116,7 @@ static void node_geo_exec(GeoNodeExecParams params)
if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil->layers().index_range()) {
Drawing *drawing = grease_pencil->get_eval_drawing(*grease_pencil->layer(layer_index));
Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
if (drawing == nullptr) {
continue;
}
@@ -146,7 +146,7 @@ static void node_geo_exec(GeoNodeExecParams params)
if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil->layers().index_range()) {
Drawing *drawing = grease_pencil->get_eval_drawing(*grease_pencil->layer(layer_index));
Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -37,7 +37,7 @@ static void reverse_grease_pencil(GreasePencil &grease_pencil, const Field<bool>
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -52,7 +52,7 @@ static void subdivide_grease_pencil_curves(GreasePencil &grease_pencil,
{
using namespace bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;

View File

@@ -58,7 +58,7 @@ static void grease_pencil_to_mesh(GeometrySet &geometry_set,
Array<Mesh *> mesh_by_layer(grease_pencil.layers().size(), nullptr);
for (const int layer_index : grease_pencil.layers().index_range()) {
const Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
const Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -235,7 +235,7 @@ static void grease_pencil_to_points(GeometrySet &geometry_set,
const GreasePencil &grease_pencil = *geometry.get_grease_pencil();
Vector<PointCloud *> pointcloud_by_layer(grease_pencil.layers().size(), nullptr);
for (const int layer_index : grease_pencil.layers().index_range()) {
const Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
const Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -175,7 +175,7 @@ static void geometry_set_curve_trim(GeometrySet &geometry_set,
using namespace bke::greasepencil;
GreasePencil &grease_pencil = *geometry_set.get_grease_pencil_for_write();
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -176,7 +176,7 @@ static GreasePencil *curve_instances_to_grease_pencil_layers(
const VArray<float> opacities = *instances_attributes.lookup_or_default<float>(
"opacity", AttrDomain::Instance, 1.0f);
instance_selection.foreach_index([&](const int instance_i, const int layer_i) {
grease_pencil->layer(layer_i)->opacity = opacities[instance_i];
grease_pencil->layer(layer_i).opacity = opacities[instance_i];
});
}

View File

@@ -118,7 +118,7 @@ static void node_geo_exec(GeoNodeExecParams params)
instances_attributes.lookup_or_add_for_write_only_span<float>("opacity",
AttrDomain::Instance);
layer_selection.foreach_index([&](const int layer_i, const int instance_i) {
opacity_attribute.span[instance_i] = grease_pencil->layer(layer_i)->opacity;
opacity_attribute.span[instance_i] = grease_pencil->layer(layer_i).opacity;
});
opacity_attribute.finish();
}

View File

@@ -226,7 +226,7 @@ static void node_geo_exec(GeoNodeExecParams params)
using namespace bke::greasepencil;
const GreasePencil &grease_pencil = *geometry_set.get_grease_pencil();
for (const int layer_index : grease_pencil.layers().index_range()) {
const Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
const Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -79,7 +79,7 @@ static void set_grease_pencil_normal(GreasePencil &grease_pencil,
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -50,7 +50,7 @@ static void node_geo_exec(GeoNodeExecParams params)
if (GreasePencil *grease_pencil = geometry_set.get_grease_pencil_for_write()) {
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil->layers().index_range()) {
Drawing *drawing = grease_pencil->get_eval_drawing(*grease_pencil->layer(layer_index));
Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -37,7 +37,7 @@ static void set_grease_pencil_tilt(GreasePencil &grease_pencil,
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -116,7 +116,7 @@ static void node_geo_exec(GeoNodeExecParams params)
using namespace blender::bke::greasepencil;
Vector<Mesh *> mesh_by_layer(grease_pencil->layers().size(), nullptr);
for (const int layer_index : grease_pencil->layers().index_range()) {
Drawing *drawing = grease_pencil->get_eval_drawing(*grease_pencil->layer(layer_index));
Drawing *drawing = grease_pencil->get_eval_drawing(grease_pencil->layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -27,7 +27,7 @@ static void set_material_index_in_grease_pencil(GreasePencil &grease_pencil,
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -82,7 +82,7 @@ static void set_position_in_grease_pencil(GreasePencil &grease_pencil,
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr || drawing->strokes().points_num() == 0) {
continue;
}

View File

@@ -37,7 +37,7 @@ static void set_grease_pencil_cyclic(GreasePencil &grease_pencil,
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}

View File

@@ -37,7 +37,7 @@ static void set_grease_pencil_resolution(GreasePencil &grease_pencil,
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = grease_pencil.get_eval_drawing(*grease_pencil.layer(layer_index));
Drawing *drawing = grease_pencil.get_eval_drawing(grease_pencil.layer(layer_index));
if (drawing == nullptr) {
continue;
}