| 625 | } |
| 626 | |
| 627 | void convertOSLComponentConnections( ShaderNetwork *network, int oslVersion ) |
| 628 | { |
| 629 | if( oslVersion < 11000 ) |
| 630 | { |
| 631 | // OSL doesn't support component-level connections, |
| 632 | // so we emulate them by inserting conversion shaders for OSL nodes. |
| 633 | ShaderNetworkAlgo::addComponentConnectionAdapters( network, "osl:" ); |
| 634 | return; |
| 635 | } |
| 636 | |
| 637 | // We have an OSL version that supports component connections. |
| 638 | // But OSL uses `[0]` rather than `.r` suffix style, so translate the connection names |
| 639 | |
| 640 | for( const auto &s : network->shaders() ) |
| 641 | { |
| 642 | bool destIsOSL = boost::starts_with( s.second->getType(), "osl:" ); |
| 643 | |
| 644 | ShaderNetwork::ConnectionRange inputConnections = network->inputConnections( s.first ); |
| 645 | for( ShaderNetwork::ConnectionIterator it = inputConnections.begin(); it != inputConnections.end(); ) |
| 646 | { |
| 647 | // Copy and increment now so we still have a valid iterator |
| 648 | // if we remove the connection. |
| 649 | const ShaderNetwork::Connection connection = *it++; |
| 650 | |
| 651 | const Shader *sourceShader = network->getShader( connection.source.shader ); |
| 652 | |
| 653 | bool sourceIsOSL = boost::starts_with( sourceShader->getType(), "osl:" ); |
| 654 | ShaderNetwork::Parameter newSourceName, newDestName; |
| 655 | |
| 656 | boost::cmatch match; |
| 657 | if( sourceIsOSL && boost::regex_match( connection.source.name.c_str(), match, g_componentRegex ) ) |
| 658 | { |
| 659 | newSourceName = convertComponentSuffix( connection.source, match[2] ); |
| 660 | } |
| 661 | if( destIsOSL && boost::regex_match( connection.destination.name.c_str(), match, g_componentRegex ) ) |
| 662 | { |
| 663 | newDestName = convertComponentSuffix( connection.destination, match[2] ); |
| 664 | } |
| 665 | if( newSourceName.shader.string().size() || newDestName.shader.string().size() ) |
| 666 | { |
| 667 | network->removeConnection( connection ); |
| 668 | network->addConnection( { |
| 669 | newSourceName.shader.string().size() ? newSourceName : connection.source, |
| 670 | newDestName.shader.string().size() ? newDestName : connection.destination |
| 671 | } ); |
| 672 | } |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | } // namespace |
| 678 |
no test coverage detected