Ejemplo n.º 1
0
IECore::ConstInternedStringVectorDataPtr SceneReader::computeChildNames( const ScenePath &path, const Gaffer::Context *context, const ScenePlug *parent ) const
{
	ConstSceneInterfacePtr s = scene( path );
	if( !s )
	{
		return parent->childNamesPlug()->defaultValue();
	}

	// get the child names
	
	InternedStringVectorDataPtr resultData = new InternedStringVectorData;
	vector<InternedString> &result = resultData->writable();
	s->childNames( result );
	
	// filter out any which don't have the right tags
	
	std::string tagsString = tagsPlug()->getValue();
	if( !tagsString.empty() )
	{
		typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
		Tokenizer tagsTokenizer( tagsString, boost::char_separator<char>( " " ) );
		
		vector<InternedString> tags;
		std::copy( tagsTokenizer.begin(), tagsTokenizer.end(), back_inserter( tags ) );
		
		vector<InternedString>::iterator newResultEnd = result.begin();
		SceneInterface::NameList childTags;
		for( vector<InternedString>::const_iterator cIt = result.begin(), cEIt = result.end(); cIt != cEIt; ++cIt )
		{
			ConstSceneInterfacePtr child = s->child( *cIt );
			childTags.clear();
			child->readTags( childTags, IECore::SceneInterface::EveryTag );
			
			bool childMatches = false;
			for( SceneInterface::NameList::const_iterator tIt = childTags.begin(), tEIt = childTags.end(); tIt != tEIt; ++tIt )
			{
				if( find( tags.begin(), tags.end(), *tIt ) != tags.end() )
				{
					childMatches = true;
					break;
				}
			}
		
			if( childMatches )
			{
				*newResultEnd++ = *cIt;
			}
		}
		
		result.erase( newResultEnd, result.end() );
	}
	
	return resultData;
}
Ejemplo n.º 2
0
Imath::M44d SceneCacheNode<BaseType>::worldTransform( const std::string &fileName, const std::string &path, double time )
{
	ConstSceneInterfacePtr scene = this->scene( fileName, SceneInterface::rootName );
	
	SceneInterface::Path p;
	SceneInterface::stringToPath( path, p );
	Imath::M44d result = scene->readTransformAsMatrix( time );
	for ( SceneInterface::Path::const_iterator it = p.begin(); scene && it != p.end(); ++it )
	{
		scene = scene->child( *it, SceneInterface::NullIfMissing );
		if ( !scene )
		{
			break;
		}
		
		result = scene->readTransformAsMatrix( time ) * result;
	}
	
	return result;
}
Ejemplo n.º 3
0
SceneInterfacePtr LinkedScene::scene( const Path &path, MissingBehaviour missingBehaviour )
{
	if ( missingBehaviour == SceneInterface::CreateIfMissing )
	{
		throw Exception( "createIfMissing is not supported!" );
	}

	SceneInterfacePtr s = m_mainScene->scene( SceneInterface::rootPath );

	Path::const_iterator pIt;
	/// first try to get as close as possible using the m_mainScene...
	for ( pIt = path.begin(); pIt != path.end(); pIt++ )
	{
		SceneInterfacePtr n = s->child( *pIt, SceneInterface::NullIfMissing );
		if ( !n )
		{
			break;
		}
		s = n;
	}
	ConstSceneInterfacePtr l = 0;
	int linkDepth = 0;
	bool atLink = false;
	bool timeRemapped = false;
	
	if ( s->hasAttribute( fileNameLinkAttribute ) && s->hasAttribute( rootLinkAttribute ) )
	{
		atLink = true;
		timeRemapped = s->hasAttribute( timeLinkAttribute );
		ConstStringDataPtr fileName = runTimeCast< const StringData >( s->readAttribute( fileNameLinkAttribute, 0 ) );
		ConstInternedStringVectorDataPtr root = runTimeCast< const InternedStringVectorData >( s->readAttribute( rootLinkAttribute, 0 ) );
		
		l = expandLink( fileName.get(), root.get(), linkDepth );
		if (!l)
		{
			atLink = false;
			timeRemapped = false;
		}
	}
	else if( s->hasAttribute( linkAttribute ) )
	{
		atLink = true;
		ConstCompoundDataPtr d = runTimeCast< const CompoundData >( s->readAttribute( linkAttribute, 0 ) );
		l = expandLink( d->member< const StringData >( g_fileName ), d->member< const InternedStringVectorData >( g_root ), linkDepth );
		if ( !l )
		{
			atLink = false;
		}
	}

	if ( pIt != path.end() )
	{
		if ( !atLink )
		{
			if ( missingBehaviour == SceneInterface::NullIfMissing )
			{
				return 0;
			}
			throw Exception( "Could not find child '" + pIt->value() + "'"  );
		}

		for ( ; pIt != path.end(); pIt++ )
		{
			l = l->child( *pIt, missingBehaviour );
			if ( !l )
			{
				return 0;
			}
		}
		atLink = false;
	}
	return new LinkedScene( s, l, linkDepth, m_readOnly, atLink, timeRemapped );
}