From e7165144ca602dade469f49b557925a8b78b755d Mon Sep 17 00:00:00 2001 From: davidsminor Date: Wed, 27 Mar 2013 10:15:29 -0700 Subject: [PATCH 1/3] SceneProcedural now renders general VisibleRenderables --- Changes | 2 ++ src/GafferScene/SceneProcedural.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Changes b/Changes index cb654f15327..7347737417e 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,5 @@ +* SceneProcedural now renders general VisibleRenderables too... + * Added base classes Executable and Despatcher and two derived Node classes: ExecutableNode and ExecutableOpHolder. * Added an enabled/disabled plug to all SceneNodes. Nodes with no inputs output an empty scene when disabled, and SceneProcessors output the first input unchanged. The enabled/disabled state can be toggled using the node right click menu or the "d" hotkey in the Graph Editor. diff --git a/src/GafferScene/SceneProcedural.cpp b/src/GafferScene/SceneProcedural.cpp index d38d6ede998..3c39728643b 100644 --- a/src/GafferScene/SceneProcedural.cpp +++ b/src/GafferScene/SceneProcedural.cpp @@ -277,6 +277,11 @@ void SceneProcedural::render( RendererPtr renderer ) const } break; // no motion blur for these chappies. } + else if( const VisibleRenderable* renderable = runTimeCast< const VisibleRenderable >( object.get() ) ) + { + renderable->render( renderer ); + break; // no motion blur for these chappies. + } } } From 2e5ae3e29cffd601e9b7a4b292a2568cb57f0294 Mon Sep 17 00:00:00 2001 From: davidsminor Date: Mon, 1 Apr 2013 12:26:25 -0700 Subject: [PATCH 2/3] Scene reader/writer now convert the context time to seconds using a hard coded framerate. Also removed the SceneReader::cache() in favor of IECore::SharedSceneInterfaces, and made the reader ignore a couple of attributes automatically written by the SceneCache, to fix a test failure --- include/GafferScene/SceneReader.h | 2 + python/GafferSceneTest/SceneReadWriteTest.py | 8 +- src/GafferScene/SceneReader.cpp | 144 +++++-------------- src/GafferScene/SceneWriter.cpp | 11 +- 4 files changed, 50 insertions(+), 115 deletions(-) diff --git a/include/GafferScene/SceneReader.h b/include/GafferScene/SceneReader.h index 91f8521f296..c3ecdb15ecd 100644 --- a/include/GafferScene/SceneReader.h +++ b/include/GafferScene/SceneReader.h @@ -51,6 +51,8 @@ class SceneReader : public FileSource virtual ~SceneReader(); IE_CORE_DECLARERUNTIMETYPEDEXTENSION( SceneReader, SceneReaderTypeId, FileSource ) + + static const double s_frameRate; protected : diff --git a/python/GafferSceneTest/SceneReadWriteTest.py b/python/GafferSceneTest/SceneReadWriteTest.py index f1f8001282a..8ada851ff1d 100644 --- a/python/GafferSceneTest/SceneReadWriteTest.py +++ b/python/GafferSceneTest/SceneReadWriteTest.py @@ -215,15 +215,15 @@ def writeAnimatedSCC( self ) : for time in [ 0.5, 1, 1.5, 2, 5, 10 ] : matrix = IECore.M44d.createTranslated( IECore.V3d( 1, time, 0 ) ) - sc1.writeTransform( IECore.M44dData( matrix ), time ) + sc1.writeTransform( IECore.M44dData( matrix ), float( time ) / 24 ) mesh["Cd"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Uniform, IECore.V3fVectorData( [ IECore.V3f( time, 1, 0 ) ] * 6 ) ) - sc2.writeObject( mesh, time ) + sc2.writeObject( mesh, float( time ) / 24 ) matrix = IECore.M44d.createTranslated( IECore.V3d( 2, time, 0 ) ) - sc2.writeTransform( IECore.M44dData( matrix ), time ) + sc2.writeTransform( IECore.M44dData( matrix ), float( time ) / 24 ) matrix = IECore.M44d.createTranslated( IECore.V3d( 3, time, 0 ) ) - sc3.writeTransform( IECore.M44dData( matrix ), time ) + sc3.writeTransform( IECore.M44dData( matrix ), float( time ) / 24 ) def testAnimatedScene( self ) : diff --git a/src/GafferScene/SceneReader.cpp b/src/GafferScene/SceneReader.cpp index 65b31925ab4..4368319dcbd 100644 --- a/src/GafferScene/SceneReader.cpp +++ b/src/GafferScene/SceneReader.cpp @@ -41,7 +41,9 @@ #include "IECore/FileIndexedIO.h" #include "IECore/LRUCache.h" #include "IECore/SceneInterface.h" +#include "IECore/SharedSceneInterfaces.h" #include "IECore/InternedString.h" +#include "IECore/SceneCache.h" #include "Gaffer/Context.h" #include "GafferScene/SceneReader.h" @@ -53,96 +55,13 @@ using namespace GafferScene; IE_CORE_DEFINERUNTIMETYPED( SceneReader ); -////////////////////////////////////////////////////////////////////////// -// SceneReader::Cache Implementation -////////////////////////////////////////////////////////////////////////// - -class SceneReader::Cache -{ - - private : - - IE_CORE_FORWARDDECLARE( FileAndMutex ) - - public : - - Cache() - : m_fileCache( fileCacheGetter, 200 ) - { - }; - - /// This class provides access to a particular location within - /// the SceneInterface, and ensures that access is threadsafe by holding - /// a mutex on the file. - class Entry : public IECore::RefCounted - { - - public : - - SceneInterface *sceneInterface() - { - return m_entry; - } - - private : - - Entry( FileAndMutexPtr fileAndMutex ) - : m_fileAndMutex( fileAndMutex ), m_lock( m_fileAndMutex->mutex ) - { - } - - FileAndMutexPtr m_fileAndMutex; - tbb::mutex::scoped_lock m_lock; - SceneInterfacePtr m_entry; - - friend class Cache; - - }; - - IE_CORE_DECLAREPTR( Entry ) - - EntryPtr entry( const std::string &fileName, const ScenePath &scenePath ) - { - FileAndMutexPtr f = m_fileCache.get( fileName ); - EntryPtr result = new Entry( f ); // this locks the mutex for us - result->m_entry = result->m_fileAndMutex->file->scene( scenePath ); - return result; - } - - void clear() - { - m_fileCache.clear(); - } - - private : - - class FileAndMutex : public IECore::RefCounted - { - public : - - typedef tbb::mutex Mutex; - Mutex mutex; - SceneInterfacePtr file; - - }; - - static FileAndMutexPtr fileCacheGetter( const std::string &fileName, size_t &cost ) - { - FileAndMutexPtr result = new FileAndMutex; - result->file = SceneInterface::create( fileName, IndexedIO::Read ); - cost = 1; - return result; - } - - typedef LRUCache FileCache; - FileCache m_fileCache; - -}; - ////////////////////////////////////////////////////////////////////////// // SceneReader implementation ////////////////////////////////////////////////////////////////////////// +/// \todo hard coded framerate should be replaced with a getTime() method on Gaffer::Context or something +const double SceneReader::s_frameRate( 24 ); + SceneReader::SceneReader( const std::string &name ) : FileSource( name ) { @@ -161,8 +80,10 @@ Imath::Box3f SceneReader::computeBound( const ScenePath &path, const Gaffer::Con return Box3f(); } - Cache::EntryPtr entry = cache().entry( fileName, path ); - Box3d b = entry->sceneInterface()->readBound( context->getFrame() ); + ConstSceneInterfacePtr s = SharedSceneInterfaces::get( fileName ); + s = s->scene( path ); + + Box3d b = s->readBound( context->getFrame() / s_frameRate ); if( b.isEmpty() ) { @@ -180,8 +101,10 @@ Imath::M44f SceneReader::computeTransform( const ScenePath &path, const Gaffer:: return M44f(); } - Cache::EntryPtr entry = cache().entry( fileName, path ); - M44d t = entry->sceneInterface()->readTransformAsMatrix( context->getFrame() ); + ConstSceneInterfacePtr s = SharedSceneInterfaces::get( fileName ); + s = s->scene( path ); + + M44d t = s->readTransformAsMatrix( context->getFrame() / s_frameRate ); return M44f( t[0][0], t[0][1], t[0][2], t[0][3], @@ -199,16 +122,28 @@ IECore::ConstCompoundObjectPtr SceneReader::computeAttributes( const ScenePath & return parent->attributesPlug()->defaultValue(); } - Cache::EntryPtr entry = cache().entry( fileName, path ); + + ConstSceneInterfacePtr s = SharedSceneInterfaces::get( fileName ); + s = s->scene( path ); SceneInterface::NameList nameList; - entry->sceneInterface()->readAttributeNames( nameList ); + s->readAttributeNames( nameList ); CompoundObjectPtr result = new CompoundObject; for( SceneInterface::NameList::iterator it = nameList.begin(); it != nameList.end(); ++it ) { - result->members()[ std::string( *it ) ] = entry->sceneInterface()->readAttribute( *it, context->getFrame() ); + // these internal attributes should be ignored: + if( *it == SceneCache::animatedObjectTopologyAttribute ) + { + continue; + } + if( *it == SceneCache::animatedObjectPrimVarsAttribute ) + { + continue; + } + + result->members()[ std::string( *it ) ] = s->readAttribute( *it, context->getFrame() / s_frameRate ); } return result; @@ -222,12 +157,14 @@ IECore::ConstObjectPtr SceneReader::computeObject( const ScenePath &path, const return parent->objectPlug()->defaultValue(); } - Cache::EntryPtr entry = cache().entry( fileName, path ); + ConstSceneInterfacePtr s = SharedSceneInterfaces::get( fileName ); + s = s->scene( path ); + ObjectPtr o; - if( entry->sceneInterface()->hasObject() ) + if( s->hasObject() ) { - ObjectPtr o = entry->sceneInterface()->readObject( context->getFrame() ); + ObjectPtr o = s->readObject( context->getFrame() / s_frameRate ); return o? o : parent->objectPlug()->defaultValue(); } @@ -243,10 +180,11 @@ IECore::ConstInternedStringVectorDataPtr SceneReader::computeChildNames( const S return parent->childNamesPlug()->defaultValue(); } - Cache::EntryPtr entry = cache().entry( fileName, path ); + ConstSceneInterfacePtr s = SharedSceneInterfaces::get( fileName ); + s = s->scene( path ); InternedStringVectorDataPtr result = new InternedStringVectorData; - entry->sceneInterface()->childNames( result->writable() ); + s->childNames( result->writable() ); return result; } @@ -256,12 +194,6 @@ IECore::ConstCompoundObjectPtr SceneReader::computeGlobals( const Gaffer::Contex return parent->globalsPlug()->defaultValue(); } -SceneReader::Cache &SceneReader::cache() -{ - static Cache c; - return c; -} - void SceneReader::plugSet( Gaffer::Plug *plug ) { // this clears the cache every time the refresh count is updated, so you don't get entries @@ -270,7 +202,7 @@ void SceneReader::plugSet( Gaffer::Plug *plug ) // way of doing this! if( plug == refreshCountPlug() ) { - cache().clear(); + SharedSceneInterfaces::clear(); } } @@ -278,5 +210,5 @@ void SceneReader::plugSet( Gaffer::Plug *plug ) void SceneReader::hash( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const { FileSource::hash( output, context, h ); - h.append( context->getFrame() ); + h.append( context->getFrame() / s_frameRate ); } diff --git a/src/GafferScene/SceneWriter.cpp b/src/GafferScene/SceneWriter.cpp index d29ae47efdb..0f97fedbbb6 100644 --- a/src/GafferScene/SceneWriter.cpp +++ b/src/GafferScene/SceneWriter.cpp @@ -35,6 +35,7 @@ ////////////////////////////////////////////////////////////////////////// #include "GafferScene/SceneWriter.h" +#include "GafferScene/SceneReader.h" #include "Gaffer/Context.h" #include "Gaffer/ScriptNode.h" @@ -101,25 +102,25 @@ void SceneWriter::writeLocation( GafferScene::ScenePlug *scenePlug, const SceneP ConstCompoundObjectPtr attributes = scenePlug->attributesPlug()->getValue(); for( CompoundObject::ObjectMap::const_iterator it = attributes->members().begin(), eIt = attributes->members().end(); it != eIt; it++ ) { - output->writeAttribute( it->first, it->second.get(), script->context()->getFrame() ); + output->writeAttribute( it->first, it->second.get(), script->context()->getFrame() / SceneReader::s_frameRate ); } if( scenePath.empty() ) { ConstCompoundObjectPtr globals = scenePlug->globalsPlug()->getValue(); - output->writeAttribute( "gaffer:globals", globals, script->context()->getFrame() ); + output->writeAttribute( "gaffer:globals", globals, script->context()->getFrame() / SceneReader::s_frameRate ); } ConstObjectPtr object = scenePlug->objectPlug()->getValue(); if( object->typeId() != IECore::NullObjectTypeId && scenePath.size() > 0 ) { - output->writeObject( object, script->context()->getFrame() ); + output->writeObject( object, script->context()->getFrame() / SceneReader::s_frameRate ); } Imath::Box3f b = scenePlug->boundPlug()->getValue(); - output->writeBound( Imath::Box3d( Imath::V3f( b.min ), Imath::V3f( b.max ) ), script->context()->getFrame() ); + output->writeBound( Imath::Box3d( Imath::V3f( b.min ), Imath::V3f( b.max ) ), script->context()->getFrame() / SceneReader::s_frameRate ); if( scenePath.size() ) { @@ -131,7 +132,7 @@ void SceneWriter::writeLocation( GafferScene::ScenePlug *scenePlug, const SceneP t[3][0], t[3][1], t[3][2], t[3][3] ); - output->writeTransform( new IECore::M44dData( transform ), script->context()->getFrame() ); + output->writeTransform( new IECore::M44dData( transform ), script->context()->getFrame() / SceneReader::s_frameRate ); } ConstInternedStringVectorDataPtr childNames = scenePlug->childNamesPlug()->getValue(); From 354a696b86982a36261b32dc3564cbdcf3a4f23f Mon Sep 17 00:00:00 2001 From: davidsminor Date: Mon, 1 Apr 2013 14:38:23 -0700 Subject: [PATCH 3/3] reader/writer code tweaks --- include/GafferScene/SceneReader.h | 2 +- include/GafferScene/SceneWriter.h | 3 ++- python/GafferSceneTest/SceneReadWriteTest.py | 18 +++++++++--------- src/GafferScene/SceneReader.cpp | 12 ++++++------ src/GafferScene/SceneWriter.cpp | 13 ++++++++----- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/include/GafferScene/SceneReader.h b/include/GafferScene/SceneReader.h index c3ecdb15ecd..89282c896ba 100644 --- a/include/GafferScene/SceneReader.h +++ b/include/GafferScene/SceneReader.h @@ -52,7 +52,6 @@ class SceneReader : public FileSource IE_CORE_DECLARERUNTIMETYPEDEXTENSION( SceneReader, SceneReaderTypeId, FileSource ) - static const double s_frameRate; protected : @@ -74,6 +73,7 @@ class SceneReader : public FileSource class Cache; static Cache &cache(); + static const double g_frameRate; }; } // namespace GafferScene diff --git a/include/GafferScene/SceneWriter.h b/include/GafferScene/SceneWriter.h index 7ef6f1ec534..3a2f8a87f09 100644 --- a/include/GafferScene/SceneWriter.h +++ b/include/GafferScene/SceneWriter.h @@ -70,7 +70,8 @@ class SceneWriter : public Gaffer::Node void writeLocation( GafferScene::ScenePlug *scenePlug, const ScenePlug::ScenePath &scenePath, IECore::SceneInterface *output ); static size_t g_firstPlugIndex; - + + static const double g_frameRate; }; } // namespace GafferScene diff --git a/python/GafferSceneTest/SceneReadWriteTest.py b/python/GafferSceneTest/SceneReadWriteTest.py index 8ada851ff1d..8808e91cf7b 100644 --- a/python/GafferSceneTest/SceneReadWriteTest.py +++ b/python/GafferSceneTest/SceneReadWriteTest.py @@ -212,18 +212,18 @@ def writeAnimatedSCC( self ) : sc3.writeObject( mesh, time ) sc3.writeTransform( IECore.M44dData(), time ) - for time in [ 0.5, 1, 1.5, 2, 5, 10 ] : + for frame in [ 0.5, 1, 1.5, 2, 5, 10 ] : - matrix = IECore.M44d.createTranslated( IECore.V3d( 1, time, 0 ) ) - sc1.writeTransform( IECore.M44dData( matrix ), float( time ) / 24 ) + matrix = IECore.M44d.createTranslated( IECore.V3d( 1, frame, 0 ) ) + sc1.writeTransform( IECore.M44dData( matrix ), float( frame ) / 24 ) - mesh["Cd"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Uniform, IECore.V3fVectorData( [ IECore.V3f( time, 1, 0 ) ] * 6 ) ) - sc2.writeObject( mesh, float( time ) / 24 ) - matrix = IECore.M44d.createTranslated( IECore.V3d( 2, time, 0 ) ) - sc2.writeTransform( IECore.M44dData( matrix ), float( time ) / 24 ) + mesh["Cd"] = IECore.PrimitiveVariable( IECore.PrimitiveVariable.Interpolation.Uniform, IECore.V3fVectorData( [ IECore.V3f( frame, 1, 0 ) ] * 6 ) ) + sc2.writeObject( mesh, float( frame ) / 24 ) + matrix = IECore.M44d.createTranslated( IECore.V3d( 2, frame, 0 ) ) + sc2.writeTransform( IECore.M44dData( matrix ), float( frame ) / 24 ) - matrix = IECore.M44d.createTranslated( IECore.V3d( 3, time, 0 ) ) - sc3.writeTransform( IECore.M44dData( matrix ), float( time ) / 24 ) + matrix = IECore.M44d.createTranslated( IECore.V3d( 3, frame, 0 ) ) + sc3.writeTransform( IECore.M44dData( matrix ), float( frame ) / 24 ) def testAnimatedScene( self ) : diff --git a/src/GafferScene/SceneReader.cpp b/src/GafferScene/SceneReader.cpp index 4368319dcbd..693d1330f5b 100644 --- a/src/GafferScene/SceneReader.cpp +++ b/src/GafferScene/SceneReader.cpp @@ -60,7 +60,7 @@ IE_CORE_DEFINERUNTIMETYPED( SceneReader ); ////////////////////////////////////////////////////////////////////////// /// \todo hard coded framerate should be replaced with a getTime() method on Gaffer::Context or something -const double SceneReader::s_frameRate( 24 ); +const double SceneReader::g_frameRate( 24 ); SceneReader::SceneReader( const std::string &name ) : FileSource( name ) @@ -83,7 +83,7 @@ Imath::Box3f SceneReader::computeBound( const ScenePath &path, const Gaffer::Con ConstSceneInterfacePtr s = SharedSceneInterfaces::get( fileName ); s = s->scene( path ); - Box3d b = s->readBound( context->getFrame() / s_frameRate ); + Box3d b = s->readBound( context->getFrame() / g_frameRate ); if( b.isEmpty() ) { @@ -104,7 +104,7 @@ Imath::M44f SceneReader::computeTransform( const ScenePath &path, const Gaffer:: ConstSceneInterfacePtr s = SharedSceneInterfaces::get( fileName ); s = s->scene( path ); - M44d t = s->readTransformAsMatrix( context->getFrame() / s_frameRate ); + M44d t = s->readTransformAsMatrix( context->getFrame() / g_frameRate ); return M44f( t[0][0], t[0][1], t[0][2], t[0][3], @@ -143,7 +143,7 @@ IECore::ConstCompoundObjectPtr SceneReader::computeAttributes( const ScenePath & continue; } - result->members()[ std::string( *it ) ] = s->readAttribute( *it, context->getFrame() / s_frameRate ); + result->members()[ std::string( *it ) ] = s->readAttribute( *it, context->getFrame() / g_frameRate ); } return result; @@ -164,7 +164,7 @@ IECore::ConstObjectPtr SceneReader::computeObject( const ScenePath &path, const if( s->hasObject() ) { - ObjectPtr o = s->readObject( context->getFrame() / s_frameRate ); + ObjectPtr o = s->readObject( context->getFrame() / g_frameRate ); return o? o : parent->objectPlug()->defaultValue(); } @@ -210,5 +210,5 @@ void SceneReader::plugSet( Gaffer::Plug *plug ) void SceneReader::hash( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const { FileSource::hash( output, context, h ); - h.append( context->getFrame() / s_frameRate ); + h.append( context->getFrame() / g_frameRate ); } diff --git a/src/GafferScene/SceneWriter.cpp b/src/GafferScene/SceneWriter.cpp index 0f97fedbbb6..366adce49c6 100644 --- a/src/GafferScene/SceneWriter.cpp +++ b/src/GafferScene/SceneWriter.cpp @@ -49,6 +49,9 @@ using namespace GafferScene; IE_CORE_DEFINERUNTIMETYPED( SceneWriter ); +/// \todo hard coded framerate should be replaced with a getTime() method on Gaffer::Context or something +const double SceneWriter::g_frameRate( 24 ); + size_t SceneWriter::g_firstPlugIndex = 0; SceneWriter::SceneWriter( const std::string &name ) @@ -102,25 +105,25 @@ void SceneWriter::writeLocation( GafferScene::ScenePlug *scenePlug, const SceneP ConstCompoundObjectPtr attributes = scenePlug->attributesPlug()->getValue(); for( CompoundObject::ObjectMap::const_iterator it = attributes->members().begin(), eIt = attributes->members().end(); it != eIt; it++ ) { - output->writeAttribute( it->first, it->second.get(), script->context()->getFrame() / SceneReader::s_frameRate ); + output->writeAttribute( it->first, it->second.get(), script->context()->getFrame() / g_frameRate ); } if( scenePath.empty() ) { ConstCompoundObjectPtr globals = scenePlug->globalsPlug()->getValue(); - output->writeAttribute( "gaffer:globals", globals, script->context()->getFrame() / SceneReader::s_frameRate ); + output->writeAttribute( "gaffer:globals", globals, script->context()->getFrame() / g_frameRate ); } ConstObjectPtr object = scenePlug->objectPlug()->getValue(); if( object->typeId() != IECore::NullObjectTypeId && scenePath.size() > 0 ) { - output->writeObject( object, script->context()->getFrame() / SceneReader::s_frameRate ); + output->writeObject( object, script->context()->getFrame() / g_frameRate ); } Imath::Box3f b = scenePlug->boundPlug()->getValue(); - output->writeBound( Imath::Box3d( Imath::V3f( b.min ), Imath::V3f( b.max ) ), script->context()->getFrame() / SceneReader::s_frameRate ); + output->writeBound( Imath::Box3d( Imath::V3f( b.min ), Imath::V3f( b.max ) ), script->context()->getFrame() / g_frameRate ); if( scenePath.size() ) { @@ -132,7 +135,7 @@ void SceneWriter::writeLocation( GafferScene::ScenePlug *scenePlug, const SceneP t[3][0], t[3][1], t[3][2], t[3][3] ); - output->writeTransform( new IECore::M44dData( transform ), script->context()->getFrame() / SceneReader::s_frameRate ); + output->writeTransform( new IECore::M44dData( transform ), script->context()->getFrame() / g_frameRate ); } ConstInternedStringVectorDataPtr childNames = scenePlug->childNamesPlug()->getValue();