Fix #135607: Grease Pencil: Auto keying not working when using trim tool

Auto key support was missing. This PR implmented this feature
back so it's consistent with what we have in Blender 4.2.

Pull Request: https://projects.blender.org/blender/blender/pulls/135609
This commit is contained in:
YimingWu
2025-03-10 10:53:01 +01:00
committed by Falk David
parent 3d49186a4a
commit df942ecaca
@@ -162,12 +162,19 @@ static int stroke_trim_execute(const bContext *C, const Span<int2> mcoords)
const bool active_layer_only = (brush->gpencil_settings->flag & GP_BRUSH_ACTIVE_LAYER_ONLY) != 0;
std::atomic<bool> changed = false;
bool inserted_keyframe = false;
if (active_layer_only) {
/* Apply trim on drawings of active layer. */
if (!grease_pencil.has_active_layer()) {
return OPERATOR_CANCELLED;
}
const bke::greasepencil::Layer &layer = *grease_pencil.get_active_layer();
bke::greasepencil::Layer &layer = *grease_pencil.get_active_layer();
if (!layer.is_editable()) {
return OPERATOR_CANCELLED;
}
ensure_active_keyframe(*scene, grease_pencil, layer, true, inserted_keyframe);
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);
const Vector<ed::greasepencil::MutableDrawingInfo> drawings =
@@ -188,6 +195,13 @@ static int stroke_trim_execute(const bContext *C, const Span<int2> mcoords)
});
}
else {
for (bke::greasepencil::Layer *layer : grease_pencil.layers_for_write()) {
if (layer->is_editable()) {
ed::greasepencil::ensure_active_keyframe(
*scene, grease_pencil, *layer, true, inserted_keyframe);
}
}
/* Apply trim on every editable drawing. */
const Vector<ed::greasepencil::MutableDrawingInfo> drawings =
ed::greasepencil::retrieve_editable_drawings(*scene, grease_pencil);
@@ -213,6 +227,9 @@ static int stroke_trim_execute(const bContext *C, const Span<int2> mcoords)
if (changed) {
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, &grease_pencil);
if (inserted_keyframe) {
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, nullptr);
}
}
return OPERATOR_FINISHED;