Skip to content

Commit

Permalink
Improve Alembic plugin to read assets with ArResolver to support othe…
Browse files Browse the repository at this point in the history
…r sources except local files
  • Loading branch information
roggiezhang-nv committed Nov 7, 2024
1 parent ba1e4a2 commit a52a420
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions pxr/usd/plugin/usdAbc/alembicReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
/// \file alembicReader.cpp

#include "pxr/pxr.h"
#include "pxr/usd/ar/asset.h"
#include "pxr/usd/ar/resolvedPath.h"
#include "pxr/usd/ar/resolver.h"
#include "pxr/usd/plugin/usdAbc/alembicReader.h"
#include "pxr/usd/plugin/usdAbc/alembicUtil.h"
#include "pxr/usd/usdGeom/hermiteCurves.h"
#include "pxr/usd/usdGeom/tokens.h"
#include "pxr/usd/usdGeom/xformable.h"
#include "pxr/usd/sdf/schema.h"
#include "pxr/base/arch/fileSystem.h"
#include "pxr/base/work/threadLimits.h"
#include "pxr/base/trace/trace.h"
#include "pxr/base/tf/envSetting.h"
Expand Down Expand Up @@ -801,6 +805,8 @@ class _ReaderContext {
const ISampleSelector& selector,
const UsdAbc_AlembicDataAny& value) const;

std::string _OpenAndGetMappedFilePath(const std::string& filePath);

// Custom auto-lock that safely ignores a NULL pointer.
class _Lock {
public:
Expand Down Expand Up @@ -872,6 +878,28 @@ _ReaderContext::_ReaderContext() :
// Do nothing
}

std::string
_ReaderContext::_OpenAndGetMappedFilePath(const std::string& filePath)
{
// Open asset with Ar to support URLs other than local paths.
std::shared_ptr<ArAsset> asset =
ArGetResolver().OpenAsset(ArResolvedPath(filePath));
if (asset)
{
FILE* fileHandle = asset->GetFileUnsafe().first;
if (fileHandle)
{
// If file handle is presented, use mapped file path instead of original one.
const std::string mappedFilePath = ArchGetFileName(fileHandle);

return mappedFilePath;
}
}

// Otherwise, fallback to original asset path.
return filePath;
}

bool
_ReaderContext::Open(const std::string& filePath, std::string* errorLog,
const SdfFileFormat::FileFormatArguments& args)
Expand All @@ -883,11 +911,11 @@ _ReaderContext::Open(const std::string& filePath, std::string* errorLog,
auto abcLayers = args.find("abcLayers");
if (abcLayers != args.end()) {
for (auto&& l : TfStringSplit(abcLayers->second, ",")) {
layeredABC.emplace_back(std::move(l));
layeredABC.emplace_back(_OpenAndGetMappedFilePath(l));
}
}
}
layeredABC.emplace_back(filePath);
layeredABC.emplace_back(_OpenAndGetMappedFilePath(filePath));

#if PXR_HDF5_SUPPORT_ENABLED && !H5_HAVE_THREADSAFE
// HDF5 may not be thread-safe.
Expand Down

0 comments on commit a52a420

Please sign in to comment.