Cleanup: Geometry Nodes: Split modifier property update function
It's a bit easier to follow this way, and we can make better use of const. It's also more reusable in case we have to use it elsewhere too (for node group operators?).
This commit is contained in:
@@ -652,43 +652,33 @@ static void init_socket_cpp_value_from_property(const IDProperty &property,
|
||||
}
|
||||
}
|
||||
|
||||
void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd)
|
||||
static void update_input_properties_from_node_tree(const bNodeTree &tree,
|
||||
const IDProperty *old_properties,
|
||||
IDProperty &properties)
|
||||
{
|
||||
if (nmd->node_group == nullptr) {
|
||||
if (nmd->settings.properties) {
|
||||
IDP_FreeProperty(nmd->settings.properties);
|
||||
nmd->settings.properties = nullptr;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
IDProperty *old_properties = nmd->settings.properties;
|
||||
{
|
||||
IDPropertyTemplate idprop = {0};
|
||||
nmd->settings.properties = IDP_New(IDP_GROUP, &idprop, "Nodes Modifier Settings");
|
||||
}
|
||||
|
||||
int socket_index;
|
||||
LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &nmd->node_group->inputs, socket_index) {
|
||||
IDProperty *new_prop = id_property_create_from_socket(*socket).release();
|
||||
tree.ensure_topology_cache();
|
||||
const Span<const bNodeSocket *> tree_inputs = tree.interface_inputs();
|
||||
for (const int i : tree_inputs.index_range()) {
|
||||
const bNodeSocket &socket = *tree_inputs[i];
|
||||
IDProperty *new_prop = id_property_create_from_socket(socket).release();
|
||||
if (new_prop == nullptr) {
|
||||
/* Out of the set of supported input sockets, only
|
||||
* geometry sockets aren't added to the modifier. */
|
||||
BLI_assert(socket->type == SOCK_GEOMETRY);
|
||||
BLI_assert(socket.type == SOCK_GEOMETRY);
|
||||
continue;
|
||||
}
|
||||
|
||||
new_prop->flag |= IDP_FLAG_OVERRIDABLE_LIBRARY;
|
||||
if (socket->description[0] != '\0') {
|
||||
if (socket.description[0] != '\0') {
|
||||
IDPropertyUIData *ui_data = IDP_ui_data_ensure(new_prop);
|
||||
ui_data->description = BLI_strdup(socket->description);
|
||||
ui_data->description = BLI_strdup(socket.description);
|
||||
}
|
||||
IDP_AddToGroup(nmd->settings.properties, new_prop);
|
||||
IDP_AddToGroup(&properties, new_prop);
|
||||
|
||||
if (old_properties != nullptr) {
|
||||
IDProperty *old_prop = IDP_GetPropertyFromGroup(old_properties, socket->identifier);
|
||||
const IDProperty *old_prop = IDP_GetPropertyFromGroup(old_properties, socket.identifier);
|
||||
if (old_prop != nullptr) {
|
||||
if (id_property_type_matches_socket(*socket, *old_prop)) {
|
||||
if (id_property_type_matches_socket(socket, *old_prop)) {
|
||||
/* #IDP_CopyPropertyContent replaces the UI data as well, which we don't (we only
|
||||
* want to replace the values). So release it temporarily and replace it after. */
|
||||
IDPropertyUIData *ui_data = new_prop->ui_data;
|
||||
@@ -707,20 +697,20 @@ void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd)
|
||||
}
|
||||
}
|
||||
|
||||
if (socket_type_has_attribute_toggle(*socket)) {
|
||||
const std::string use_attribute_id = socket->identifier + use_attribute_suffix;
|
||||
const std::string attribute_name_id = socket->identifier + attribute_name_suffix;
|
||||
if (socket_type_has_attribute_toggle(socket)) {
|
||||
const std::string use_attribute_id = socket.identifier + use_attribute_suffix;
|
||||
const std::string attribute_name_id = socket.identifier + attribute_name_suffix;
|
||||
|
||||
IDPropertyTemplate idprop = {0};
|
||||
IDProperty *use_attribute_prop = IDP_New(IDP_INT, &idprop, use_attribute_id.c_str());
|
||||
IDP_AddToGroup(nmd->settings.properties, use_attribute_prop);
|
||||
IDP_AddToGroup(&properties, use_attribute_prop);
|
||||
|
||||
IDProperty *attribute_prop = IDP_New(IDP_STRING, &idprop, attribute_name_id.c_str());
|
||||
IDP_AddToGroup(nmd->settings.properties, attribute_prop);
|
||||
IDP_AddToGroup(&properties, attribute_prop);
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -739,23 +729,31 @@ void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LISTBASE_FOREACH (bNodeSocket *, socket, &nmd->node_group->outputs) {
|
||||
if (!socket_type_has_attribute_toggle(*socket)) {
|
||||
static void update_output_properties_from_node_tree(const bNodeTree &tree,
|
||||
const IDProperty *old_properties,
|
||||
IDProperty &properties)
|
||||
{
|
||||
tree.ensure_topology_cache();
|
||||
const Span<const bNodeSocket *> tree_outputs = tree.interface_outputs();
|
||||
for (const int i : tree_outputs.index_range()) {
|
||||
const bNodeSocket &socket = *tree_outputs[i];
|
||||
if (!socket_type_has_attribute_toggle(socket)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const std::string idprop_name = socket->identifier + attribute_name_suffix;
|
||||
const std::string idprop_name = socket.identifier + attribute_name_suffix;
|
||||
IDProperty *new_prop = IDP_NewString("", idprop_name.c_str(), MAX_NAME);
|
||||
if (socket->description[0] != '\0') {
|
||||
if (socket.description[0] != '\0') {
|
||||
IDPropertyUIData *ui_data = IDP_ui_data_ensure(new_prop);
|
||||
ui_data->description = BLI_strdup(socket->description);
|
||||
ui_data->description = BLI_strdup(socket.description);
|
||||
}
|
||||
IDP_AddToGroup(nmd->settings.properties, new_prop);
|
||||
IDP_AddToGroup(&properties, new_prop);
|
||||
|
||||
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);
|
||||
if (socket.default_attribute_name && socket.default_attribute_name[0] != '\0') {
|
||||
IDP_AssignString(new_prop, socket.default_attribute_name, MAX_NAME);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -773,6 +771,27 @@ void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
IDProperty *old_properties = nmd->settings.properties;
|
||||
{
|
||||
IDPropertyTemplate idprop = {0};
|
||||
nmd->settings.properties = IDP_New(IDP_GROUP, &idprop, "Nodes Modifier Settings");
|
||||
}
|
||||
IDProperty *new_properties = nmd->settings.properties;
|
||||
|
||||
update_input_properties_from_node_tree(*nmd->node_group, old_properties, *new_properties);
|
||||
update_output_properties_from_node_tree(*nmd->node_group, old_properties, *new_properties);
|
||||
|
||||
if (old_properties != nullptr) {
|
||||
IDP_FreeProperty(old_properties);
|
||||
|
||||
Reference in New Issue
Block a user