IECoreGL::ConstRenderablePtr StandardLightVisualiser::pointRays()
{
    IECoreGL::GroupPtr group = new IECoreGL::Group();
    addWireframeCurveState( group.get() );

    IECore::CompoundObjectPtr parameters = new CompoundObject;
    parameters->members()["aimType"] = new IntData( 1 );
    group->getState()->add(
        new IECoreGL::ShaderStateComponent( ShaderLoader::defaultShaderLoader(), TextureLoader::defaultTextureLoader(), faceCameraVertexSource(), "", IECoreGL::Shader::constantFragmentSource(), parameters )
    );

    IntVectorDataPtr vertsPerCurve = new IntVectorData;
    V3fVectorDataPtr p = new V3fVectorData;

    const int numRays = 8;
    for( int i = 0; i < numRays; ++i )
    {
        const float angle = M_PI * 2.0f * float(i)/(float)numRays;
        const V2f dir( cos( angle ), sin( angle ) );
        addRay( dir * .5, dir * 1, vertsPerCurve->writable(), p->writable() );
    }

    IECoreGL::CurvesPrimitivePtr curves = new IECoreGL::CurvesPrimitive( IECore::CubicBasisf::linear(), false, vertsPerCurve );
    curves->addPrimitiveVariable( "P", IECore::PrimitiveVariable( IECore::PrimitiveVariable::Vertex, p ) );
    curves->addPrimitiveVariable( "Cs", IECore::PrimitiveVariable( IECore::PrimitiveVariable::Constant, new Color3fData( Color3f( 1.0f, 0.835f, 0.07f ) ) ) );

    group->addChild( curves );

    return group;
}
void StandardLightVisualiser::addEnvLightVisualiser( GroupPtr &output, Color3f multiplier, const std::string &textureName )
{
    IECoreGL::GroupPtr sphereGroup = new IECoreGL::Group();

    Imath::M44f trans;
    trans.scale( V3f( 1, 1, -1 ) );
    trans.rotate( V3f( -0.5 * M_PI, -0.5 * M_PI, 0 ) );
    sphereGroup->setTransform( trans );

    IECoreGL::SpherePrimitivePtr sphere = new IECoreGL::SpherePrimitive();
    sphereGroup->addChild( sphere );

    IECore::CompoundObjectPtr parameters = new CompoundObject;
    parameters->members()["lightMultiplier"] = new Color3fData( multiplier );
    parameters->members()["previewOpacity"] = new FloatData( 1 );
    parameters->members()["mapSampler"] = new StringData( textureName );
    parameters->members()["defaultColor"] = new Color3fData( Color3f( textureName == "" ? 1.0f : 0.0f ) );
    sphereGroup->getState()->add(
        new IECoreGL::ShaderStateComponent( ShaderLoader::defaultShaderLoader(), TextureLoader::defaultTextureLoader(), IECoreGL::Shader::defaultVertexSource(), "", environmentLightDrawFragSource(), parameters )
    );
    sphereGroup->getState()->add(
        new IECoreGL::DoubleSidedStateComponent( false )
    );

    output->addChild( sphereGroup );
}
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 ProceduralHolderUI::unhiliteGroupChildren( const std::string &name, IECoreGL::GroupPtr group, IECoreGL::StateComponentPtr base ) const
{
	assert( base );
	assert( group );

	/// Add state so that the group hilite state doesn't propogate down the hierarchy past the given name
	IECoreGL::ConstNameStateComponentPtr n = group->getState()->get< IECoreGL::NameStateComponent >();
	if ( n && n->name() != name )
	{
		if ( m_stateMap.find( group.get() ) == m_stateMap.end() )
		{
			IECoreGL::StatePtr oldState = new IECoreGL::State( *(group->getState()) );
			assert( oldState );
			m_stateMap[ group.get() ] = oldState;
		}

		group->getState()->add( base );
		return;
	}

	const IECoreGL::Group::ChildContainer &children = group->children();
	for ( IECoreGL::Group::ChildContainer::const_iterator it = children.begin(); it != children.end(); ++it )
	{
		assert( *it );

		IECoreGL::GroupPtr childGroup = IECore::runTimeCast< IECoreGL::Group >( *it );
		if ( childGroup )
		{
			unhiliteGroupChildren( name, childGroup, base );
		}
	}
}
IECoreGL::ConstRenderablePtr StandardLightVisualiser::spotlightCone( float innerAngle, float outerAngle, float lensRadius )
{
    IECoreGL::GroupPtr group = new IECoreGL::Group();
    addWireframeCurveState( group.get() );

    group->getState()->add( new IECoreGL::CurvesPrimitive::GLLineWidth( 1.0f ) );

    IECore::CompoundObjectPtr parameters = new CompoundObject;
    parameters->members()["aimType"] = new IntData( 0 );
    group->getState()->add(
        new IECoreGL::ShaderStateComponent( ShaderLoader::defaultShaderLoader(), TextureLoader::defaultTextureLoader(), faceCameraVertexSource(), "", IECoreGL::Shader::constantFragmentSource(), parameters )
    );

    IntVectorDataPtr vertsPerCurve = new IntVectorData;
    V3fVectorDataPtr p = new V3fVectorData;
    addCone( innerAngle, lensRadius, vertsPerCurve->writable(), p->writable() );

    IECoreGL::CurvesPrimitivePtr curves = new IECoreGL::CurvesPrimitive( IECore::CubicBasisf::linear(), false, vertsPerCurve );
    curves->addPrimitiveVariable( "P", IECore::PrimitiveVariable( IECore::PrimitiveVariable::Vertex, p ) );
    curves->addPrimitiveVariable( "Cs", IECore::PrimitiveVariable( IECore::PrimitiveVariable::Constant, new Color3fData( Color3f( 1.0f, 0.835f, 0.07f ) ) ) );

    group->addChild( curves );

    if( fabs( innerAngle - outerAngle ) > 0.1 )
    {
        IECoreGL::GroupPtr outerGroup = new Group;
        outerGroup->getState()->add( new IECoreGL::CurvesPrimitive::GLLineWidth( 0.5f ) );

        IntVectorDataPtr vertsPerCurve = new IntVectorData;
        V3fVectorDataPtr p = new V3fVectorData;
        addCone( outerAngle, lensRadius, vertsPerCurve->writable(), p->writable() );

        IECoreGL::CurvesPrimitivePtr curves = new IECoreGL::CurvesPrimitive( IECore::CubicBasisf::linear(), false, vertsPerCurve );
        curves->addPrimitiveVariable( "P", IECore::PrimitiveVariable( IECore::PrimitiveVariable::Vertex, p ) );
        curves->addPrimitiveVariable( "Cs", IECore::PrimitiveVariable( IECore::PrimitiveVariable::Constant, new Color3fData( Color3f( 1.0f, 0.835f, 0.07f ) ) ) );

        outerGroup->addChild( curves );

        group->addChild( outerGroup );
    }

    return group;
}
void ProceduralHolderUI::hiliteGroups( const ProceduralHolder::ComponentToGroupMap::mapped_type &groups, IECoreGL::StateComponentPtr hilite, IECoreGL::StateComponentPtr base ) const
{
	assert( base );
	for( ProceduralHolder::ComponentToGroupMap::mapped_type::const_iterator it = groups.begin(); it != groups.end(); ++it )
	{
		unhiliteGroupChildren( it->first, it->second, base );
	}

	for( ProceduralHolder::ComponentToGroupMap::mapped_type::const_iterator it = groups.begin(); it != groups.end(); ++it )
	{
		IECoreGL::GroupPtr group = it->second;
		assert( group );

		if ( m_stateMap.find( group.get() ) == m_stateMap.end() )
		{
			IECoreGL::StatePtr oldState = new IECoreGL::State( *(group->getState()) );
			assert( oldState );
			m_stateMap[ group.get() ] = oldState;
		}

		group->getState()->add( hilite );
	}
}
IECoreGL::ConstRenderablePtr StandardLightVisualiser::ray()
{
    IECoreGL::GroupPtr group = new IECoreGL::Group();
    addWireframeCurveState( group.get() );

    IECore::CompoundObjectPtr parameters = new CompoundObject;
    parameters->members()["aimType"] = new IntData( 0 );
    group->getState()->add(
        new IECoreGL::ShaderStateComponent( ShaderLoader::defaultShaderLoader(), TextureLoader::defaultTextureLoader(), faceCameraVertexSource(), "", IECoreGL::Shader::constantFragmentSource(), parameters )
    );

    IntVectorDataPtr vertsPerCurve = new IntVectorData;
    V3fVectorDataPtr p = new V3fVectorData;
    addRay( V2f( 0 ), V2f( 1, 0 ), vertsPerCurve->writable(), p->writable() );

    IECoreGL::CurvesPrimitivePtr curves = new IECoreGL::CurvesPrimitive( IECore::CubicBasisf::linear(), false, vertsPerCurve );
    curves->addPrimitiveVariable( "P", IECore::PrimitiveVariable( IECore::PrimitiveVariable::Vertex, p ) );
    curves->addPrimitiveVariable( "Cs", IECore::PrimitiveVariable( IECore::PrimitiveVariable::Constant, new Color3fData( Color3f( 1.0f, 0.835f, 0.07f ) ) ) );

    group->addChild( curves );

    return group;
}
Beispiel #8
0
void SceneShapeUI::hiliteGroups( IECoreGL::GroupPtr group, IECoreGL::StateComponentPtr hilite, IECoreGL::StateComponentPtr base ) const
{
	assert( base );
	
	if( group )
	{
		IECoreGL::ConstNameStateComponentPtr n = group->getState()->get< IECoreGL::NameStateComponent >();
		if( n )
		{
			const std::string &name = n->name();
			unhiliteGroupChildren( name, group, base );
		}
		
		if ( m_stateMap.find( group.get() ) == m_stateMap.end() )
		{
			IECoreGL::StatePtr oldState = new IECoreGL::State( *(group->getState()) );
			assert( oldState );
			m_stateMap[ group.get() ] = oldState;
		}
	
		group->getState()->add( hilite );
	}
}
IECoreGL::ConstRenderablePtr StandardLightVisualiser::colorIndicator( const Imath::Color3f &color, bool faceCamera )
{

    float maxChannel = std::max( color[0], std::max( color[1], color[2] ) );
    float exposure = 0;
    Imath::Color3f indicatorColor = color;
    if( maxChannel > 1 )
    {
        indicatorColor = color / maxChannel;
        exposure = log( maxChannel ) / log( 2 );
    }
    IECoreGL::GroupPtr group = new IECoreGL::Group();
    IECoreGL::GroupPtr wirelessGroup = new IECoreGL::Group();

    IECore::CompoundObjectPtr parameters = new CompoundObject;
    parameters->members()["aimType"] = new IntData( 1 );
    group->getState()->add(
        new IECoreGL::ShaderStateComponent( ShaderLoader::defaultShaderLoader(), TextureLoader::defaultTextureLoader(), faceCamera ? faceCameraVertexSource() : "", "", IECoreGL::Shader::constantFragmentSource(), parameters )
    );

    wirelessGroup->getState()->add( new IECoreGL::Primitive::DrawWireframe( false ) );

    float indicatorRad = 0.3;
    int indicatorAxis = faceCamera ? 0 : 2;

    {
        IntVectorDataPtr vertsPerPoly = new IntVectorData;
        IntVectorDataPtr vertIds = new IntVectorData;
        V3fVectorDataPtr p = new V3fVectorData;

        addSolidArc( indicatorAxis, V3f( 0 ), indicatorRad, indicatorRad * 0.9, 0, 1, vertsPerPoly->writable(), vertIds->writable(), p->writable() );

        IECore::MeshPrimitivePtr mesh = new IECore::MeshPrimitive( vertsPerPoly, vertIds, "linear", p );
        mesh->variables["N"] = IECore::PrimitiveVariable( IECore::PrimitiveVariable::Constant, new V3fData( V3f( 0 ) ) );
        mesh->variables["Cs"] = IECore::PrimitiveVariable( IECore::PrimitiveVariable::Constant, new Color3fData( indicatorColor ) );
        ToGLMeshConverterPtr meshConverter = new ToGLMeshConverter( mesh );
        group->addChild( IECore::runTimeCast<IECoreGL::Renderable>( meshConverter->convert() ) );
    }
    {
        IntVectorDataPtr vertsPerPoly = new IntVectorData;
        IntVectorDataPtr vertIds = new IntVectorData;
        V3fVectorDataPtr p = new V3fVectorData;

        addSolidArc( indicatorAxis, V3f( 0 ), indicatorRad * 0.4, 0.0, 0, 1, vertsPerPoly->writable(), vertIds->writable(), p->writable() );

        for( int i = 0; i < exposure && i < 20; i++ )
        {
            float startAngle = 1 - pow( 0.875, i );
            float endAngle = 1 - pow( 0.875, std::min( i+1.0, (double)exposure ) );
            float maxEndAngle = 1 - pow( 0.875, i+1.0);
            float sectorScale = ( maxEndAngle - startAngle - 0.008 ) / ( maxEndAngle - startAngle );
            addSolidArc( indicatorAxis, V3f( 0 ), indicatorRad * 0.85, indicatorRad * 0.45, startAngle, startAngle + ( endAngle - startAngle ) * sectorScale, vertsPerPoly->writable(), vertIds->writable(), p->writable() );
        }

        IECore::MeshPrimitivePtr mesh = new IECore::MeshPrimitive( vertsPerPoly, vertIds, "linear", p );
        mesh->variables["N"] = IECore::PrimitiveVariable( IECore::PrimitiveVariable::Constant, new V3fData( V3f( 0 ) ) );
        mesh->variables["Cs"] = IECore::PrimitiveVariable( IECore::PrimitiveVariable::Constant, new Color3fData( indicatorColor ) );
        ToGLMeshConverterPtr meshConverter = new ToGLMeshConverter( mesh );
        wirelessGroup->addChild( IECore::runTimeCast<IECoreGL::Renderable>( meshConverter->convert() ) );
    }

    // For exposures greater than 20, draw an additional solid bar of a darker color at the very end, without any segment dividers
    if( exposure > 20 )
    {
        IntVectorDataPtr vertsPerPoly = new IntVectorData;
        IntVectorDataPtr vertIds = new IntVectorData;
        V3fVectorDataPtr p = new V3fVectorData;

        float startAngle = 1 - pow( 0.875, 20 );
        float endAngle = 1 - pow( 0.875, (double)exposure );
        addSolidArc( indicatorAxis, V3f( 0 ), indicatorRad * 0.85, indicatorRad * 0.45, startAngle, endAngle, vertsPerPoly->writable(), vertIds->writable(), p->writable() );

        IECore::MeshPrimitivePtr mesh = new IECore::MeshPrimitive( vertsPerPoly, vertIds, "linear", p );
        mesh->variables["N"] = IECore::PrimitiveVariable( IECore::PrimitiveVariable::Constant, new V3fData( V3f( 0 ) ) );
        mesh->variables["Cs"] = IECore::PrimitiveVariable( IECore::PrimitiveVariable::Constant, new Color3fData( 0.5f * indicatorColor ) );
        ToGLMeshConverterPtr meshConverter = new ToGLMeshConverter( mesh );
        wirelessGroup->addChild( IECore::runTimeCast<IECoreGL::Renderable>( meshConverter->convert() ) );
    }

    group->addChild( wirelessGroup );

    return group;
}