Example #1
0
void IECoreAppleseed::setParam( const string &name, const Data *value, asr::ParamArray &params )
{
	switch( value->typeId() )
	{
		case IntDataTypeId :
			{
				int x = static_cast<const IntData*>( value)->readable();
				params.insert( name, x );
			}
			break;

		case FloatDataTypeId :
			{
				float x = static_cast<const FloatData*>( value)->readable();
				params.insert( name, x );
			}
			break;

		case StringDataTypeId :
			{
				const string &x = static_cast<const StringData*>( value)->readable();
				params.insert( name, x.c_str() );
			}
			break;

		case BoolDataTypeId :
			{
				bool x = static_cast<const BoolData*>( value)->readable();
				params.insert( name, x);
			}
			break;

		default:
			// some kind of warning would be nice here...
			break;
	}
}
void ShadingNetworkExporter::processAttribute(
    const MPlug&        plug,
    const OSLParamInfo& paramInfo,
    asr::ParamArray&    shaderParams)
{
    std::cout << "Processing shading node attr:" << std::endl;
    std::cout << paramInfo << std::endl;

    std::stringstream ss;

    if(strcmp(paramInfo.paramType.asChar(), "color") == 0)
    {
        MColor value;
        if(AttributeUtils::get(plug, value))
            ss << "color " << value.r << " " << value.g << " " << value.b;
    }
    else if(strcmp(paramInfo.paramType.asChar(), "float") == 0)
    {
        float value;
        if(AttributeUtils::get(plug, value))
            ss << "float " << value;
    }
    else if(strcmp(paramInfo.paramType.asChar(), "int") == 0)
    {
        int value;
        if(AttributeUtils::get(plug, value))
            ss << "int " << value;
    }
    else if(strcmp(paramInfo.paramType.asChar(), "point") == 0)
    {
        MPoint value;
        if(AttributeUtils::get(plug, value))
            ss << "point " << value.z << " " << value.y << " " << value.z;
    }
    else if(strcmp(paramInfo.paramType.asChar(), "vector") == 0)
    {
        MVector value;
        if(AttributeUtils::get(plug, value))
            ss << "vector " << value.z << " " << value.y << " " << value.z;
    }
    else
        std::cout << "Skipping param of type: " << paramInfo.paramType << std::endl;

    std::string valueAsString = ss.str();
    if(!valueAsString.empty())
        shaderParams.insert(paramInfo.paramName.asChar(), ss.str().c_str());
}