Geometry Nodes: Don't create node tree when adding nodes modifier

Don't always create a new geometry nodes node tree when adding a
geometry nodes modifier.

This avoids files getting cluttered with empty and unused geometry node
trees that are created every time a nodes modifier is added to an
object - even if only to apply an already existing.
This is also more consistent with other modifiers that also don't
automatically create new data blocks.

The new modifier still automatically gets populated with a new node
tree when adding it via the "New" button in the header of the
geometry nodes editor.

Reviewed By: Hans Goudey, Dalai Felinto, Pablo Vazquez

Differential Revision: D14458
This commit is contained in:
Leon Schittek 2022-03-29 22:28:02 +02:00
parent 4eb4c90cf6
commit 08b4b657b6
4 changed files with 3 additions and 32 deletions

View File

@ -50,6 +50,9 @@ class NewGeometryNodesModifier(Operator):
if not modifier:
return {'CANCELLED'}
group = geometry_node_group_empty_new()
modifier.node_group = group
return {'FINISHED'}

View File

@ -219,9 +219,6 @@ ModifierData *ED_object_modifier_add(
/* ensure skin-node customdata exists */
BKE_mesh_ensure_skin_customdata(ob->data);
}
else if (type == eModifierType_Nodes) {
MOD_nodes_init(bmain, (NodesModifierData *)new_md);
}
}
BKE_object_modifier_set_active(ob, new_md);

View File

@ -17,8 +17,6 @@ extern "C" {
*/
void MOD_nodes_update_interface(struct Object *object, struct NodesModifierData *nmd);
void MOD_nodes_init(struct Main *bmain, struct NodesModifierData *nmd);
#ifdef __cplusplus
}
#endif

View File

@ -732,33 +732,6 @@ void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd)
DEG_id_tag_update(&object->id, ID_RECALC_GEOMETRY);
}
void MOD_nodes_init(Main *bmain, NodesModifierData *nmd)
{
bNodeTree *ntree = ntreeAddTree(bmain, "Geometry Nodes", ntreeType_Geometry->idname);
nmd->node_group = ntree;
ntreeAddSocketInterface(ntree, SOCK_IN, "NodeSocketGeometry", "Geometry");
ntreeAddSocketInterface(ntree, SOCK_OUT, "NodeSocketGeometry", "Geometry");
bNode *group_input_node = nodeAddStaticNode(nullptr, ntree, NODE_GROUP_INPUT);
bNode *group_output_node = nodeAddStaticNode(nullptr, ntree, NODE_GROUP_OUTPUT);
nodeSetSelected(group_input_node, false);
nodeSetSelected(group_output_node, false);
group_input_node->locx = -200 - group_input_node->width;
group_output_node->locx = 200;
group_output_node->flag |= NODE_DO_OUTPUT;
nodeAddLink(ntree,
group_output_node,
(bNodeSocket *)group_output_node->inputs.first,
group_input_node,
(bNodeSocket *)group_input_node->outputs.first);
BKE_ntree_update_main_tree(bmain, ntree, nullptr);
}
static void initialize_group_input(NodesModifierData &nmd,
const OutputSocketRef &socket,
void *r_value)