Fix #31675 Reroute nodes aren't working for cycles.
authorLukas Toenne <lukas.toenne@googlemail.com>
Tue, 12 Jun 2012 07:27:50 +0000 (07:27 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Tue, 12 Jun 2012 07:27:50 +0000 (07:27 +0000)
Note that currently the reroute nodes are hardcoded to color values, which means they will not work for shader type connections (and possibly cause overhead for float and vector conversion). Looking into a solution.

intern/cycles/blender/blender_shader.cpp
source/blender/makesrna/intern/rna_nodetree.c

index 35fe4c67673dbafc03801ef10943965045a49122..d5b58298e18c5fd115844eeed9e452bd888289db 100644 (file)
@@ -75,6 +75,52 @@ static float get_node_output_value(BL::Node b_node, const string& name)
        return sock.default_value();
 }
 
+static ShaderSocketType convert_socket_type(BL::NodeSocket::type_enum b_type)
+{
+       switch (b_type) {
+       case BL::NodeSocket::type_VALUE:
+               return SHADER_SOCKET_FLOAT;
+       case BL::NodeSocket::type_VECTOR:
+               return SHADER_SOCKET_VECTOR;
+       case BL::NodeSocket::type_RGBA:
+               return SHADER_SOCKET_COLOR;
+       case BL::NodeSocket::type_SHADER:
+               return SHADER_SOCKET_CLOSURE;
+       
+       case BL::NodeSocket::type_BOOLEAN:
+       case BL::NodeSocket::type_MESH:
+       case BL::NodeSocket::type_INT:
+       default:
+               return SHADER_SOCKET_FLOAT;
+       }
+}
+
+static void set_default_value(ShaderInput *input, BL::NodeSocket sock)
+{
+       /* copy values for non linked inputs */
+       switch(input->type) {
+       case SHADER_SOCKET_FLOAT: {
+               BL::NodeSocketFloatNone value_sock(sock);
+               input->set(value_sock.default_value());
+               break;
+       }
+       case SHADER_SOCKET_COLOR: {
+               BL::NodeSocketRGBA rgba_sock(sock);
+               input->set(get_float3(rgba_sock.default_value()));
+               break;
+       }
+       case SHADER_SOCKET_NORMAL:
+       case SHADER_SOCKET_POINT:
+       case SHADER_SOCKET_VECTOR: {
+               BL::NodeSocketVectorNone vec_sock(sock);
+               input->set(get_float3(vec_sock.default_value()));
+               break;
+       }
+       case SHADER_SOCKET_CLOSURE:
+               break;
+       }
+}
+
 static void get_tex_mapping(TextureMapping *mapping, BL::TexMapping b_mapping)
 {
        if(!b_mapping)
@@ -122,10 +168,18 @@ static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph
                /* handled outside this function */
                case BL::ShaderNode::type_GROUP: break;
                /* existing blender nodes */
+               case BL::ShaderNode::type_REROUTE: {
+                       BL::Node::inputs_iterator b_input;
+                       b_node.inputs.begin(b_input);
+                       BL::Node::outputs_iterator b_output;
+                       b_node.outputs.begin(b_output);
+                       ProxyNode *proxy = new ProxyNode(convert_socket_type(b_input->type()), convert_socket_type(b_output->type()));
+                       node = proxy;
+                       break;
+               }
                case BL::ShaderNode::type_CURVE_RGB: {
                        RGBCurvesNode *ramp = new RGBCurvesNode();
                        node = ramp;
-                       break;
                }
                case BL::ShaderNode::type_VALTORGB: {
                        RGBRampNode *ramp = new RGBRampNode();
@@ -488,52 +542,6 @@ static SocketPair node_socket_map_pair(PtrNodeMap& node_map, BL::Node b_node, BL
        return SocketPair(node_map[b_node.ptr.data], name);
 }
 
-static ShaderSocketType convert_socket_type(BL::NodeSocket::type_enum b_type)
-{
-       switch (b_type) {
-       case BL::NodeSocket::type_VALUE:
-               return SHADER_SOCKET_FLOAT;
-       case BL::NodeSocket::type_VECTOR:
-               return SHADER_SOCKET_VECTOR;
-       case BL::NodeSocket::type_RGBA:
-               return SHADER_SOCKET_COLOR;
-       case BL::NodeSocket::type_SHADER:
-               return SHADER_SOCKET_CLOSURE;
-       
-       case BL::NodeSocket::type_BOOLEAN:
-       case BL::NodeSocket::type_MESH:
-       case BL::NodeSocket::type_INT:
-       default:
-               return SHADER_SOCKET_FLOAT;
-       }
-}
-
-static void set_default_value(ShaderInput *input, BL::NodeSocket sock)
-{
-       /* copy values for non linked inputs */
-       switch(input->type) {
-       case SHADER_SOCKET_FLOAT: {
-               BL::NodeSocketFloatNone value_sock(sock);
-               input->set(value_sock.default_value());
-               break;
-       }
-       case SHADER_SOCKET_COLOR: {
-               BL::NodeSocketRGBA rgba_sock(sock);
-               input->set(get_float3(rgba_sock.default_value()));
-               break;
-       }
-       case SHADER_SOCKET_NORMAL:
-       case SHADER_SOCKET_POINT:
-       case SHADER_SOCKET_VECTOR: {
-               BL::NodeSocketVectorNone vec_sock(sock);
-               input->set(get_float3(vec_sock.default_value()));
-               break;
-       }
-       case SHADER_SOCKET_CLOSURE:
-               break;
-       }
-}
-
 static void add_nodes(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph *graph, BL::ShaderNodeTree b_ntree, PtrSockMap& sockets_map)
 {
        /* add nodes */
index ca61b5328627dee9eaa9119b90b581cadd037b5b..92de882d48b737b0225ad5a056b04da08576a1a8 100644 (file)
@@ -1058,6 +1058,7 @@ static void init(void)
        reg_node(NODE_FORLOOP, Category_LoopNode, "FORLOOP", "NodeForLoop", "Node", "ForLoop", "");
        reg_node(NODE_WHILELOOP, Category_LoopNode, "WHILELOOP", "NodeWhileLoop", "Node", "WhileLoop", "");
        reg_node(NODE_FRAME, Category_LayoutNode, "FRAME", "NodeFrame", "Node", "Frame", "");
+       reg_node(NODE_REROUTE, Category_LayoutNode, "REROUTE", "NodeReroute", "Node", "Reroute", "");
 }
 
 static StructRNA *def_node(BlenderRNA *brna, int node_id)
@@ -1075,7 +1076,7 @@ static StructRNA *def_node(BlenderRNA *brna, int node_id)
 static void alloc_node_type_items(EnumPropertyItem *items, int category)
 {
        int i;
-       int count = 3;
+       int count = 4;
        EnumPropertyItem *item  = items;
        
        for (i = 0; i < MaxNodes; i++)
@@ -1105,6 +1106,14 @@ static void alloc_node_type_items(EnumPropertyItem *items, int category)
        
        item++;
        
+       item->value = NODE_REROUTE;
+       item->identifier = "REROUTE";
+       item->icon = 0;
+       item->name = "Reroute";
+       item->description = "";
+       
+       item++;
+       
        /* NOTE!, increase 'count' when adding items here */
        
        memset(item, 0, sizeof(EnumPropertyItem));
@@ -4208,6 +4217,7 @@ void RNA_def_nodetree(BlenderRNA *brna)
        define_specific_node(brna, NODE_FORLOOP, def_forloop);
        define_specific_node(brna, NODE_WHILELOOP, def_whileloop);
        define_specific_node(brna, NODE_FRAME, def_frame);
+       define_specific_node(brna, NODE_REROUTE, 0);
        
        /* special socket types */
        rna_def_cmp_output_file_slot_file(brna);