Geometry Nodes: Polish switch node UI

Based on the task T88006, there are a few simple changes
to make to improve the switch node:
- Change the label to "False" / "True" for clarity
- Change default to geometry, as it's the basic data container in
  geometry nodes.
- Change node class to `NODE_CLASS_CONVERTOR`, which was an oversight
  in the original patch.

I will add the new socket types (material and texture) in a separate commit.
Thanks to @EitanSomething for the original patch.

Differential Revision: https://developer.blender.org/D11165
This commit is contained in:
Hans Goudey 2021-05-28 12:17:04 -04:00
parent c0ce7fce89
commit 653bbaa246
Notes: blender-bot 2023-02-14 08:38:11 +01:00
Referenced by issue #88006, Switch node polishing
3 changed files with 67 additions and 34 deletions

View File

@ -39,7 +39,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 1
#define BLENDER_FILE_SUBVERSION 2
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file

View File

@ -22,6 +22,7 @@
#include "BLI_listbase.h"
#include "BLI_math_vector.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "DNA_brush_types.h"
@ -85,6 +86,32 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
}
}
static void version_switch_node_input_prefix(Main *bmain)
{
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
if (ntree->type == NTREE_GEOMETRY) {
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
if (node->type == GEO_NODE_SWITCH) {
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
/* Skip the "switch" socket. */
if (socket == node->inputs.first) {
continue;
}
strcpy(socket->name, socket->name[0] == 'A' ? "False" : "True");
/* Replace "A" and "B", but keep the unique number suffix at the end. */
char number_suffix[8];
BLI_strncpy(number_suffix, socket->identifier + 1, sizeof(number_suffix));
strcpy(socket->identifier, socket->name);
strcat(socket->identifier, number_suffix);
}
}
}
}
}
FOREACH_NODETREE_END;
}
/* NOLINTNEXTLINE: readability-function-size */
void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
{
@ -110,17 +137,10 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
/**
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
if (!MAIN_VERSION_ATLEAST(bmain, 300, 2)) {
version_switch_node_input_prefix(bmain);
if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "custom_scale_xyz[3]")) {
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
if (ob->pose == NULL) {
@ -132,4 +152,17 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
/**
* Versioning code until next subversion bump goes here.
*
* \note Be sure to check when bumping the version:
* - "versioning_userdef.c", #blo_do_versions_userdef
* - "versioning_userdef.c", #do_versions_theme
*
* \note Keep this message at the bottom of the function.
*/
{
/* Keep this block, even when empty. */
}
}

View File

@ -22,24 +22,24 @@
static bNodeSocketTemplate geo_node_switch_in[] = {
{SOCK_BOOLEAN, N_("Switch")},
{SOCK_FLOAT, N_("A"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_FLOAT, N_("B"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_INT, N_("A"), 0, 0, 0, 0, -100000, 100000},
{SOCK_INT, N_("B"), 0, 0, 0, 0, -100000, 100000},
{SOCK_BOOLEAN, N_("A")},
{SOCK_BOOLEAN, N_("B")},
{SOCK_VECTOR, N_("A"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_VECTOR, N_("B"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_RGBA, N_("A"), 0.8, 0.8, 0.8, 1.0},
{SOCK_RGBA, N_("B"), 0.8, 0.8, 0.8, 1.0},
{SOCK_STRING, N_("A")},
{SOCK_STRING, N_("B")},
{SOCK_GEOMETRY, N_("A")},
{SOCK_GEOMETRY, N_("B")},
{SOCK_OBJECT, N_("A")},
{SOCK_OBJECT, N_("B")},
{SOCK_COLLECTION, N_("A")},
{SOCK_COLLECTION, N_("B")},
{SOCK_FLOAT, N_("False"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_FLOAT, N_("True"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_INT, N_("False"), 0, 0, 0, 0, -100000, 100000},
{SOCK_INT, N_("True"), 0, 0, 0, 0, -100000, 100000},
{SOCK_BOOLEAN, N_("False")},
{SOCK_BOOLEAN, N_("True")},
{SOCK_VECTOR, N_("False"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_VECTOR, N_("True"), 0.0, 0.0, 0.0, 0.0, -FLT_MAX, FLT_MAX},
{SOCK_RGBA, N_("False"), 0.8, 0.8, 0.8, 1.0},
{SOCK_RGBA, N_("True"), 0.8, 0.8, 0.8, 1.0},
{SOCK_STRING, N_("False")},
{SOCK_STRING, N_("True")},
{SOCK_GEOMETRY, N_("False")},
{SOCK_GEOMETRY, N_("True")},
{SOCK_OBJECT, N_("False")},
{SOCK_OBJECT, N_("True")},
{SOCK_COLLECTION, N_("False")},
{SOCK_COLLECTION, N_("True")},
{-1, ""},
};
@ -64,7 +64,7 @@ static void geo_node_switch_layout(uiLayout *layout, bContext *UNUSED(C), Pointe
static void geo_node_switch_init(bNodeTree *UNUSED(tree), bNode *node)
{
NodeSwitch *data = (NodeSwitch *)MEM_callocN(sizeof(NodeSwitch), __func__);
data->input_type = SOCK_FLOAT;
data->input_type = SOCK_GEOMETRY;
node->storage = data;
}
@ -91,8 +91,8 @@ static void output_input(GeoNodeExecParams &params,
const StringRef input_suffix,
const StringRef output_identifier)
{
const std::string name_a = "A" + input_suffix;
const std::string name_b = "B" + input_suffix;
const std::string name_a = "False" + input_suffix;
const std::string name_b = "True" + input_suffix;
if (input) {
params.set_input_unused(name_a);
if (params.lazy_require_input(name_b)) {
@ -165,7 +165,7 @@ void register_node_type_geo_switch()
{
static bNodeType ntype;
geo_node_type_base(&ntype, GEO_NODE_SWITCH, "Switch", NODE_CLASS_GEOMETRY, 0);
geo_node_type_base(&ntype, GEO_NODE_SWITCH, "Switch", NODE_CLASS_CONVERTOR, 0);
node_type_socket_templates(&ntype, geo_node_switch_in, geo_node_switch_out);
node_type_init(&ntype, geo_node_switch_init);
node_type_update(&ntype, blender::nodes::geo_node_switch_update);