diff options
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/graph.cpp | 20 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 18 | ||||
-rw-r--r-- | intern/cycles/render/nodes.h | 2 |
3 files changed, 18 insertions, 22 deletions
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp index ac78238dfee..66601fa3502 100644 --- a/intern/cycles/render/graph.cpp +++ b/intern/cycles/render/graph.cpp @@ -374,24 +374,12 @@ void ShaderGraph::copy_nodes(ShaderNodeSet& nodes, ShaderNodeMap& nnodemap) ShaderNode *nnode = node->clone(); nnodemap[node] = nnode; + /* create new inputs and outputs to recreate links and ensure + * that we still point to valid SocketType if the NodeType + * changed in cloning, as it does for OSL nodes */ nnode->inputs.clear(); nnode->outputs.clear(); - - foreach(ShaderInput *input, node->inputs) { - ShaderInput *ninput = new ShaderInput(*input); - nnode->inputs.push_back(ninput); - - ninput->parent = nnode; - ninput->link = NULL; - } - - foreach(ShaderOutput *output, node->outputs) { - ShaderOutput *noutput = new ShaderOutput(*output); - nnode->outputs.push_back(noutput); - - noutput->parent = nnode; - noutput->links.clear(); - } + nnode->create_inputs_outputs(nnode->type); } /* recreate links */ diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 66c92bda54b..e26084c690b 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -5062,12 +5062,10 @@ OSLNode::~OSLNode() ShaderNode *OSLNode::clone() const { - OSLNode *node = new OSLNode(*this); - node->type = new NodeType(*type); - return node; + return OSLNode::create(this->inputs.size(), this); } -OSLNode* OSLNode::create(size_t num_inputs) +OSLNode* OSLNode::create(size_t num_inputs, const OSLNode *from) { /* allocate space for the node itself and parameters, aligned to 16 bytes * assuming that's the most parameter types need */ @@ -5077,7 +5075,17 @@ OSLNode* OSLNode::create(size_t num_inputs) char *node_memory = (char*) operator new(node_size + inputs_size); memset(node_memory, 0, node_size + inputs_size); - return new(node_memory) OSLNode(); + if (!from) { + return new(node_memory) OSLNode(); + } + else { + /* copy input default values and node type for cloning */ + memcpy(node_memory + node_size, (char*)from + node_size, inputs_size); + + OSLNode *node = new(node_memory) OSLNode(*from); + node->type = new NodeType(*(from->type)); + return node; + } } char* OSLNode::input_default_value() diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index c98ff6f278d..caad11af0f8 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -921,7 +921,7 @@ public: class OSLNode : public ShaderNode { public: - static OSLNode *create(size_t num_inputs); + static OSLNode *create(size_t num_inputs, const OSLNode *from = NULL); ~OSLNode(); ShaderNode *clone() const; |