From 0ad73bb9655f04afb5ad56174d8fb416cded3e4c Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 28 Apr 2022 08:39:30 -0500 Subject: Geometry Nodes: Add default attribute name to field inputs/outputs Geometry node group inputs and outputs get a new property that controls the attribute name used for that field input/output when assigning the node group to a modifier for the first time. If the default name is assigned to an input, the default "Use attribute name" is true . In order to properly detect when a node group is first assigned, the modifier now clears its properties when clearing the node group. Ref T96707 Differential Revision: https://developer.blender.org/D14761 --- source/blender/modifiers/intern/MOD_nodes.cc | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'source/blender/modifiers/intern') diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index 3867abbd29c..1c890190678 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -628,6 +628,10 @@ static void init_socket_cpp_value_from_property(const IDProperty &property, void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd) { if (nmd->node_group == nullptr) { + if (nmd->settings.properties) { + IDP_FreeProperty(nmd->settings.properties); + nmd->settings.properties = nullptr; + } return; } @@ -680,7 +684,13 @@ void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd) IDProperty *attribute_prop = IDP_New(IDP_STRING, &idprop, attribute_name_id.c_str()); IDP_AddToGroup(nmd->settings.properties, attribute_prop); - if (old_properties != nullptr) { + if (old_properties == nullptr) { + if (socket->default_attribute_name && socket->default_attribute_name[0] != '\0') { + IDP_AssignString(attribute_prop, socket->default_attribute_name, MAX_NAME); + IDP_Int(use_attribute_prop) = 1; + } + } + else { IDProperty *old_prop_use_attribute = IDP_GetPropertyFromGroup(old_properties, use_attribute_id.c_str()); if (old_prop_use_attribute != nullptr) { @@ -709,7 +719,12 @@ void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd) } IDP_AddToGroup(nmd->settings.properties, new_prop); - if (old_properties != nullptr) { + if (old_properties == nullptr) { + if (socket->default_attribute_name && socket->default_attribute_name[0] != '\0') { + IDP_AssignString(new_prop, socket->default_attribute_name, MAX_NAME); + } + } + else { IDProperty *old_prop = IDP_GetPropertyFromGroup(old_properties, idprop_name.c_str()); if (old_prop != nullptr) { /* #IDP_CopyPropertyContent replaces the UI data as well, which we don't (we only @@ -1728,8 +1743,13 @@ static void blendWrite(BlendWriter *writer, const ModifierData *md) static void blendRead(BlendDataReader *reader, ModifierData *md) { NodesModifierData *nmd = reinterpret_cast(md); - BLO_read_data_address(reader, &nmd->settings.properties); - IDP_BlendDataRead(reader, &nmd->settings.properties); + if (nmd->node_group == nullptr) { + nmd->settings.properties = nullptr; + } + else { + BLO_read_data_address(reader, &nmd->settings.properties); + IDP_BlendDataRead(reader, &nmd->settings.properties); + } nmd->runtime_eval_log = nullptr; } -- cgit v1.2.3