Example #1
0
void SceneView::contextChanged( const IECore::InternedString &name )
{
	if( name.value() == "ui:scene:selectedPaths" )
	{
		// if only the selection has changed then we can just update the selection
		// on our existing scene representation.
		const StringVectorData *sc = getContext()->get<StringVectorData>( "ui:scene:selectedPaths" );
		RenderableGadget::Selection sr;
		sr.insert( sc->readable().begin(), sc->readable().end() );

		BlockedConnection blockedConnection( m_selectionChangedConnection );
		m_renderableGadget->setSelection( sr );
		return;
	}
	
	if(
		name.value().compare( 0, 3, "ui:" ) == 0 &&
		name.value() != "ui:scene:expandedPaths"
	)
	{
		// if it's just a ui context entry that has changed, and it doesn't
		// affect our expansion, then early out.
		return;
	}
	
	// the context change might affect the scene itself, so we must
	// schedule an update.
	updateRequestSignal()( this );
}
Example #2
0
void SceneView::contextChanged( const IECore::InternedString &name )
{
	if( name.value() == "ui:scene:selectedPaths" )
	{
		// If only the selection has changed then we can just update the selection
		// on our existing scene representation.
		const StringVectorData *sc = getContext()->get<StringVectorData>( "ui:scene:selectedPaths" );
		/// \todo Store selection as PathMatcherData within the context, so we don't need
		/// this conversion.
		GafferScene::PathMatcherDataPtr sg = new GafferScene::PathMatcherData;
		sg->writable().init( sc->readable().begin(), sc->readable().end() );
		m_sceneGadget->setSelection( sg );
		return;
	}
	else if( name.value() == "ui:scene:expandedPaths" )
	{
		const GafferScene::PathMatcherData *expandedPaths = getContext()->get<GafferScene::PathMatcherData>( "ui:scene:expandedPaths" );
		m_sceneGadget->setExpandedPaths( expandedPaths );
		return;
	}
	else if( boost::starts_with( name.value(), "ui:" ) )
	{
		// ui context entries shouldn't affect computation.
		return;
	}
}
Example #3
0
void Shader::NetworkBuilder::parameterValueWalk( const Shader *shaderNode, const Gaffer::Plug *parameterPlug, const IECore::InternedString &parameterName, IECore::CompoundDataMap &values )
{
	for( InputPlugIterator it( parameterPlug ); it != it.end(); ++it )
	{
		IECore::InternedString childParameterName;
		if( parameterName.string().size() )
		{
			childParameterName = parameterName.string() + "." + (*it)->getName().string();
		}
		else
		{
			childParameterName = (*it)->getName();
		}

		if( (*it)->typeId() == CompoundPlug::staticTypeId() )
		{
			parameterValueWalk( shaderNode, it->get(), childParameterName, values );
		}
		else
		{
			if( IECore::DataPtr value = shaderNode->parameterValue( it->get(), *this ) )
			{
				values[childParameterName] = value;
			}
		}
	}
}
Example #4
0
		void addParameterWalk( const Gaffer::Plug *parameter, const IECore::InternedString &parameterName, IECoreScene::Shader *shader, vector<IECoreScene::ShaderNetwork::Connection> &connections )
		{
			if( !isLeafParameter( parameter ) || parameter->parent<Node>() )
			{
				// Compound parameter - recurse
				for( InputPlugIterator it( parameter ); !it.done(); ++it )
				{
					IECore::InternedString childParameterName;
					if( parameterName.string().size() )
					{
						childParameterName = parameterName.string() + "." + (*it)->getName().string();
					}
					else
					{
						childParameterName = (*it)->getName();
					}

					addParameterWalk( it->get(), childParameterName, shader, connections );
				}
			}
			else if( const Gaffer::ArrayPlug *array = IECore::runTimeCast<const Gaffer::ArrayPlug>( parameter ) )
			{
				int i = 0;
				for( InputPlugIterator it( array ); !it.done(); ++it, ++i )
				{
					IECore::InternedString childParameterName = parameterName.string() + "[" + std::to_string( i ) + "]";
					addParameter( it->get(), childParameterName, shader, connections );
				}
			}
			else
			{
				addParameter( parameter, parameterName, shader, connections );
			}
		}
