void StandardLightVisualiser::addBasicLightVisualiser( ConstStringDataPtr type, GroupPtr &output, Color3f multiplier, float coneAngle, float penumbraAngle, const std::string *penumbraType, float lensRadius )
{
    bool indicatorFaceCamera = false;
    if( !type || type->readable() == "point" )
    {
        output->addChild( const_pointer_cast<IECoreGL::Renderable>( pointRays() ) );
        indicatorFaceCamera = true;
    }
    else if( type->readable() == "spot" )
    {
        float innerAngle = 0;
        float outerAngle = 0;

        if( !penumbraType || *penumbraType == "inset" )
        {
            outerAngle = coneAngle;
            innerAngle = coneAngle - 2.0f * penumbraAngle;
        }
        else if( *penumbraType == "outset" )
        {
            outerAngle = coneAngle + 2.0f * penumbraAngle;
            innerAngle = coneAngle ;
        }
        else if( *penumbraType == "absolute" )
        {
            outerAngle = coneAngle;
            innerAngle = penumbraAngle;
        }

        output->addChild( const_pointer_cast<IECoreGL::Renderable>( spotlightCone( innerAngle, outerAngle, lensRadius ) ) );
        output->addChild( const_pointer_cast<IECoreGL::Renderable>( ray() ) );
    }
    else if( type->readable() == "distant" )
    {
        for ( int i = 0; i < 3; i++ )
        {
            IECoreGL::GroupPtr rayGroup = new IECoreGL::Group();

            Imath::M44f trans;
            trans.rotate( V3f( 0, 0, 2.0 * M_PI / 3.0 * i ) );
            trans.translate( V3f( 0, 0.4, 0.5 ) );
            rayGroup->addChild( const_pointer_cast<IECoreGL::Renderable>( ray() ) );
            rayGroup->setTransform( trans );

            output->addChild( rayGroup );
        }
    }

    output->addChild( const_pointer_cast<IECoreGL::Renderable>( colorIndicator( multiplier, indicatorFaceCamera ) ) );
}
void IECoreMantra::ProceduralPrimitive::applySettings()
{
	// Shaders are hidden in the attribute stack with a ':' prefix.
	// The renderer method Shader() stores them as a full shader invocation string.
	CompoundDataMap::const_iterator s_it = m_renderer->m_attributeStack.top().attributes->readable().find(":surface");
	if ( s_it != m_renderer->m_attributeStack.top().attributes->readable().end() )
	{
		ConstStringDataPtr s = runTimeCast<const StringData>( s_it->second );
		changeSetting("surface", s->readable().c_str(), "object");
	}
	CompoundDataMap::const_iterator a_it;
	for (a_it = m_renderer->m_attributeStack.top().attributes->readable().begin(); 
		 a_it != m_renderer->m_attributeStack.top().attributes->readable().end(); a_it++)
	{
		std::string name = a_it->first;
		if ( name.compare(0, 1, ":") == 0 ) // skip internal attributes
		{
			continue;
		}
		std::string ifd, type;
		m_renderer->ifdString( a_it->second, ifd, type);
		/// \todo there are more efficient changeSetting methods  that don't use string values
		changeSetting( name.c_str(), ifd.c_str() );
	}
}
Пример #3
0
ImageDisplayDriver::ImageDisplayDriver( const Box2i &displayWindow, const Box2i &dataWindow, const vector<string> &channelNames, ConstCompoundDataPtr parameters ) :
		DisplayDriver( displayWindow, dataWindow, channelNames, parameters ),
		m_image( new ImagePrimitive( dataWindow, displayWindow ) )
{
	for ( vector<string>::const_iterator it = channelNames.begin(); it != channelNames.end(); it++ )
	{
		m_image->createChannel<float>( *it );
	}
	if( parameters )
	{
		CompoundDataMap &xData = m_image->blindData()->writable();
		const CompoundDataMap &yData = parameters->readable();
		CompoundDataMap::const_iterator iterY = yData.begin();
		for ( ; iterY != yData.end(); iterY++ )
		{
			xData[iterY->first] = iterY->second->copy();
		}
	
		ConstStringDataPtr handle = parameters->member<StringData>( "handle" );
		if( handle )
		{
			tbb::mutex::scoped_lock lock( g_poolMutex );
			g_pool[handle->readable()] = m_image;
		}
	}
}
Пример #4
0
void DisplayIop::driverCreated( NukeDisplayDriver *driver )
{
	ConstStringDataPtr portNumber = driver->parameters()->member<StringData>( "displayPort" );
	if( portNumber && boost::lexical_cast<int>( portNumber->readable() ) == m_portNumber )
	{
		firstDisplayIop()->connectToDriver( driver );
	}
}
Пример #5
0
void Display::driverCreated( GafferDisplayDriver *driver )
{
	ConstStringDataPtr portNumber = driver->parameters()->member<StringData>( "displayPort" );
	if( portNumber && boost::lexical_cast<int>( portNumber->readable() ) == portPlug()->getValue() )
	{
		setupDriver( driver );
	}
}
Пример #6
0
bool PlugAdder::canCreateConnection( const Gaffer::Plug *endpoint ) const
{
	ConstStringDataPtr noduleType = Gaffer::Metadata::value<StringData>( endpoint, IECore::InternedString( "nodule:type" ) );
	if( noduleType )
	{
		if( noduleType->readable() == "GafferUI::CompoundNodule" )
		{
			return false;
		}
	}

	return true;
}
const std::string &SpherePrimitiveEvaluator::Result::stringPrimVar( const PrimitiveVariable &pv ) const
{
	ConstStringDataPtr data = runTimeCast< const StringData >( pv.data );

	if (data)
	{
		return data->readable();
	}
	else
	{
		ConstStringVectorDataPtr data = runTimeCast< const StringVectorData >( pv.data );

		if (data)
		{
			return data->readable()[0];
		}
	}

	throw InvalidArgumentException( "Could not retrieve primvar data for SpherePrimitiveEvaluator" );
}
Пример #8
0
void Dot::setup( const Plug *plug )
{
	const Plug *originalPlug = plug;

	if( const Plug *inputPlug = plug->getInput() )
	{
		// We'd prefer to set up based on an input plug if possible - see comments
		// in DotNodeGadgetTest.testCustomNoduleTangentsPreferInputIfAvailable().
		plug = inputPlug;
	}

	Gaffer::PlugPtr in = plug->createCounterpart( g_inPlugName, Plug::In );
	Gaffer::PlugPtr out = plug->createCounterpart( g_outPlugName, Plug::Out );

	MetadataAlgo::copyColors( originalPlug , in.get() , /* overwrite = */ false );
	MetadataAlgo::copyColors( originalPlug , out.get() , /* overwrite = */ false );

	in->setFlags( Plug::Serialisable, true );
	out->setFlags( Plug::Serialisable, true );

	// Set up Metadata so our plugs appear in the right place. We must do this now rather
	// than later because the GraphEditor will add a Nodule for the plug as soon as the plug
	// is added as a child.

	ConstStringDataPtr sectionData;
	for( const Plug *metadataPlug = plug; metadataPlug; metadataPlug = metadataPlug->parent<Plug>() )
	{
		if( ( sectionData = Metadata::value<StringData>( metadataPlug, g_sectionName ) ) )
		{
			break;
		}
	}

	if( sectionData )
	{
		const std::string &section = sectionData->readable();
		std::string oppositeSection;
		if( section == "left" )
		{
			oppositeSection = "right";
		}
		else if( section == "right" )
		{
			oppositeSection = "left";
		}
		else if( section == "bottom" )
		{
			oppositeSection = "top";
		}
		else
		{
			oppositeSection = "bottom";
		}

		Metadata::registerValue(
			plug->direction() == Plug::In ? in.get() : out.get(),
			g_sectionName, sectionData
		);
		Metadata::registerValue(
			plug->direction() == Plug::In ? out.get() : in.get(),
			g_sectionName, new StringData( oppositeSection )
		);
	}

	setChild( g_inPlugName, in );
	setChild( g_outPlugName, out );

	out->setInput( in );
}
IECoreGL::ConstRenderablePtr StandardLightVisualiser::visualise( const IECore::InternedString &attributeName, const IECore::ObjectVector *shaderVector, IECoreGL::ConstStatePtr &state ) const
{
    if( !shaderVector || shaderVector->members().size() == 0 )
    {
        return NULL;
    }

    IECore::InternedString metadataTarget;
    const IECore::CompoundData *shaderParameters = NULL;
    if( const IECore::Shader *shader = IECore::runTimeCast<const IECore::Shader>( shaderVector->members().back().get() ) )
    {
        metadataTarget = attributeName.string() + ":" + shader->getName();
        shaderParameters = shader->parametersData();
    }
    else if( const IECore::Light *light = IECore::runTimeCast<const IECore::Light>( shaderVector->members().back().get() ) )
    {
        /// \todo Remove once all Light node derived classes are
        /// creating only shaders.
        metadataTarget = attributeName.string() + ":" + light->getName();
        shaderParameters = light->parametersData().get();
    }

    if( !shaderParameters )
    {
        return NULL;
    }

    ConstStringDataPtr type = Metadata::value<StringData>( metadataTarget, "type" );
    ConstM44fDataPtr orientation = Metadata::value<M44fData>( metadataTarget, "visualiserOrientation" );

    const Color3f color = parameter<Color3f>( metadataTarget, shaderParameters, "colorParameter", Color3f( 1.0f ) );
    const float intensity = parameter<float>( metadataTarget, shaderParameters, "intensityParameter", 1 );
    const float exposure = parameter<float>( metadataTarget, shaderParameters, "exposureParameter", 0 );

    const Color3f finalColor = color * intensity * pow( 2.0f, exposure );

    if( type && type->readable() == "area" )
    {
        const std::string textureName = parameter<std::string>( metadataTarget, shaderParameters, "textureNameParameter", "" );
        const bool flipNormal = parameter<bool>( metadataTarget, shaderParameters, "flipNormalParameter", 0 );
        const bool doubleSided = parameter<bool>( metadataTarget, shaderParameters, "doubleSidedParameter", 0 );
        const bool sphericalProjection = parameter<bool>( metadataTarget, shaderParameters, "sphericalProjectionParameter", 0 );

        M44f projectionTransform = parameter<M44f>( metadataTarget, shaderParameters, "projectionTransformParameter", M44f() );
        const std::vector<float> projectionTransformVector = parameter<std::vector<float> >( metadataTarget, shaderParameters, "projectionTransformParameter", std::vector<float>() );
        if( projectionTransformVector.size() == 16 )
        {
            projectionTransform = M44f( (float(*)[4])(&projectionTransformVector[0]) );
        }
        addAreaLightVisualiser( state, finalColor, textureName, flipNormal, doubleSided,
                                sphericalProjection, projectionTransform );
        return NULL;
    }

    GroupPtr result = new Group;

    const float locatorScale = parameter<float>( metadataTarget, shaderParameters, "locatorScaleParameter", 1 );
    Imath::M44f topTrans;
    if( orientation )
    {
        topTrans = orientation->readable();
    }
    topTrans.scale( V3f( locatorScale ) );
    result->setTransform( topTrans );

    if( type && type->readable() == "environment" )
    {
        const std::string textureName = parameter<std::string>( metadataTarget, shaderParameters, "textureNameParameter", "" );
        addEnvLightVisualiser( result, finalColor, textureName );
    }
    else
    {
        float coneAngle = parameter<float>( metadataTarget, shaderParameters, "coneAngleParameter", 0.0f );
        float penumbraAngle = parameter<float>( metadataTarget, shaderParameters, "penumbraAngleParameter", 0.0f );

        if( ConstStringDataPtr angleUnit = Metadata::value<StringData>( metadataTarget, "angleUnit" ) )
        {
            if( angleUnit->readable() == "radians" )
            {
                coneAngle *= 180.0 / M_PI;
                penumbraAngle *= 180 / M_PI;
            }
        }

        const std::string *penumbraType = NULL;
        ConstStringDataPtr penumbraTypeData = Metadata::value<StringData>( metadataTarget, "penumbraType" );
        if( penumbraTypeData )
        {
            penumbraType = &penumbraTypeData->readable();
        }


        float lensRadius = 0.0f;
        if( parameter<bool>( metadataTarget, shaderParameters, "lensRadiusEnableParameter", true ) )
        {
            lensRadius = parameter<float>( metadataTarget, shaderParameters, "lensRadiusParameter", 0.0f );
        }

        addBasicLightVisualiser( type, result, finalColor, coneAngle, penumbraAngle, penumbraType, lensRadius / locatorScale );
    }
    return result;
}