Skip to content

Commit 8a67e65

Browse files
Merge pull request #1483 from lucienfostier/rootTagSupportIECoreUSD
Root tag support ie core usd
2 parents 643f16a + 1812557 commit 8a67e65

File tree

6 files changed

+84
-4
lines changed

6 files changed

+84
-4
lines changed

Changes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
10.5.x.x (relative to 10.5.15.3)
22
========
33

4+
Improvements
5+
-----
6+
7+
- IECoreUSD: Added support for root level tags (reading/writing) to our IECoreUSD::SceneCacheData plugin.
8+
9+
Fixes
10+
-----
411

12+
- IECoreUSD: Fixed crash when using invalid file path with IECoreUSD::SceneCacheFileFormat.
513

614
10.5.15.3 (relative to 10.5.15.2)
715
=========

contrib/IECoreUSD/src/IECoreUSD/SceneCacheData.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void SceneCacheData::addReference( ConstSceneInterfacePtr scene, SpecData& spec,
217217
addValueClip( spec, times, actives, linkFileName, linkRootPath.GetText() );
218218
}
219219

220-
void SceneCacheData::addInternalRoot( TfTokenVector children )
220+
void SceneCacheData::addInternalRoot( TfTokenVector children, IECoreScene::ConstSceneInterfacePtr scene )
221221
{
222222
// add transform for internal root.
223223
SdfPath internalRootPath = SdfPath::AbsoluteRootPath().AppendChild( SceneCacheDataAlgo::internalRootNameToken() );
@@ -237,6 +237,26 @@ void SceneCacheData::addInternalRoot( TfTokenVector children )
237237
// steal root children
238238
internalRootSpec.fields.push_back( FieldValuePair( SdfChildrenKeys->PrimChildren, children ) );
239239

240+
// add collection
241+
FieldValuePair propertyChildren;
242+
propertyChildren.first = SdfChildrenKeys->PropertyChildren;
243+
TfTokenVector properties;
244+
245+
// we don't want to keep children tags in this case.
246+
m_collections.clear();
247+
248+
SceneInterface::NameList tags;
249+
scene->readTags( tags );
250+
for ( auto& tag : tags )
251+
{
252+
m_collections[tag].push_back( internalRootPath );
253+
}
254+
255+
addCollections( internalRootSpec, properties, internalRootPath );
256+
257+
propertyChildren.second = properties;
258+
internalRootSpec.fields.push_back( propertyChildren );
259+
240260
m_data[internalRootPath] = internalRootSpec;
241261
}
242262

@@ -344,7 +364,7 @@ void SceneCacheData::loadSceneIntoCache( ConstSceneInterfacePtr scene )
344364
// end timecode
345365
spec.fields.push_back( FieldValuePair( SdfFieldKeys->EndTimeCode, lastFrame ) );
346366

347-
addInternalRoot( children );
367+
addInternalRoot( children, scene );
348368

349369
// add internal root as single child
350370
children.clear();

contrib/IECoreUSD/src/IECoreUSD/SceneCacheData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class SceneCacheData : public SdfAbstractData
179179
void addCollections( SpecData& spec, TfTokenVector& properties, const SdfPath& primPath );
180180
void addReference( IECoreScene::ConstSceneInterfacePtr scene, SpecData& spec, TfTokenVector& children );
181181
void addValueClip( SpecData& spec, const VtVec2dArray times, const VtVec2dArray actives, const std::string& assetPath, const std::string& primPath);
182-
void addInternalRoot( TfTokenVector children );
182+
void addInternalRoot( TfTokenVector children, IECoreScene::ConstSceneInterfacePtr scene );
183183

184184
VtValue getTimeSampleMap( const SdfPath& path, const TfToken& field, const VtValue& value ) const;
185185

contrib/IECoreUSD/src/IECoreUSD/SceneCacheFileFormat.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ bool UsdSceneCacheFileFormat::WriteToFile( const SdfLayer& layer, const std::str
175175
SceneInterfacePtr outScene;
176176

177177
outScene = SdfFileFormatSharedSceneWriters::get( filePath );
178+
if ( !outScene )
179+
{
180+
IECore::msg( IECore::Msg::Error, "UsdSceneCacheFileFormat::WriteToFile", boost::format( "Invalid file path \"%s\" for layer \"%s\"." ) % filePath % layer.GetIdentifier() );
181+
return false;
182+
}
178183

179184
SceneInterface::NameList childNames;
180185
usdScene->childNames( childNames );
@@ -370,6 +375,18 @@ void UsdSceneCacheFileFormat::writeLocation(
370375
}
371376
}
372377
}
378+
// internal root is mapped to the SceneInterface root '/'
379+
else
380+
{
381+
SceneInterface::NameList tags;
382+
inChild->readTags( tags );
383+
// round trip internal tag name
384+
for ( auto& tag : tags )
385+
{
386+
tag = SceneCacheDataAlgo::fromInternalName( tag );
387+
}
388+
outChild->writeTags( tags );
389+
}
373390

