From 0783debda88779c6ee56281d08ac0b2d3b3d4dd9 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 7 Sep 2023 14:47:40 +0200 Subject: [PATCH] Geometry Nodes: Hide node group selector for asset modifiers When adding modifiers from assets in the new modifier menu, switching the node group the modifier uses afterwards will not be common. The goal is to replace the builtin modifier directly. In that case it's easier to just add a new modifier. The "Empty Modifier" item makes it easy to choose an arbitrary node group anyway. Combined with hiding the two sub-panels when they are unnecessary, many node-modifiers will look just as clean as their builtin counterparts. The option to show the data-block selector is added to the menu in the node header so it's still accessible though. Pull Request: https://projects.blender.org/blender/blender/pulls/111995 --- .../editors/object/add_modifier_assets.cc | 3 +++ .../editors/object/object_relations.cc | 9 ++++++++ .../editors/space_view3d/space_view3d.cc | 9 +++++++- source/blender/makesdna/DNA_modifier_types.h | 10 +++++++++ .../blender/makesrna/intern/rna_modifier.cc | 7 ++++++ source/blender/modifiers/intern/MOD_nodes.cc | 22 ++++++++++--------- .../blender/modifiers/intern/MOD_ui_common.cc | 1 + 7 files changed, 50 insertions(+), 11 deletions(-) diff --git a/source/blender/editors/object/add_modifier_assets.cc b/source/blender/editors/object/add_modifier_assets.cc index 908644c58df..5c83e227e50 100644 --- a/source/blender/editors/object/add_modifier_assets.cc +++ b/source/blender/editors/object/add_modifier_assets.cc @@ -219,6 +219,9 @@ static int modifier_add_asset_exec(bContext *C, wmOperator *op) id_us_plus(&node_group->id); MOD_nodes_update_interface(object, nmd); + /* By default, don't show the data-block selector since it's not usually necessary for assets. */ + nmd->flag |= NODES_MODIFIER_HIDE_DATABLOCK_SELECTOR; + STRNCPY(nmd->modifier.name, DATA_(node_group->id.name + 2)); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, object); diff --git a/source/blender/editors/object/object_relations.cc b/source/blender/editors/object/object_relations.cc index f3876c2cf2b..ba68e448ee8 100644 --- a/source/blender/editors/object/object_relations.cc +++ b/source/blender/editors/object/object_relations.cc @@ -3027,6 +3027,10 @@ static int drop_geometry_nodes_invoke(bContext *C, wmOperator *op, const wmEvent return OPERATOR_CANCELLED; } + if (!RNA_boolean_get(op->ptr, "show_datablock_in_modifier")) { + nmd->flag |= NODES_MODIFIER_HIDE_DATABLOCK_SELECTOR; + } + nmd->node_group = node_tree; id_us_plus(&node_tree->id); MOD_nodes_update_interface(ob, nmd); @@ -3057,6 +3061,11 @@ void OBJECT_OT_drop_geometry_nodes(wmOperatorType *ot) INT32_MIN, INT32_MAX); RNA_def_property_flag(prop, (PropertyFlag)(PROP_HIDDEN | PROP_SKIP_SAVE)); + RNA_def_boolean(ot->srna, + "show_datablock_in_modifier", + true, + "Show the datablock selector in the modifier", + ""); } /** \} */ diff --git a/source/blender/editors/space_view3d/space_view3d.cc b/source/blender/editors/space_view3d/space_view3d.cc index 6496d324736..0b63d07a9b5 100644 --- a/source/blender/editors/space_view3d/space_view3d.cc +++ b/source/blender/editors/space_view3d/space_view3d.cc @@ -911,6 +911,13 @@ static void view3d_id_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop) ID *id = WM_drag_get_local_ID_or_import_from_asset(C, drag, 0); WM_operator_properties_id_lookup_set_from_id(drop->ptr, id); + RNA_boolean_set(drop->ptr, "show_datablock_in_modifier", (drag->type != WM_DRAG_ASSET)); +} + +static void view3d_geometry_nodes_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop) +{ + view3d_id_drop_copy(C, drag, drop); + RNA_boolean_set(drop->ptr, "show_datablock_in_modifier", (drag->type != WM_DRAG_ASSET)); } static void view3d_id_drop_copy_with_type(bContext *C, wmDrag *drag, wmDropBox *drop) @@ -1008,7 +1015,7 @@ static void view3d_dropboxes() WM_dropbox_add(lb, "OBJECT_OT_drop_geometry_nodes", view3d_geometry_nodes_drop_poll, - view3d_id_drop_copy, + view3d_geometry_nodes_drop_copy, WM_drag_free_imported_drag_ID, view3d_geometry_nodes_drop_tooltip); WM_dropbox_add(lb, diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 04cc32d42ad..2c58b7c3cba 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -2333,9 +2333,19 @@ typedef struct NodesModifierData { * Directory where baked simulation states are stored. This may be relative to the .blend file. */ char *simulation_bake_directory; + + /** NodesModifierFlag. */ + int8_t flag; + + char _pad[7]; + NodesModifierRuntimeHandle *runtime; } NodesModifierData; +typedef enum NodesModifierFlag { + NODES_MODIFIER_HIDE_DATABLOCK_SELECTOR = (1 << 0), +} NodesModifierFlag; + typedef struct MeshToVolumeModifierData { ModifierData modifier; diff --git a/source/blender/makesrna/intern/rna_modifier.cc b/source/blender/makesrna/intern/rna_modifier.cc index bed28e9d85d..f2952e0b7ef 100644 --- a/source/blender/makesrna/intern/rna_modifier.cc +++ b/source/blender/makesrna/intern/rna_modifier.cc @@ -7075,6 +7075,13 @@ static void rna_def_modifier_nodes(BlenderRNA *brna) prop, "Simulation Bake Directory", "Location on disk where the bake data is stored"); RNA_def_property_update(prop, 0, nullptr); + prop = RNA_def_property(srna, "show_group_selector", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna( + prop, nullptr, "flag", NODES_MODIFIER_HIDE_DATABLOCK_SELECTOR); + RNA_def_property_ui_text(prop, "Show Node Group Selector", ""); + RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE); + RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, nullptr); + RNA_define_lib_overridable(false); } diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index 7e84daec27b..8a55c8b257a 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -1487,16 +1487,18 @@ static void panel_draw(const bContext *C, Panel *panel) * attribute/value toggle requires a manually built layout anyway. */ uiLayoutSetPropDecorate(layout, false); - uiTemplateID(layout, - C, - ptr, - "node_group", - "node.new_geometry_node_group_assign", - nullptr, - nullptr, - 0, - false, - nullptr); + if (!(nmd->flag & NODES_MODIFIER_HIDE_DATABLOCK_SELECTOR)) { + uiTemplateID(layout, + C, + ptr, + "node_group", + "node.new_geometry_node_group_assign", + nullptr, + nullptr, + 0, + false, + nullptr); + } if (nmd->node_group != nullptr && nmd->settings.properties != nullptr) { PointerRNA bmain_ptr = RNA_main_pointer_create(bmain); diff --git a/source/blender/modifiers/intern/MOD_ui_common.cc b/source/blender/modifiers/intern/MOD_ui_common.cc index f32031a3da4..4a4cde618d1 100644 --- a/source/blender/modifiers/intern/MOD_ui_common.cc +++ b/source/blender/modifiers/intern/MOD_ui_common.cc @@ -288,6 +288,7 @@ static void modifier_ops_extra_draw(bContext *C, uiLayout *layout, void *md_v) WM_OP_INVOKE_DEFAULT, UI_ITEM_NONE, &op_ptr); + uiItemR(layout, &ptr, "show_group_selector", UI_ITEM_NONE, nullptr, ICON_NONE); } }