Cleanup / Cycles: Code de-duplication for graph node relinking.
Differential Revision: https://developer.blender.org/D1018
This commit is contained in:
@@ -227,6 +227,21 @@ void ShaderGraph::disconnect(ShaderInput *to)
|
|||||||
from->links.erase(remove(from->links.begin(), from->links.end(), to), from->links.end());
|
from->links.erase(remove(from->links.begin(), from->links.end(), to), from->links.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShaderGraph::relink(vector<ShaderInput*> inputs, vector<ShaderInput*> outputs, ShaderOutput *output)
|
||||||
|
{
|
||||||
|
/* Remove nodes and re-link if output isn't NULL. */
|
||||||
|
foreach(ShaderInput *sock, inputs) {
|
||||||
|
if(sock->link)
|
||||||
|
disconnect(sock);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(ShaderInput *sock, outputs) {
|
||||||
|
disconnect(sock);
|
||||||
|
if(output)
|
||||||
|
connect(output, sock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderGraph::finalize(bool do_bump, bool do_osl)
|
void ShaderGraph::finalize(bool do_bump, bool do_osl)
|
||||||
{
|
{
|
||||||
/* before compiling, the shader graph may undergo a number of modifications.
|
/* before compiling, the shader graph may undergo a number of modifications.
|
||||||
@@ -383,14 +398,7 @@ void ShaderGraph::remove_unneeded_nodes()
|
|||||||
(!bg->inputs[1]->link && bg->inputs[1]->value.x == 0.0f)) {
|
(!bg->inputs[1]->link && bg->inputs[1]->value.x == 0.0f)) {
|
||||||
vector<ShaderInput*> inputs = bg->outputs[0]->links;
|
vector<ShaderInput*> inputs = bg->outputs[0]->links;
|
||||||
|
|
||||||
foreach(ShaderInput *sock, bg->inputs) {
|
relink(bg->inputs, inputs, NULL);
|
||||||
if(sock->link)
|
|
||||||
disconnect(sock);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach(ShaderInput *input, inputs)
|
|
||||||
disconnect(input);
|
|
||||||
|
|
||||||
removed[bg->id] = true;
|
removed[bg->id] = true;
|
||||||
any_node_removed = true;
|
any_node_removed = true;
|
||||||
}
|
}
|
||||||
@@ -404,15 +412,7 @@ void ShaderGraph::remove_unneeded_nodes()
|
|||||||
ShaderOutput *output = mix->inputs[1]->link;
|
ShaderOutput *output = mix->inputs[1]->link;
|
||||||
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
||||||
|
|
||||||
foreach(ShaderInput *sock, mix->inputs)
|
relink(mix->inputs, inputs, output);
|
||||||
if(sock->link)
|
|
||||||
disconnect(sock);
|
|
||||||
|
|
||||||
foreach(ShaderInput *input, inputs) {
|
|
||||||
disconnect(input);
|
|
||||||
if(output)
|
|
||||||
connect(output, input);
|
|
||||||
}
|
|
||||||
removed[mix->id] = true;
|
removed[mix->id] = true;
|
||||||
any_node_removed = true;
|
any_node_removed = true;
|
||||||
}
|
}
|
||||||
@@ -425,15 +425,7 @@ void ShaderGraph::remove_unneeded_nodes()
|
|||||||
ShaderOutput *output = mix->inputs[1]->link;
|
ShaderOutput *output = mix->inputs[1]->link;
|
||||||
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
||||||
|
|
||||||
foreach(ShaderInput *sock, mix->inputs)
|
relink(mix->inputs, inputs, output);
|
||||||
if(sock->link)
|
|
||||||
disconnect(sock);
|
|
||||||
|
|
||||||
foreach(ShaderInput *input, inputs) {
|
|
||||||
disconnect(input);
|
|
||||||
if(output)
|
|
||||||
connect(output, input);
|
|
||||||
}
|
|
||||||
removed[mix->id] = true;
|
removed[mix->id] = true;
|
||||||
any_node_removed = true;
|
any_node_removed = true;
|
||||||
}
|
}
|
||||||
@@ -441,16 +433,8 @@ void ShaderGraph::remove_unneeded_nodes()
|
|||||||
else if(mix->inputs[0]->value.x == 1.0f) {
|
else if(mix->inputs[0]->value.x == 1.0f) {
|
||||||
ShaderOutput *output = mix->inputs[2]->link;
|
ShaderOutput *output = mix->inputs[2]->link;
|
||||||
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
||||||
|
|
||||||
foreach(ShaderInput *sock, mix->inputs)
|
|
||||||
if(sock->link)
|
|
||||||
disconnect(sock);
|
|
||||||
|
|
||||||
foreach(ShaderInput *input, inputs) {
|
relink(mix->inputs, inputs, output);
|
||||||
disconnect(input);
|
|
||||||
if(output)
|
|
||||||
connect(output, input);
|
|
||||||
}
|
|
||||||
removed[mix->id] = true;
|
removed[mix->id] = true;
|
||||||
any_node_removed = true;
|
any_node_removed = true;
|
||||||
}
|
}
|
||||||
@@ -467,15 +451,7 @@ void ShaderGraph::remove_unneeded_nodes()
|
|||||||
ShaderOutput *output = mix->inputs[1]->link;
|
ShaderOutput *output = mix->inputs[1]->link;
|
||||||
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
||||||
|
|
||||||
foreach(ShaderInput *sock, mix->inputs)
|
relink(mix->inputs, inputs, output);
|
||||||
if(sock->link)
|
|
||||||
disconnect(sock);
|
|
||||||
|
|
||||||
foreach(ShaderInput *input, inputs) {
|
|
||||||
disconnect(input);
|
|
||||||
if(output)
|
|
||||||
connect(output, input);
|
|
||||||
}
|
|
||||||
removed[mix->id] = true;
|
removed[mix->id] = true;
|
||||||
any_node_removed = true;
|
any_node_removed = true;
|
||||||
}
|
}
|
||||||
@@ -484,15 +460,7 @@ void ShaderGraph::remove_unneeded_nodes()
|
|||||||
ShaderOutput *output = mix->inputs[2]->link;
|
ShaderOutput *output = mix->inputs[2]->link;
|
||||||
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
vector<ShaderInput*> inputs = mix->outputs[0]->links;
|
||||||
|
|
||||||
foreach(ShaderInput *sock, mix->inputs)
|
relink(mix->inputs, inputs, output);
|
||||||
if(sock->link)
|
|
||||||
disconnect(sock);
|
|
||||||
|
|
||||||
foreach(ShaderInput *input, inputs) {
|
|
||||||
disconnect(input);
|
|
||||||
if(output)
|
|
||||||
connect(output, input);
|
|
||||||
}
|
|
||||||
removed[mix->id] = true;
|
removed[mix->id] = true;
|
||||||
any_node_removed = true;
|
any_node_removed = true;
|
||||||
}
|
}
|
||||||
|
@@ -247,6 +247,7 @@ public:
|
|||||||
|
|
||||||
void connect(ShaderOutput *from, ShaderInput *to);
|
void connect(ShaderOutput *from, ShaderInput *to);
|
||||||
void disconnect(ShaderInput *to);
|
void disconnect(ShaderInput *to);
|
||||||
|
void relink(vector<ShaderInput*> inputs, vector<ShaderInput*> outputs, ShaderOutput *output);
|
||||||
|
|
||||||
void remove_unneeded_nodes();
|
void remove_unneeded_nodes();
|
||||||
void finalize(bool do_bump = false, bool do_osl = false);
|
void finalize(bool do_bump = false, bool do_osl = false);
|
||||||
|
Reference in New Issue
Block a user