|
38 | 38 | #include "IECore/MessageHandler.h" |
39 | 39 |
|
40 | 40 | IECORE_PUSH_DEFAULT_VISIBILITY |
41 | | -#include "pxr/usd/sdf/schema.h" |
42 | | - |
43 | 41 | #include "pxr/base/gf/matrix3f.h" |
44 | 42 | #include "pxr/base/gf/matrix3d.h" |
45 | 43 | #include "pxr/base/gf/matrix4f.h" |
46 | 44 | #include "pxr/base/gf/matrix4d.h" |
| 45 | + |
| 46 | +#include "pxr/usd/sdf/layerUtils.h" |
| 47 | +#include "pxr/usd/sdf/schema.h" |
47 | 48 | IECORE_POP_DEFAULT_VISIBILITY |
48 | 49 |
|
49 | 50 | #include "boost/unordered_map.hpp" |
@@ -139,9 +140,46 @@ IECore::DataPtr dataFromArray( const pxr::VtValue &value, GeometricData::Interpr |
139 | 140 | return d; |
140 | 141 | } |
141 | 142 |
|
| 143 | +IECore::DataPtr dataFromSdfAssetPath( const SdfAssetPath &assetPath, const pxr::UsdAttribute *attribute = nullptr ) |
| 144 | +{ |
| 145 | + if( assetPath.GetResolvedPath().size() || !assetPath.GetAssetPath().size() || !attribute ) |
| 146 | + { |
| 147 | + return new StringData( assetPath.GetResolvedPath() ); |
| 148 | + } |
| 149 | + |
| 150 | + // Path resolution failed, for a couple of possible reasons : |
| 151 | + // |
| 152 | + // - The asset may not exist. In this case we still want to load the source |
| 153 | + // asset path so that users can debug the problem. |
| 154 | + // - The source path may have contained a `<UDIM>` token, which is not |
| 155 | + // understood by ArResolvers. USD defers all UDIM handling to UsdImaging, |
| 156 | + // which is of no use to us. We still want to load the source path |
| 157 | + // because the `<UDIM>` token will be resolved by the Cortex Renderer. |
| 158 | + // |
| 159 | + // In both cases, the source path may be relative to the layer in which |
| 160 | + // it was authored, which may be buried deep in a complex composition, so |
| 161 | + // we need to find that layer and make the path absolute. |
| 162 | + |
| 163 | + SdfLayerHandle layer; |
| 164 | + for( const auto &spec : attribute->GetPropertyStack() ) |
| 165 | + { |
| 166 | + if( |
| 167 | + spec->HasDefaultValue() || |
| 168 | + spec->GetLayer()->GetNumTimeSamplesForPath( spec->GetPath() ) |
| 169 | + ) |
| 170 | + { |
| 171 | + return new StringData( |
| 172 | + SdfComputeAssetPathRelativeToLayer( spec->GetLayer(), assetPath.GetAssetPath() ) |
| 173 | + ); |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + return new StringData(); |
| 178 | +} |
| 179 | + |
142 | 180 | IECore::DataPtr dataFromSdfAssetPath( const pxr::VtValue &value, GeometricData::Interpretation interpretation, bool arrayAccepted ) |
143 | 181 | { |
144 | | - return new StringData( value.Get<SdfAssetPath>().GetResolvedPath() ); |
| 182 | + return dataFromSdfAssetPath( value.UncheckedGet<SdfAssetPath>() ); |
145 | 183 | } |
146 | 184 |
|
147 | 185 | static const std::map<pxr::TfType, IECore::DataPtr (*)( const pxr::VtValue &, GeometricData::Interpretation, bool )> g_fromVtValueConverters = { |
@@ -281,7 +319,15 @@ IECore::DataPtr IECoreUSD::DataAlgo::fromUSD( const pxr::UsdAttribute &attribute |
281 | 319 | return nullptr; |
282 | 320 | } |
283 | 321 |
|
284 | | - return DataAlgo::fromUSD( value, attribute.GetTypeName(), arrayAccepted ); |
| 322 | + if( value.IsHolding<SdfAssetPath>() ) |
| 323 | + { |
| 324 | + // Special case to deal with resolution of UDIM textures. |
| 325 | + return dataFromSdfAssetPath( value.UncheckedGet<SdfAssetPath>(), &attribute ); |
| 326 | + } |
| 327 | + else |
| 328 | + { |
| 329 | + return DataAlgo::fromUSD( value, attribute.GetTypeName(), arrayAccepted ); |
| 330 | + } |
285 | 331 | } |
286 | 332 |
|
287 | 333 | ////////////////////////////////////////////////////////////////////////// |
|
0 commit comments