Skip to content

Commit c498a77

Browse files
committed
fixup! IECoreUSD : Option for relative prototype paths inside a PointInstancer
- Rename `gafferUSDPointInstancers...` variable to reflect that it is static and doesn't reference a Gaffer environment variable. - Reduce nesting by dealing with both absolute cases in one block. - Fix snake-casing of environment variables (extra '_' between words). - Improve tests - Set environment variable for absolute test, in case the original environment contains the variable. - Add test for the case where the variable is not set. - Use `subTest` to consolidate testing code into only two functions.
1 parent 059b91c commit c498a77

File tree

2 files changed

+29
-35
lines changed

2 files changed

+29
-35
lines changed

contrib/IECoreUSD/src/IECoreUSD/PointInstancerAlgo.cpp

+7-14
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ IECore::ObjectPtr readPointInstancer( pxr::UsdGeomPointInstancer &pointInstancer
121121

122122
// Prototype paths
123123

124-
const static bool gafferUSDPointInstancersRelativeProtoypes = checkEnvFlag( "IECOREUSD_POINTINSTANCER_RELATIVEPROTOTYPES", false );
124+
const static bool g_relativePrototypes = checkEnvFlag( "IECOREUSD_POINTINSTANCER_RELATIVE_PROTOTYPES", false );
125125

126126
pxr::SdfPathVector targets;
127127
Canceller::check( canceller );
@@ -134,24 +134,17 @@ IECore::ObjectPtr readPointInstancer( pxr::UsdGeomPointInstancer &pointInstancer
134134
prototypeRoots.reserve( targets.size() );
135135
for( const auto &t : targets )
136136
{
137-
if( !gafferUSDPointInstancersRelativeProtoypes )
137+
if( !g_relativePrototypes || !t.HasPrefix( primPath ) )
138138
{
139139
prototypeRoots.push_back( t.GetString() );
140140
}
141141
else
142142
{
143-
if( t.HasPrefix( primPath ) )
144-
{
145-
// The ./ prefix shouldn't be necessary - we want to just use the abscence of a leading
146-
// slash to indicate relative paths. We can remove the prefix here once we deprecate the
147-
// env var GAFFERSCENE_INSTANCER_EXPLICITABSOLUTEPATHS and have Gaffer always require a leading
148-
// slash for absolute paths
149-
prototypeRoots.push_back( "./" + t.MakeRelativePath( primPath ).GetString() );
150-
}
151-
else
152-
{
153-
prototypeRoots.push_back( t.GetString() );
154-
}
143+
// The ./ prefix shouldn't be necessary - we want to just use the absence of a leading
144+
// slash to indicate relative paths. We can remove the prefix here once we deprecate the
145+
// GAFFERSCENE_INSTANCER_EXPLICIT_ABSOLUTE_PATHS env var and have Gaffer always require a leading
146+
// slash for absolute paths.
147+
prototypeRoots.push_back( "./" + t.MakeRelativePath( primPath ).GetString() );
155148
}
156149
}
157150

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

+22-21
Original file line numberDiff line numberDiff line change
@@ -4488,38 +4488,39 @@ def testAssetPathSlashes ( self ) :
44884488
self.assertNotIn( "\\", xform.readAttribute( "render:testAsset", 0 ).value )
44894489
self.assertTrue( pathlib.Path( xform.readAttribute( "render:testAsset", 0 ).value ).is_file() )
44904490

4491+
def _testPointInstancerRelativePrototypes( self ) :
44914492

4492-
@unittest.skipIf( os.environ.get("IECOREUSD_POINTINSTANCER_RELATIVEPROTOTYPES", "0") == "0", "Set IECOREUSD_POINTINSTANCER_RELATIVEPROTOTYPES to run relative version of this test." )
4493-
def testPointInstancerRelative( self ) :
44944493
root = IECoreScene.SceneInterface.create(
44954494
os.path.join( os.path.dirname( __file__ ), "data", "pointInstancerWeirdPrototypes.usda" ),
44964495
IECore.IndexedIO.OpenMode.Read
44974496
)
44984497
pointInstancer = root.child( "inst" )
44994498
obj = pointInstancer.readObject(0.0)
4500-
self.assertEqual( obj["prototypeRoots"].data, IECore.StringVectorData( [ './Prototypes/sphere', '/cube' ] ) )
45014499

4502-
def testPointInstancerRelativeRunner( self ) :
4503-
env = os.environ.copy()
4504-
env["IECOREUSD_POINTINSTANCER_RELATIVEPROTOTYPES"] = "1"
4500+
if os.environ.get( "IECOREUSD_POINTINSTANCER_RELATIVE_PROTOTYPES", "0" ) != "0" :
4501+
self.assertEqual( obj["prototypeRoots"].data, IECore.StringVectorData( [ './Prototypes/sphere', '/cube' ] ) )
4502+
else :
4503+
self.assertEqual( obj["prototypeRoots"].data, IECore.StringVectorData( [ '/inst/Prototypes/sphere', '/cube' ] ) )
45054504

4506-
try :
4507-
subprocess.check_output(
4508-
[ sys.executable, __file__, "USDSceneTest.testPointInstancerRelative" ],
4509-
env = env, stderr = subprocess.STDOUT
4510-
)
4511-
except subprocess.CalledProcessError as e :
4512-
self.fail( e.output )
4505+
def testPointInstancerRelativePrototypes( self ) :
45134506

4514-
def testPointInstancerAbsolute( self ) :
4515-
root = IECoreScene.SceneInterface.create(
4516-
os.path.join( os.path.dirname( __file__ ), "data", "pointInstancerWeirdPrototypes.usda" ),
4517-
IECore.IndexedIO.OpenMode.Read
4518-
)
4519-
pointInstancer = root.child( "inst" )
4520-
obj = pointInstancer.readObject(0.0)
4521-
self.assertEqual( obj["prototypeRoots"].data, IECore.StringVectorData( [ '/inst/Prototypes/sphere', '/cube' ] ) )
4507+
for relative in [ "0", "1", None ] :
4508+
4509+
with self.subTest( relative = relative ) :
45224510

4511+
env = os.environ.copy()
4512+
if relative is not None :
4513+
env["IECOREUSD_POINTINSTANCER_RELATIVE_PROTOTYPES"] = relative
4514+
else :
4515+
env.pop( "IECOREUSD_POINTINSTANCER_RELATIVE_PROTOTYPES", None )
4516+
4517+
try :
4518+
subprocess.check_output(
4519+
[ sys.executable, __file__, "USDSceneTest._testPointInstancerRelativePrototypes" ],
4520+
env = env, stderr = subprocess.STDOUT
4521+
)
4522+
except subprocess.CalledProcessError as e :
4523+
self.fail( e.output )
45234524

45244525
@unittest.skipIf( not haveVDB, "No IECoreVDB" )
45254526
def testUsdVolVolumeSlashes( self ) :

0 commit comments

Comments
 (0)