Пример #1
0
IECore::ObjectVectorPtr AppleseedLight::computeLight( const Gaffer::Context *context ) const
{
	IECoreScene::ShaderPtr result = new IECoreScene::Shader( modelPlug()->getValue(), "as:light" );
	for( InputValuePlugIterator it( parametersPlug() ); !it.done(); ++it )
	{
		result->parameters()[(*it)->getName()] = CompoundDataPlug::extractDataFromPlug( it->get() );
	}

	IECore::ObjectVectorPtr resultVector = new IECore::ObjectVector();
	resultVector->members().push_back( result );
	return resultVector;
}
Пример #2
0
IECore::ObjectVectorPtr ArnoldLight::computeLight( const Gaffer::Context *context ) const
{
	IECore::ObjectVectorPtr result = new IECore::ObjectVector;
	IECoreScene::ShaderPtr lightShader = new IECoreScene::Shader( shaderNamePlug()->getValue(), "ai:light" );
	for( InputPlugIterator it( parametersPlug() ); !it.done(); ++it )
	{
		if( const Shader *shader = (*it)->source<Plug>()->ancestor<Shader>() )
		{
			/// \todo We should generalise Shader::NetworkBuilder so we can
			/// use it directly to do the whole of the light generation, instead
			/// of dealing with input networks manually one by one here. Alternatively
			/// we could take the approach that OSLLight takes, and use an internal
			/// ArnoldShader to do all the shader loading and network generation.
			/// This would avoid exposing any Shader internals, and would generalise
			/// nicely to the other Light subclasses too.
			IECore::ConstCompoundObjectPtr inputAttributes = shader->attributes();
			const IECore::ObjectVector *inputNetwork = inputAttributes->member<const IECore::ObjectVector>( "ai:surface" );
			if( !inputNetwork || inputNetwork->members().empty() )
			{
				continue;
			}

			// Add input network into our result.
			result->members().insert( result->members().end(), inputNetwork->members().begin(), inputNetwork->members().end() );
			// Update endpoint of network with a handle we can refer to it with.
			result->members().back() = result->members().back()->copy();
			IECoreScene::Shader *endpoint = static_cast<IECoreScene::Shader *>( result->members().back().get() );
			endpoint->parameters()["__handle"] = new IECore::StringData( (*it)->getName() );
			// Add a parameter value linking to the input network.
			lightShader->parameters()[(*it)->getName()] = new IECore::StringData( "link:" + (*it)->getName().string() );
		}
		else if( ValuePlug *valuePlug = IECore::runTimeCast<ValuePlug>( it->get() ) )
		{
			lightShader->parameters()[valuePlug->getName()] = CompoundDataPlug::extractDataFromPlug( valuePlug );
		}
	}

	result->members().push_back( lightShader );
	return result;
}