Example #5
0
IECore::ConstInternedStringVectorDataPtr ObjectSource::computeSetNames( const Gaffer::Context *context, const ScenePlug *parent ) const
{
	IECore::InternedStringVectorDataPtr result = new IECore::InternedStringVectorData;
	Gaffer::tokenize( setsPlug()->getValue(), ' ', result->writable() );
	IECore::InternedString n = standardSetName();
	if( n.string().size() )
	{
		result->writable().push_back( n );
	}
	return result;
}
Example #6
0
void Path::checkName( const IECore::InternedString &name ) const
{
	if( name.string().find( '/' ) != string::npos )
	{
		throw IECore::Exception( "Path name contains '/'." );
	}

	if( name.string().empty() )
	{
		throw IECore::Exception( "Path name is empty." );
	}
}
Example #7
0
void ScenePath::contextChanged( const IECore::InternedString &key )
{
	if( !boost::starts_with( key.c_str(), "ui:" ) )
	{
		emitPathChanged();
	}
}
Example #8
0
void NoduleLayout::nodeMetadataChanged( IECore::TypeId nodeTypeId, IECore::InternedString key, const Gaffer::Node *node )
{
	const Node *typedParent = runTimeCast<const Node>( m_parent.get() );
	if( !typedParent || !affectedByChange( typedParent, nodeTypeId, node ) )
	{
		return;
	}

	if( affectsSpacing( key, m_section ) )
	{
		updateSpacing();
	}
	if( affectsDirection( key, m_section ) )
	{
		updateDirection();
	}
	if( affectsOrientation( key, m_section ) )
	{
		updateOrientation();
	}
	if( boost::starts_with( key.string(), "noduleLayout:customGadget" ) )
	{
		updateLayout();
	}
}
Example #9
0
		void addParameterComponentConnections( const Gaffer::Plug *parameter, const IECore::InternedString &parameterName, vector<IECoreScene::ShaderNetwork::Connection> &connections )
		{
			if( !isCompoundNumericPlug( parameter ) )
			{
				return;
			}
			for( InputPlugIterator it( parameter ); !it.done(); ++it )
			{
				const Gaffer::Plug *effectiveParameter = this->effectiveParameter( it->get() );
				if( effectiveParameter && isOutputParameter( effectiveParameter ) )
				{
					const Shader *effectiveShader = static_cast<const Shader *>( effectiveParameter->node() );
					IECore::InternedString outputName;
					if( effectiveShader->outPlug()->isAncestorOf( effectiveParameter ) )
					{
						outputName = effectiveParameter->relativeName( effectiveShader->outPlug() );
					}
					IECore::InternedString inputName = parameterName.string() + "." + (*it)->getName().string();
					connections.push_back( {
						{ this->handle( effectiveShader ), outputName },
						{ IECore::InternedString(), inputName }
					} );
				}
			}
		}
Example #10
0
		void contextChanged( const IECore::InternedString &name )
		{
			if( !boost::starts_with( name.value(), "ui:" ) )
			{
				m_lookThroughCameraDirty = m_viewportCameraDirty = true;
			}
		}
Example #11
0
void CameraTool::contextChanged( const IECore::InternedString &name )
{
	if( !boost::starts_with( name.string(), "ui:" ) )
	{
		m_cameraSelectionDirty = true;
		view()->viewportGadget()->renderRequestSignal()( view()->viewportGadget() );
	}
}
Example #12
0
void ImageGadget::contextChanged( const IECore::InternedString &name )
{
	if( !boost::starts_with( name.string(), "ui:" ) )
	{
		m_dirtyFlags = AllDirty;
		requestRender();
	}
}
Example #13
0
	boost::signals::detail::unusable operator()( boost::python::object slot, ConstContextPtr context, const IECore::InternedString &name )
	{
		try
		{
			slot( IECore::constPointerCast<Context>( context ), name.value() );
		}
		catch( const error_already_set &e )
		{
			PyErr_PrintEx( 0 ); // clears the error status
		}
		return boost::signals::detail::unusable();
	}
