Esempio n. 1
0
void IECoreArnold::RendererImplementation::light( const std::string &name, const std::string &handle, const IECore::CompoundDataMap &parameters )
{
	const char *unprefixedName = name.c_str();
	if( name.find( ':' ) != string::npos )
	{
		if( boost::starts_with( name, "ai:" ) )
		{
			unprefixedName += 3;
		}
		else
		{
			return;
		}
	}

	AtNode *l = AiNode( unprefixedName );
	if( !l )
	{
		msg( Msg::Warning, "IECoreArnold::RendererImplementation::light", boost::format( "Couldn't load light \"%s\"" ) % unprefixedName );
		return;
	}
	for( CompoundDataMap::const_iterator parmIt=parameters.begin(); parmIt!=parameters.end(); parmIt++ )
	{
		ParameterAlgo::setParameter( l, parmIt->first.value().c_str(), parmIt->second.get() );
	}
	applyTransformToNode( l );
	addNode( l );
}
Esempio n. 2
0
void ScriptNode::plugSet( Plug *plug )
{
	if( plug == frameStartPlug() )
	{
		frameEndPlug()->setValue( std::max( frameEndPlug()->getValue(), frameStartPlug()->getValue() ) );
	}
	else if( plug == frameEndPlug() )
	{
		frameStartPlug()->setValue( std::min( frameStartPlug()->getValue(), frameEndPlug()->getValue() ) );
	}
	else if( plug == framesPerSecondPlug() )
	{
		context()->setFramesPerSecond( framesPerSecondPlug()->getValue() );
	}
	else if( plug == variablesPlug() )
	{
		IECore::CompoundDataMap values;
		variablesPlug()->fillCompoundData( values );
		for( IECore::CompoundDataMap::const_iterator it = values.begin(), eIt = values.end(); it != eIt; ++it )
		{
			context()->set( it->first, it->second.get() );
		}
	}
	else if( plug == fileNamePlug() )
	{
		boost::filesystem::path fileName( fileNamePlug()->getValue() );
		context()->set( "script:name", boost::filesystem::basename( fileName ) );
	}
}
Esempio n. 3
0
void setParameters( AtNode *node, const IECore::CompoundDataMap &values )
{
	for( CompoundDataMap::const_iterator it=values.begin(); it!=values.end(); it++ )
	{
		setParameter( node, it->first.value().c_str(), it->second.get() );
	}
}
Esempio n. 4
0
ParameterList::ParameterList( const IECore::CompoundDataMap &parameters, const std::map<std::string, std::string> *typeHints )
{
	reserve( parameters );
	CompoundDataMap::const_iterator it;
	for( it=parameters.begin(); it!=parameters.end(); it++ )
	{
		appendParameter( it->first, it->second.get(), typeHints );
	}
}
Esempio n. 5
0
ParameterList::ParameterList( const IECore::CompoundDataMap &parameters, const std::string &prefix,
	const std::map<std::string, std::string> *typeHints )
{
	reserve( parameters );
	CompoundDataMap::const_iterator it;
	for( it=parameters.begin(); it!=parameters.end(); it++ )
	{
		if( 0==it->first.value().compare( 0, prefix.size(), prefix ) )
		{
			appendParameter( string( it->first, prefix.size() ), it->second.get(), typeHints );
		}
	}
}
Esempio n. 6
0
void ParameterList::reserve( const IECore::CompoundDataMap &parameters )
{
	size_t numStrings = 0;
	size_t numCharPtrs = 0;
	size_t numInts = 0;
	size_t numFloats = 0;
	for( IECore::CompoundDataMap::const_iterator it=parameters.begin(); it!=parameters.end(); it++ )
	{
		accumulateReservations( it->second.get(), numStrings, numCharPtrs, numInts, numFloats );
	}
	m_strings.reserve( numStrings );
	m_charPtrs.reserve( numCharPtrs );
	m_ints.reserve( numInts );
	m_floats.reserve( numFloats );
}
Esempio n. 7
0
void ScriptNode::plugSet( Plug *plug )
{
	if( plug == frameStartPlug() )
	{
		frameEndPlug()->setValue( std::max( frameEndPlug()->getValue(), frameStartPlug()->getValue() ) );
	}
	else if( plug == frameEndPlug() )
	{
		frameStartPlug()->setValue( std::min( frameStartPlug()->getValue(), frameEndPlug()->getValue() ) );
	}
	else if( plug == framePlug() )
	{
		context()->setFrame( framePlug()->getValue() );
	}
	else if( plug == framesPerSecondPlug() )
	{
		context()->setFramesPerSecond( framesPerSecondPlug()->getValue() );
	}
	else if( plug == variablesPlug() )
	{
		IECore::CompoundDataMap values;
		variablesPlug()->fillCompoundData( values );
		for( IECore::CompoundDataMap::const_iterator it = values.begin(), eIt = values.end(); it != eIt; ++it )
		{
			context()->set( it->first, it->second.get() );
		}
	}
	else if( plug == fileNamePlug() )
	{
		const boost::filesystem::path fileName( fileNamePlug()->getValue() );
		context()->set( "script:name", fileName.stem().string() );
		MetadataAlgo::setReadOnly(
			this,
			boost::filesystem::exists( fileName ) && 0 != access( fileName.c_str(), W_OK ),
			/* persistent = */ false
		);
	}
}
Esempio n. 8
0
void IECoreArnold::RendererImplementation::shader( const std::string &type, const std::string &name, const IECore::CompoundDataMap &parameters )
{
	if(
		type=="shader" || type=="ai:shader" ||
		type=="surface" || type=="ai:surface" ||
		type=="displacement" || type=="ai:displacement"
	)
	{
		AtNode *s = 0;
		if( 0 == name.compare( 0, 10, "reference:" ) )
		{
			s = AiNodeLookUpByName( name.c_str() + 10 );
			if( !s )
			{
				msg( Msg::Warning, "IECoreArnold::RendererImplementation::shader", boost::format( "Couldn't find shader \"%s\"" ) % name );
				return;
			}
		}
		else
		{
			s = AiNode( name.c_str() );
			if( !s )
			{
				msg( Msg::Warning, "IECoreArnold::RendererImplementation::shader", boost::format( "Couldn't load shader \"%s\"" ) % name );
				return;
			}
			for( CompoundDataMap::const_iterator parmIt=parameters.begin(); parmIt!=parameters.end(); parmIt++ )
			{
				if( parmIt->second->isInstanceOf( IECore::StringDataTypeId ) )
				{
					const std::string &potentialLink = static_cast<const StringData *>( parmIt->second.get() )->readable();
					if( 0 == potentialLink.compare( 0, 5, "link:" ) )
					{
						std::string linkHandle = potentialLink.c_str() + 5;
						AttributeState::ShaderMap::const_iterator shaderIt = m_attributeStack.top().shaders.find( linkHandle );
						if( shaderIt != m_attributeStack.top().shaders.end() )
						{
							AiNodeLinkOutput( shaderIt->second, "", s, parmIt->first.value().c_str() );
						}
						else
						{
							msg( Msg::Warning, "IECoreArnold::RendererImplementation::shader", boost::format( "Couldn't find shader handle \"%s\" for linking" ) % linkHandle );
						}
						continue;
					}
				}
				ParameterAlgo::setParameter( s, parmIt->first.value().c_str(), parmIt->second.get() );
			}
			addNode( s );
		}

		if( type=="shader" || type == "ai:shader" )
		{
			CompoundDataMap::const_iterator handleIt = parameters.find( "__handle" );
			if( handleIt != parameters.end() && handleIt->second->isInstanceOf( IECore::StringDataTypeId ) )
			{
				const std::string &handle = static_cast<const StringData *>( handleIt->second.get() )->readable();
				m_attributeStack.top().shaders[handle] = s;
			}
			else
			{
				msg( Msg::Warning, "IECoreArnold::RendererImplementation::shader", "No __handle parameter specified." );
			}
		}
		else if( type=="surface" || type == "ai:surface" )
		{
			m_attributeStack.top().surfaceShader = s;
		}
		else
		{
			m_attributeStack.top().displacementShader = s;
		}
	}
	else
	{
		if( type.find( ':' ) == string::npos )
		{
			msg( Msg::Warning, "IECoreArnold::RendererImplementation::shader", boost::format( "Unsupported shader type \"%s\"" ) % type );
		}
	}
}
SxShader IECoreRI::SXRendererImplementation::createShader( const char *name, const char *handle, const IECore::CompoundDataMap &parameters ) const
{
	// create a shader which we'll use just for getting information from. we have to do this
	// in a temporary context created just for the purpose, so that we don't end up making two shaders
	// in the context we actually care about.
	
	boost::shared_ptr<void> tmpContext( SxCreateContext( m_stateStack.top().context.get() ), SxDestroyContext );
	
	SxShader shaderInfo = SxCreateShader( tmpContext.get(), 0, name, 0 );
	if( !shaderInfo )
	{
		// 3delight will have printed a warning already.
		return 0;
	}
	
	// convert the parameter list for the shader
		
	SxParameterList parameterList = SxCreateParameterList( m_stateStack.top().context.get(), 1, "shader" );
	for( IECore::CompoundDataMap::const_iterator it=parameters.begin(); it!=parameters.end(); it++ )
	{
		if( it->first=="__handle" )
		{
			// skip the special handle parameter intended for use as the coshader handle
			continue;
		}
		switch( it->second->typeId() )
		{
			case FloatDataTypeId :
				SxSetParameter( parameterList, it->first.value().c_str(), SxFloat, (void *)&(static_cast<const FloatData *>( it->second.get() )->readable() ) );
				break;
			case IntDataTypeId :
			{
				float value = static_cast<const IntData *>( it->second.get() )->readable();
				SxSetParameter( parameterList, it->first.value().c_str(), SxFloat, &value );
				break;	
			}
			case BoolDataTypeId :
			{
				float value = static_cast<const BoolData *>( it->second.get() )->readable() ? 1.0f : 0.0f;
				SxSetParameter( parameterList, it->first.value().c_str(), SxFloat, &value );
				break;		
			}
			case V3fDataTypeId :
			{
				unsigned numParameters = SxGetNumParameters( shaderInfo );
				SxType type = SxInvalid;
				unsigned arraySize;
				for( unsigned i=0; i<numParameters; i++ )
				{
					bool varying;
					SxData defaultValue;
					const char *name = SxGetParameterInfo( shaderInfo, i, &type, &varying, &defaultValue, &arraySize );
					if( 0==strcmp( name, it->first.value().c_str() ) )
					{
						break;
					}
					else
					{
						type = SxInvalid;
					}
				}
				if( type==SxPoint || type==SxVector || type==SxNormal )
				{
					SxSetParameter( parameterList, it->first.value().c_str(), type, (void *)&(static_cast<const V3fData *>( it->second.get() )->readable() ) );
				}
				else if( type==SxFloat && arraySize==3 )
				{
					SxSetParameter( parameterList, it->first.value().c_str(), type, (void *)&(static_cast<const V3fData *>( it->second.get() )->readable() ), false, arraySize );
				}
				else
				{
					msg( Msg::Warning, "IECoreRI::SXRendererImplementation::createShader", boost::format( "Parameter \"%s\" is not a point, vector, normal or float[3] and will be ignored" ) % it->second->typeName() );
				}
				break;
			}
			case Color3fDataTypeId :
				SxSetParameter( parameterList, it->first.value().c_str(), SxColor, (void *)&(static_cast<const Color3fData *>( it->second.get() )->readable() ) );
				break;
			case M33fDataTypeId :
				SxSetParameter( parameterList, it->first.value().c_str(), SxMatrix, (void *)&(static_cast<const M33fData *>( it->second.get() )->readable() ) );
				break;
			case StringDataTypeId :
			{
				const char *s = static_cast<const StringData *>( it->second.get() )->readable().c_str();
				SxSetParameter( parameterList, it->first.value().c_str(), SxString, &s );
				break;
			}
			case StringVectorDataTypeId :
			{
				const std::vector<std::string> &strings = static_cast<const StringVectorData *>( it->second.get() )->readable();
				std::vector<const char *> charPtrs; charPtrs.resize( strings.size() );
				for( unsigned i=0; i<strings.size(); i++ )
				{
					charPtrs[i] = strings[i].c_str();
				}
				SxSetParameter( parameterList, it->first.value().c_str(), SxString, &(charPtrs[0]), false, strings.size() );
				break;
			}
			case SplineffDataTypeId :
			{
				const IECore::Splineff &spline = static_cast<const SplineffData *>( it->second.get() )->readable();
				size_t size = spline.points.size();
				if( size )
				{
					vector<float> positions( size );
					vector<float> values( size );
					size_t i = 0;
					for( IECore::Splineff::PointContainer::const_iterator sIt=spline.points.begin(); sIt!=spline.points.end(); sIt++ )
					{
						positions[i] = sIt->first;
						values[i] = sIt->second;
						i++;
					}
					string positionsName = it->first.value() + "Positions";
					string valuesName = it->first.value() + "Values";
					SxSetParameter( parameterList, positionsName.c_str(), SxFloat, &(positions[0]), false, size );
					SxSetParameter( parameterList, valuesName.c_str(), SxFloat, &(values[0]), false, size );
				}
				else
				{
					msg( Msg::Warning, "IECoreRI::SXRendererImplementation::createShader", boost::format( "SplinefColor3f parameter \"%s\" has no points and will be ignored" ) % it->second->typeName() );
				}
				break;	
			}
			case SplinefColor3fDataTypeId :
			{
				const IECore::SplinefColor3f &spline = static_cast<const SplinefColor3fData *>( it->second.get() )->readable();
				size_t size = spline.points.size();
				if( size )
				{
					vector<float> positions( size );
					vector<Color3f> values( size );
					size_t i = 0;
					for( IECore::SplinefColor3f::PointContainer::const_iterator sIt=spline.points.begin(); sIt!=spline.points.end(); sIt++ )
					{
						positions[i] = sIt->first;
						values[i] = sIt->second;
						i++;
					}
					string positionsName = it->first.value() + "Positions";
					string valuesName = it->first.value() + "Values";
					SxSetParameter( parameterList, positionsName.c_str(), SxFloat, &(positions[0]), false, size );
					SxSetParameter( parameterList, valuesName.c_str(), SxColor, &(values[0]), false, size );
				}
				else
				{
					msg( Msg::Warning, "IECoreRI::SXRendererImplementation::createShader", boost::format( "SplinefColor3f parameter \"%s\" has no points and will be ignored" ) % it->second->typeName() );
				}
				break;	
			}
			default :
				msg( Msg::Warning, "IECoreRI::SXRendererImplementation::createShader", boost::format( "Unsupported parameter type \"%s\"" ) % it->second->typeName() );
		}
	}
		
	return SxCreateShader( m_stateStack.top().context.get(), parameterList, name, handle );
}