| 495 | } |
| 496 | |
| 497 | void ShaderNetworkAlgo::removeComponentConnectionAdapters( ShaderNetwork *network ) |
| 498 | { |
| 499 | std::vector< IECore::InternedString > toRemove; |
| 500 | |
| 501 | InternedString component; |
| 502 | InternedString inParameter; |
| 503 | std::array<InternedString, 4> inParameters; |
| 504 | InternedString outParameter; |
| 505 | |
| 506 | for( const auto &s : network->shaders() ) |
| 507 | { |
| 508 | if( isSplitAdapter( s.second.get(), component, inParameter, outParameter ) ) |
| 509 | { |
| 510 | ShaderNetwork::Parameter source = network->input( ShaderNetwork::Parameter( s.first, inParameter ) ); |
| 511 | if( !source ) |
| 512 | { |
| 513 | throw IECore::Exception( boost::str( |
| 514 | boost::format( |
| 515 | "removeComponentConnectionAdapters : \"%1%.%2%\" has no input" |
| 516 | ) % s.first.string() % inParameter.string() |
| 517 | ) ); |
| 518 | } |
| 519 | source.name = source.name.string() + "." + component.string(); |
| 520 | |
| 521 | const ShaderNetwork::ConnectionRange outputConnections = network->outputConnections( s.first ); |
| 522 | for( auto connectionIt = outputConnections.begin(); connectionIt != outputConnections.end(); ) |
| 523 | { |
| 524 | // Copy and increment now so we still have a valid iterator when we |
| 525 | // remove the connection. |
| 526 | const ShaderNetwork::Connection connection = *connectionIt++; |
| 527 | network->removeConnection( connection ); |
| 528 | network->addConnection( { source, connection.destination } ); |
| 529 | } |
| 530 | |
| 531 | toRemove.push_back( s.first ); |
| 532 | } |
| 533 | else if( isJoinAdapter( s.second.get(), inParameters, outParameter ) ) |
| 534 | { |
| 535 | std::array<ShaderNetwork::Parameter, 4> componentInputs; |
| 536 | for( size_t i = 0; i < inParameters.size(); ++i ) |
| 537 | { |
| 538 | if( !inParameters[i].string().empty() ) |
| 539 | { |
| 540 | componentInputs[i] = network->input( { s.first, inParameters[i] } ); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | const ShaderNetwork::ConnectionRange outputConnections = network->outputConnections( s.first ); |
| 545 | for( auto connectionIt = outputConnections.begin(); connectionIt != outputConnections.end(); ) |
| 546 | { |
| 547 | // Copy and increment now so we still have a valid iterator when we |
| 548 | // remove the connection. |
| 549 | const ShaderNetwork::Connection connection = *connectionIt++; |
| 550 | network->removeConnection( connection ); |
| 551 | |
| 552 | const Data *destinationValue = network->getShader( connection.destination.shader )->parametersData()->member<Data>( connection.destination.name ); |
| 553 | const bool isColor = runTimeCast<const Color3fData>( destinationValue ) || runTimeCast<const Color4fData>( destinationValue ); |
| 554 | |