374391
// recursion
375392
SceneInterface::NameList grandChildNames;

contrib/IECoreUSD/src/IECoreUSD/SdfFileFormatSharedSceneWriters.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "SdfFileFormatSharedSceneWriters.h"
3636

3737
#include "IECore/LRUCache.h"
38+
#include "IECore/MessageHandler.h"
3839

3940
using namespace IECore;
4041
using namespace IECoreScene;
@@ -61,7 +62,15 @@ class Cache : public SceneLRUCache
6162

6263
static SceneInterfacePtr fileCacheGetter( const std::string &fileName, size_t &cost )
6364
{
64-
SceneInterfacePtr result = SceneInterface::create( fileName, IECore::IndexedIO::Write );
65+
SceneInterfacePtr result = nullptr;
66+
try
67+
{
68+
result = SceneInterface::create( fileName, IECore::IndexedIO::Write );
69+
}
70+
catch ( ... )
71+
{
72+
IECore::msg( IECore::Msg::Error, "SdfFileFormatSharedSceneWriters::SceneLRUCache", boost::format( "Unable to open file path \"%s\" for writing IndexedIo data." ) % fileName );
73+
}
6574
cost = 1;
6675
return result;
6776
}

contrib/IECoreUSD/test/IECoreUSD/SceneCacheFileFormatTest.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ def testTagsLoadedAsCollections( self ):
320320
# includes
321321
fileName = os.path.join( self.temporaryDirectory(), "testUSDTags.scc" )
322322
m = IECoreScene.SceneCache( fileName, IECore.IndexedIO.OpenMode.Write )
323+
m.writeTags( ["geoId:chessy"] )
323324
t = m.createChild( "t" )
324325
s = t.createChild( "s" )
325326
t.writeTags( ["t1", "all", "asset-(12)"] )
@@ -330,6 +331,16 @@ def testTagsLoadedAsCollections( self ):
330331
stage = pxr.Usd.Stage.Open( fileName )
331332
root = stage.GetPseudoRoot()
332333

334+
tagInternalRootPrim = root.GetPrimAtPath( f"/{IECoreUSD.SceneCacheDataAlgo.internalRootName()}" )
335+
self.assertEqual(
336+
tagInternalRootPrim.GetRelationship(
337+
"collection:{}:includes".format(
338+
IECoreUSD.SceneCacheDataAlgo.toInternalName( "geoId:chessy" )
339+
)
340+
).GetTargets(),
341+
[ pxr.Sdf.Path( f"/{IECoreUSD.SceneCacheDataAlgo.internalRootName()}" ) ]
342+
)
343+
333344
tagPrim = root.GetPrimAtPath( "/{}/t".format( IECoreUSD.SceneCacheDataAlgo.internalRootName() ) )
334345
self.assertTrue( tagPrim )
335346

@@ -346,6 +357,10 @@ def testTagsLoadedAsCollections( self ):
346357
stage.Export( exportPath )
347358

348359
scene = IECoreScene.SharedSceneInterfaces.get( exportPath )
360+
# check root tags
361+
self.assertTrue( "geoId:chessy" in scene.readTags() )
362+
363+
# check children tags
349364
for tag, paths in tags.items():
350365
for path in paths:
351366
child = scene.scene( IECoreScene.SceneInterface.stringToPath( path ) )
@@ -939,6 +954,17 @@ def testSceneWrite( self ):
939954
stage.Export( exportPath )
940955
self.assertTrue( os.path.exists( exportPath ) )
941956

957+
# invalid path
958+
invalidExportPath = os.path.join( self.temporaryDirectory(), "invalid", "invalid.scc" )
959+
with IECore.CapturingMessageHandler() as mh :
960+
stage.Export( invalidExportPath )
961+
962+
self.assertEqual( len( mh.messages ), 2 )
963+
self.assertEqual( mh.messages[0].level, IECore.Msg.Level.Error )
964+
self.assertEqual( mh.messages[0].context, "SdfFileFormatSharedSceneWriters::SceneLRUCache" )
965+
self.assertEqual( mh.messages[1].level, IECore.Msg.Level.Error )
966+
self.assertEqual( mh.messages[1].context, "UsdSceneCacheFileFormat::WriteToFile" )
967+
942968
# root
943969
layer = pxr.Sdf.Layer.FindOrOpen( linkFileName )
944970

0 commit comments

Comments
 (0)