From 6d24017529fd0f551fd60df1b2f140e7cdd0b68e Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 11 Aug 2021 15:42:36 +0200 Subject: Cleanup: use socket identifier instead of names in Cycles shader export Will be required when we support setting different names and identifiers for OSL. Ref D12074 --- intern/cycles/blender/blender_shader.cpp | 78 +++++++++++++------------------- 1 file changed, 32 insertions(+), 46 deletions(-) (limited to 'intern') diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 7f129310736..f3ad9c3639a 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -149,7 +149,7 @@ BlenderAttributeType blender_attribute_name_split_type(ustring name, string *r_r static BL::NodeSocket get_node_output(BL::Node &b_node, const string &name) { for (BL::NodeSocket &b_out : b_node.outputs) { - if (b_out.name() == name) { + if (b_out.identifier() == name) { return b_out; } } @@ -215,7 +215,12 @@ static void set_default_value(ShaderInput *input, break; } case SocketType::INT: { - node->set(socket, get_int(b_sock.ptr, "default_value")); + if (b_sock.type() == BL::NodeSocket::type_BOOLEAN) { + node->set(socket, get_boolean(b_sock.ptr, "default_value")); + } + else { + node->set(socket, get_int(b_sock.ptr, "default_value")); + } break; } case SocketType::COLOR: { @@ -1006,67 +1011,48 @@ static ShaderInput *node_find_input_by_name(ShaderNode *node, BL::Node &b_node, BL::NodeSocket &b_socket) { - string name = b_socket.name(); + string name = b_socket.identifier(); + ShaderInput *input = node->input(name.c_str()); - if (node_use_modified_socket_name(node)) { - bool found = false; - int counter = 0, total = 0; + if (!input && node_use_modified_socket_name(node)) { + /* Different internal name for shader. */ + if (string_startswith(name, "Shader")) { + string_replace(name, "Shader", "Closure"); + } + input = node->input(name.c_str()); - for (BL::NodeSocket &b_input : b_node.inputs) { - if (b_input.name() == name) { - if (!found) { - counter++; - } - total++; + if (!input) { + /* Different internal numbering of two sockets with same name. */ + if (string_endswith(name, "_001")) { + string_replace(name, "_001", "2"); + } + else { + name += "1"; } - if (b_input.ptr.data == b_socket.ptr.data) - found = true; + input = node->input(name.c_str()); } - - /* rename if needed */ - if (name == "Shader") - name = "Closure"; - - if (total > 1) - name = string_printf("%s%d", name.c_str(), counter); } - return node->input(name.c_str()); + return input; } static ShaderOutput *node_find_output_by_name(ShaderNode *node, BL::Node &b_node, BL::NodeSocket &b_socket) { - string name = b_socket.name(); + string name = b_socket.identifier(); + ShaderOutput *output = node->output(name.c_str()); - if (node_use_modified_socket_name(node)) { - bool found = false; - int counter = 0, total = 0; - - for (BL::NodeSocket &b_output : b_node.outputs) { - if (b_output.name() == name) { - if (!found) { - counter++; - } - total++; - } - - if (b_output.ptr.data == b_socket.ptr.data) { - found = true; - } - } - - /* rename if needed */ - if (name == "Shader") + if (!output && node_use_modified_socket_name(node)) { + /* Different internal name for shader. */ + if (name == "Shader") { name = "Closure"; - - if (total > 1) - name = string_printf("%s%d", name.c_str(), counter); + output = node->output(name.c_str()); + } } - return node->output(name.c_str()); + return output; } static void add_nodes(Scene *scene, -- cgit v1.2.3