@@ -17,18 +17,18 @@ def export_flattened(asset_stage: Usd.Stage, output_dir: str, asset_dir: str, as
1717 asset_identifier = f"{ output_path .absolute ().as_posix ()} /{ asset_stem } .{ asset_format } "
1818 usdex .core .exportLayer (layer , asset_identifier , get_authoring_metadata (), comment )
1919
20- # fix all PreviewMaterial inputs:file to ./Textures/xxx
20+ # fix all PreviewMaterial material interface asset inputs from abs to rel paths ( ./Textures/xxx)
2121 stage = Usd .Stage .Open (asset_identifier )
2222 for prim in stage .Traverse ():
23- if prim .IsA (UsdShade .Shader ):
24- shader = UsdShade .Shader (prim )
25- file_input = shader . GetInput ( "file" )
26- if file_input and file_input . Get () is not None :
27- file_path = pathlib .Path (file_input .Get ().path if hasattr (file_input .Get (), "path" ) else file_input .Get ())
28- tmpdir = pathlib .Path (tempfile .gettempdir ())
29- if file_path .is_relative_to (tmpdir ):
30- new_path = f"./{ Tokens .Textures } /{ file_path .name } "
31- file_input .Set (Sdf .AssetPath (new_path ))
23+ if prim .IsA (UsdShade .Material ):
24+ material = UsdShade .Material (prim )
25+ for input in material . GetInputs ( onlyAuthored = True ):
26+ if input . GetTypeName () == Sdf . ValueTypeNames . Asset :
27+ file_path = pathlib .Path (input .Get ().path if hasattr (input .Get (), "path" ) else input .Get ())
28+ tmpdir = pathlib .Path (tempfile .gettempdir ())
29+ if file_path .is_relative_to (tmpdir ):
30+ new_path = f"./{ Tokens .Textures } /{ file_path .name } "
31+ input .Set (Sdf .AssetPath (new_path ))
3232 stage .Save ()
3333 # copy texture to output dir
3434 temp_textures_dir = pathlib .Path (asset_dir ) / Tokens .Payload / Tokens .Textures
0 commit comments