Grease Pencil: Viewport option for showing onion skins of the active object only

This PR adds an option to only show the onion skins of the active
object. The option is added to the Grease Pencil overlay menu in the
3D viewport.
When enabled, only the onion skins of the active object are shown.
This keeps the viewport a lot cleaner when working with multiple
Grease Pencil objects.

This resolves #136820.

Pull Request: https://projects.blender.org/blender/blender/pulls/137405
This commit is contained in:
Sietse Brouwer
2025-05-01 17:43:17 +02:00
committed by Falk David
parent 5e2a856566
commit 668aed18e9
5 changed files with 21 additions and 2 deletions

View File

@@ -7910,7 +7910,12 @@ class VIEW3D_PT_overlay_grease_pencil_options(Panel):
translate=False
)
layout.prop(overlay, "use_gpencil_onion_skin", text="Onion Skin")
split = layout.split()
col = split.column()
col.prop(overlay, "use_gpencil_onion_skin", text="Onion Skin")
col = split.column()
col.active = overlay.use_gpencil_onion_skin
col.prop(overlay, "use_gpencil_onion_skin_active_object", text="Active Object Only")
col = layout.column()
row = col.row()

View File

@@ -181,6 +181,8 @@ void Instance::begin_sync()
nullptr :
false;
this->do_onion = show_onion && !hide_overlay && !playing;
this->do_onion_only_active_object = ((draw_ctx->v3d->gp_flag &
V3D_GP_ONION_SKIN_ACTIVE_OBJECT) != 0);
this->playing = playing;
/* Save simplify flags (can change while drawing, so it's better to save). */
Scene *scene = draw_ctx->scene;
@@ -346,7 +348,8 @@ tObject *Instance::object_sync_do(Object *ob, ResourceHandle res_handle)
const bool is_vertex_mode = (ob->mode & OB_MODE_VERTEX_PAINT) != 0;
const Bounds<float3> bounds = grease_pencil.bounds_min_max_eval().value_or(Bounds(float3(0)));
const bool do_onion = !this->is_render && this->do_onion;
const bool do_onion = !this->is_render && this->do_onion &&
(this->do_onion_only_active_object ? this->obact == ob : true);
const bool do_multi_frame = (((this->scene->toolsettings->gpencil_flags &
GP_USE_MULTI_FRAME_EDITING) != 0) &&
(ob->mode != OB_MODE_OBJECT));

View File

@@ -256,6 +256,8 @@ struct Instance final : public DrawEngine {
/* Display onion skinning */
bool do_onion;
/* Show only the onion skins of the active object. */
bool do_onion_only_active_object;
/* Playing animation */
bool playing;
/* simplify settings */

View File

@@ -556,6 +556,8 @@ enum {
V3D_GP_SHOW_GRID_XRAY = 1 << 9,
/** Force 3D depth rendering and ignore per-object stroke depth mode. */
V3D_GP_FORCE_STROKE_ORDER_3D = 1 << 10,
/** Onion skin for active object only. */
V3D_GP_ONION_SKIN_ACTIVE_OBJECT = 1 << 11,
};
/** #View3DShading.flag */

View File

@@ -5167,6 +5167,13 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna)
prop, "Onion Skins", "Show ghosts of the keyframes before and after the current frame");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, nullptr);
/* Show onion skin for active object only. */
prop = RNA_def_property(srna, "use_gpencil_onion_skin_active_object", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "gp_flag", V3D_GP_ONION_SKIN_ACTIVE_OBJECT);
RNA_def_property_ui_text(
prop, "Active Object Only", "Show only the onion skins of the active object");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, nullptr);
/* vertex opacity */
prop = RNA_def_property(srna, "vertex_opacity", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, nullptr, "vertex_opacity");