-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Alembic plugin to read assets with ArResolver to support other sources except local files #3302
Closed
roggiezhang-nv
wants to merge
5
commits into
PixarAnimationStudios:dev
from
roggiezhang-nv:fix_abc_file_plugin
Closed
Improve Alembic plugin to read assets with ArResolver to support other sources except local files #3302
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6dffeb3
Improve Alembic plugin to read assets with ArResolver to support othe…
roggiezhang-nv f4a8aa2
Returns original filePath if it exists locally
roggiezhang-nv d5d484e
Hold opened assets within the lifetime of _ReaderContext
roggiezhang-nv 2b26e6c
Resolve symlinks and more checks before using mapped file path
roggiezhang-nv 46e0e33
Check fileOffset
roggiezhang-nv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,23 @@ | |
/// \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" | ||
#include "pxr/base/tf/staticData.h" | ||
#include "pxr/base/tf/staticTokens.h" | ||
#include "pxr/base/tf/ostreamMethods.h" | ||
#include "pxr/base/tf/fileUtils.h" | ||
#include <Alembic/Abc/ArchiveInfo.h> | ||
#include <Alembic/Abc/IArchive.h> | ||
#include <Alembic/Abc/IObject.h> | ||
|
@@ -801,6 +806,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: | ||
|
@@ -853,6 +860,8 @@ class _ReaderContext { | |
_PrimMap _prims; | ||
Prim* _pseudoRoot; | ||
UsdAbc_TimeSamples _allTimeSamples; | ||
|
||
std::vector<std::shared_ptr<ArAsset>> _assetHolders; | ||
}; | ||
|
||
static | ||
|
@@ -872,6 +881,33 @@ _ReaderContext::_ReaderContext() : | |
// Do nothing | ||
} | ||
|
||
std::string | ||
_ReaderContext::_OpenAndGetMappedFilePath(const std::string& filePath) | ||
{ | ||
// Return as it is if it's a local path and not a symlink. | ||
if (!TfIsFile(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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also add the condition that the offset from GetFileUnsafe is not 0? |
||
{ | ||
// If file handle is presented, use mapped file path instead of original one. | ||
const std::string mappedFilePath = ArchGetFileName(fileHandle); | ||
_assetHolders.emplace_back(std::move(asset)); | ||
roggiezhang-nv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return mappedFilePath; | ||
} | ||
} | ||
} | ||
|
||
// Otherwise, fallback to original asset path. | ||
return filePath; | ||
} | ||
|
||
bool | ||
_ReaderContext::Open(const std::string& filePath, std::string* errorLog, | ||
const SdfFileFormat::FileFormatArguments& args) | ||
|
@@ -883,11 +919,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. | ||
|
@@ -1507,6 +1543,7 @@ _ReaderContext::_Clear() | |
_allTimeSamples.clear(); | ||
_instanceSources.clear(); | ||
_instances.clear(); | ||
_assetHolders.clear(); | ||
} | ||
|
||
const _ReaderContext::Prim* | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's resolve symlinks in this TfIsFile call