Skip to content

Commit

Permalink
IECoreUSD : Use / for resolved paths.
Browse files Browse the repository at this point in the history
On Windows, the result of USD's `GetResolvedPath()` method returns the
resolved path using `\` between directories. This can cause problems
when doing string substition on a resolved path since the `\` will be
interpreted as the start of an escape character. Using `/` also
conforms to Cortex's standard of always using `/` for paths because they
work on all operating systems.
  • Loading branch information
ericmehl committed Jul 17, 2024
1 parent 0f34fb8 commit 566dd76
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
10.5.x.x (relative to 10.5.9.1)
========

Fixes
-----

- IECoreUSD : Asset and volume paths now use `/` in the resolved path on all operating systems.

10.5.9.1 (relative to 10.5.9.0)
========
Expand Down
4 changes: 3 additions & 1 deletion contrib/IECoreUSD/src/IECoreUSD/DataAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ IECORE_POP_DEFAULT_VISIBILITY

#include "boost/unordered_map.hpp"

#include <filesystem>

using namespace std;
using namespace pxr;
using namespace IECore;
Expand Down Expand Up @@ -144,7 +146,7 @@ IECore::DataPtr dataFromSdfAssetPath( const SdfAssetPath &assetPath, const pxr::
{
if( assetPath.GetResolvedPath().size() || !assetPath.GetAssetPath().size() || !attribute )
{
return new StringData( assetPath.GetResolvedPath() );
return new StringData( std::filesystem::path( assetPath.GetResolvedPath() ).generic_string() );
}

// Path resolution failed, for a couple of possible reasons :
Expand Down
4 changes: 3 additions & 1 deletion contrib/IECoreUSD/src/IECoreUSD/VolumeAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ IECORE_PUSH_DEFAULT_VISIBILITY
#include "pxr/usd/usdVol/openVDBAsset.h"
IECORE_POP_DEFAULT_VISIBILITY

#include <filesystem>

using namespace pxr;
using namespace IECore;
using namespace IECoreScene;
Expand Down Expand Up @@ -98,7 +100,7 @@ IECore::ObjectPtr readVolume( pxr::UsdVolVolume &volume, pxr::UsdTimeCode time,

SdfAssetPath fieldAssetPath;
fieldAsset.GetFilePathAttr().Get( &fieldAssetPath, time );
const std::string fieldFileName = fieldAssetPath.GetResolvedPath();
const std::string fieldFileName = std::filesystem::path( fieldAssetPath.GetResolvedPath() ).generic_string();

if( fileName.empty() )
{
Expand Down
25 changes: 25 additions & 0 deletions contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#
##########################################################################

import IECore

import importlib
import os
import math
Expand Down Expand Up @@ -4257,5 +4259,28 @@ def testPerPurposeModelBound( self ) :
self.assertTrue( root.child( "group" ).hasBound() )
self.assertEqual( root.child( "group" ).readBound( 0 ), imath.Box3d( imath.V3d( -1 ), imath.V3d( 1 ) ) )

def testAsetPathSlashes ( self ) :

root = IECoreScene.SceneInterface.create(
os.path.join( os.path.dirname( __file__ ), "data", "assetPathAttribute.usda" ),
IECore.IndexedIO.OpenMode.Read
)
xform = root.child( "xform" )

self.assertEqual( xform.attributeNames(), [ "render:testAsset" ] )
self.assertNotIn( "\\", xform.readAttribute( "render:testAsset", 0 ).value )

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

import IECoreVDB

fileName = os.path.dirname( __file__ ) + "/data/volume.usda"
root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Read )
child = root.child( "volume" )

vdbObject = child.readObject( 0 )
self.assertNotIn( "\\", vdbObject.fileName() )

if __name__ == "__main__":
unittest.main()

0 comments on commit 566dd76

Please sign in to comment.