Ejemplo n.º 1
0
Imath::M44f CompoundObjectSource::computeTransform( const ScenePath &path, const Gaffer::Context *context, const GafferScene::ScenePlug *parent ) const
{
	ConstM44fDataPtr transform = entryForPath( path )->member<M44fData>( "transform" );
	if( transform )
	{
		return transform->readable();
	}
	return Imath::M44f();
}
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;
}