Example #14
0
		void removeShader( const IECore::InternedString &handle )
		{
			auto it = m_nodes.find( handle );
			if( it == m_nodes.end() )
			{
				throw IECore::Exception( boost::str(
					boost::format(
						"Shader \"%1%\" not in network"
					) % handle.c_str()
				) );
			}
			removeShader( it );
		}
Example #15
0
void Set::hashSet( const IECore::InternedString &setName, const Gaffer::Context *context, const ScenePlug *parent, IECore::MurmurHash &h ) const
{
	const std::string allSets = " " + namePlug()->getValue() + " ";
	const std::string setNameToFind = " " + setName.string() + " ";
	if( allSets.find( setNameToFind ) == std::string::npos )
	{
		h = inPlug()->setPlug()->hash();
		return;
	}

	FilteredSceneProcessor::hashSet( setName, context, parent, h );
	inPlug()->setPlug()->hash( h );
	modePlug()->hash( h );
	pathMatcherPlug()->hash( h );
}
Example #16
0
		ShaderNetwork::ConnectionRange outputConnections( const IECore::InternedString &handle ) const
		{
			auto it = m_nodes.find( handle );
			if( it == m_nodes.end() )
			{
				throw IECore::Exception( boost::str(
					boost::format(
						"Source shader \"%1%\" not in network"
					) % handle.c_str()
				) );
			}

			return ConnectionRange(
				ConnectionIterator( &it->outputConnections, it->outputConnections.size() ? &*it->outputConnections.begin() : nullptr ),
				ConnectionIterator( &it->outputConnections, nullptr )
			);
		}
Example #17
0
InteractiveRender::InteractiveRender( const IECore::InternedString &rendererType, const std::string &name )
	:	Node( name ),
		m_state( Stopped )
{
	storeIndexOfNextChild( g_firstPlugIndex );
	addChild( new ScenePlug( "in" ) );
	addChild( new StringPlug( rendererType.string().empty() ? "renderer" : "__renderer", Plug::In, rendererType.string() ) );
	addChild( new IntPlug( "state", Plug::In, Stopped, Stopped, Paused, Plug::Default & ~Plug::Serialisable ) );
	addChild( new ScenePlug( "out", Plug::Out, Plug::Default & ~Plug::Serialisable ) );
	addChild( new ScenePlug( "__adaptedIn", Plug::In, Plug::Default & ~Plug::Serialisable ) );

	SceneProcessorPtr adaptors = RendererAlgo::createAdaptors();
	setChild( "__adaptors", adaptors );
	adaptors->inPlug()->setInput( inPlug() );
	adaptedInPlug()->setInput( adaptors->outPlug() );

	outPlug()->setInput( inPlug() );

	plugDirtiedSignal().connect( boost::bind( &InteractiveRender::plugDirtied, this, ::_1 ) );
}
Example #18
0
GafferScene::ConstPathMatcherDataPtr Set::computeSet( const IECore::InternedString &setName, const Gaffer::Context *context, const ScenePlug *parent ) const
{
	const std::string allSets = " " + namePlug()->getValue() + " ";
	const std::string setNameToFind = " " + setName.string() + " ";
	if( allSets.find( setNameToFind ) == std::string::npos )
	{
		return inPlug()->setPlug()->getValue();
	}

	ConstPathMatcherDataPtr pathMatcher = pathMatcherPlug()->getValue();
	switch( modePlug()->getValue() )
	{
		case Add : {
			ConstPathMatcherDataPtr inputSet = inPlug()->setPlug()->getValue();
			if( !inputSet->readable().isEmpty() )
			{
				PathMatcherDataPtr result = inputSet->copy();
				result->writable().addPaths( pathMatcher->readable() );
				return result;
			}
			// Input set empty - fall through to create mode.
		}
		case Create : {
			return pathMatcher;
		}
		case Remove :
		default : {
			ConstPathMatcherDataPtr inputSet = inPlug()->setPlug()->getValue();
			if( inputSet->readable().isEmpty() )
			{
				return inputSet;
			}
			PathMatcherDataPtr result = inputSet->copy();
			result->writable().removePaths( pathMatcher->readable() );
			return result;
		}
	}
}
Example #19
0
void NoduleLayout::plugMetadataChanged( IECore::TypeId nodeTypeId, const Gaffer::MatchPattern &plugPath, IECore::InternedString key, const Gaffer::Plug *plug )
{
	if( childAffectedByChange( m_parent.get(), nodeTypeId, plugPath, plug ) )
	{
		if(
			key == g_sectionKey || key == g_indexKey || key == g_visibleKey ||
			key == g_noduleTypeKey ||
			key == g_nodulePositionKey || key == g_noduleIndexKey
		)
		{
			updateLayout();
		}
	}

	if( const Plug *typedParent = runTimeCast<const Plug>( m_parent.get() ) )
	{
		if( affectedByChange( typedParent, nodeTypeId, plugPath, plug ) )
		{
			if( affectsSpacing( key, m_section ) )
			{
				updateSpacing();
			}
			if( affectsDirection( key, m_section ) )
			{
				updateDirection();
			}
			if( affectsOrientation( key, m_section ) )
			{
				updateOrientation();
			}
			if( boost::starts_with( key.string(), "noduleLayout:customGadget" ) )
			{
				updateLayout();
			}
		}
	}
}
Example #20
0
			const std::string &handleKey() const { return handle.string(); }
Example #21
0
const IECore::InternedString &GraphComponent::setName( const IECore::InternedString &name )
{
	// make sure the name is valid
	static boost::regex validator( "^[A-Za-z_]+[A-Za-z_0-9]*" );
	if( !regex_match( name.c_str(), validator ) )
	{
		std::string what = boost::str( boost::format( "Invalid name \"%s\"" ) % name.string() );
		throw IECore::Exception( what );
	}
	
	// make sure the name is unique
	IECore::InternedString newName = name;
	if( m_parent )
	{
		bool uniqueAlready = true;
		for( ChildContainer::const_iterator it=m_parent->m_children.begin(), eIt=m_parent->m_children.end(); it != eIt; it++ )
		{
			if( *it != this && (*it)->m_name == m_name )
			{
				uniqueAlready = false;
				break;
			}
		}
	
		if( !uniqueAlready )
		{
			// split name into a prefix and a numeric suffix. if no suffix
			// exists then it defaults to 1.
			std::string prefix;
			int suffix = numericSuffix( newName.value(), 1, &prefix );

			// iterate over all the siblings to find the minimum value for the suffix which
			// will be greater than any existing suffix.
			for( ChildContainer::const_iterator it=m_parent->m_children.begin(), eIt=m_parent->m_children.end(); it != eIt; it++ )
			{
				if( *it == this )
				{
					continue;
				}
				if( (*it)->m_name.value().compare( 0, prefix.size(), prefix ) == 0 )
				{
					char *endPtr = 0;
					long siblingSuffix = strtol( (*it)->m_name.value().c_str() + prefix.size(), &endPtr, 10 );
					if( *endPtr == '\0' )
					{
						suffix = max( suffix, (int)siblingSuffix + 1 );
					}
				}
			}
			static boost::format formatter( "%s%d" );
			newName = boost::str( formatter % prefix % suffix );
		}
	}
	
	// set the new name if it's different to the old
	if( newName==m_name )
	{
		return m_name;
	}
	
	Action::enact(
		this,
		// ok to bind raw pointers to this, because enact() guarantees
		// the lifetime of the subject.
		boost::bind( &GraphComponent::setNameInternal, this, newName ),
		boost::bind( &GraphComponent::setNameInternal, this, m_name )
	);
	
	return m_name;
}
Example #22
0
inline PathMatcher::Name::Name( IECore::InternedString name )
	: name( name ), type( name == g_ellipsis || Gaffer::hasWildcards( name.c_str() ) ? Wildcarded : Plain )
{
}
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;
}