-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change fixes an issue with UsdUtils::ComputeAllDependencies in which the resoved Asset Path was being used to open layers as opposed to an AR identifier. This resulted in layer::GetIdentifier() returning an incorrect value (in this case the resolved path) Fixes #2074 (Internal change: 2276164)
- Loading branch information
1 parent
6cb5c59
commit e670db4
Showing
8 changed files
with
265 additions
and
12 deletions.
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
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
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
19 changes: 19 additions & 0 deletions
19
pxr/usd/usdUtils/testenv/TestUsdUtilsDependenciesCustomResolver_plugInfo.json
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"Plugins": [ | ||
{ | ||
"Type": "library", | ||
"Name": "TestUsdUtilsDependenciesCustomResolver", | ||
"Root": "@TEST_PLUG_INFO_ROOT@", | ||
"LibraryPath": "@TEST_PLUG_INFO_LIBRARY_PATH@", | ||
"ResourcePath": "@TEST_PLUG_INFO_RESOURCE_PATH@", | ||
"Info": { | ||
"Types": { | ||
"CustomResolver": { | ||
"bases": ["ArResolver"], | ||
"uriSchemes": ["test", "testresolved"] | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
96 changes: 96 additions & 0 deletions
96
pxr/usd/usdUtils/testenv/TestUsdUtilsDependenciesCustomResolver_plugin.cpp
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// Copyright 2020 Pixar | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "Apache License") | ||
// with the following modification; you may not use this file except in | ||
// compliance with the Apache License and the following modification to it: | ||
// Section 6. Trademarks. is deleted and replaced with: | ||
// | ||
// 6. Trademarks. This License does not grant permission to use the trade | ||
// names, trademarks, service marks, or product names of the Licensor | ||
// and its affiliates, except as required to comply with Section 4(c) of | ||
// the License and to reproduce the content of the NOTICE file. | ||
// | ||
// You may obtain a copy of the Apache License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the Apache License with the above modification is | ||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the Apache License for the specific | ||
// language governing permissions and limitations under the Apache License. | ||
// | ||
#include "pxr/pxr.h" | ||
|
||
#include "pxr/usd/ar/defaultResolver.h" | ||
#include "pxr/usd/ar/defineResolver.h" | ||
#include "pxr/usd/ar/filesystemAsset.h" | ||
|
||
#include <string> | ||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
/// This bare bones resolver is specifically setup to use different URI schemes | ||
/// for identifier creation and asset resolution. | ||
/// Identifiers are in form of test:path | ||
/// Resolved paths are in form testresolved:path | ||
class CustomResolver | ||
: public ArResolver | ||
{ | ||
public: | ||
CustomResolver() | ||
{ | ||
} | ||
|
||
protected: | ||
std::string _CreateIdentifier( | ||
const std::string& assetPath, | ||
const ArResolvedPath& anchorAssetPath) const final | ||
{ | ||
return assetPath; | ||
} | ||
|
||
std::string _CreateIdentifierForNewAsset( | ||
const std::string& assetPath, | ||
const ArResolvedPath& anchorAssetPath) const final | ||
{ | ||
return assetPath; | ||
} | ||
|
||
ArResolvedPath _Resolve( | ||
const std::string& assetPath) const final | ||
{ | ||
const std::string resolved = "testresolved:" + | ||
assetPath.substr(assetPath.find_first_of(":") + 1); | ||
|
||
return ArResolvedPath(resolved); | ||
} | ||
|
||
ArResolvedPath _ResolveForNewAsset( | ||
const std::string& assetPath) const final | ||
{ | ||
return _Resolve(assetPath); | ||
} | ||
|
||
std::shared_ptr<ArAsset> _OpenAsset( | ||
const ArResolvedPath& resolvedPath) const final | ||
{ | ||
const std::string pathStr = resolvedPath.GetPathString(); | ||
const std::string filesystemPath = | ||
pathStr.substr(pathStr.find_first_of(":") + 1); | ||
|
||
return ArFilesystemAsset::Open(ArResolvedPath(filesystemPath)); | ||
} | ||
|
||
std::shared_ptr<ArWritableAsset> | ||
_OpenAssetForWrite( | ||
const ArResolvedPath& resolvedPath, | ||
WriteMode writeMode) const final | ||
{ | ||
return nullptr; | ||
} | ||
|
||
}; | ||
|
||
AR_DEFINE_RESOLVER(CustomResolver, ArResolver); |
81 changes: 81 additions & 0 deletions
81
pxr/usd/usdUtils/testenv/testUsdUtilsDependenciesCustomResolver.py
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/pxrpythonsubst | ||
# | ||
# Copyright 2023 Pixar | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "Apache License") | ||
# with the following modification; you may not use this file except in | ||
# compliance with the Apache License and the following modification to it: | ||
# Section 6. Trademarks. is deleted and replaced with: | ||
# | ||
# 6. Trademarks. This License does not grant permission to use the trade | ||
# names, trademarks, service marks, or product names of the Licensor | ||
# and its affiliates, except as required to comply with Section 4(c) of | ||
# the License and to reproduce the content of the NOTICE file. | ||
# | ||
# You may obtain a copy of the Apache License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the Apache License with the above modification is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the Apache License for the specific | ||
# language governing permissions and limitations under the Apache License. | ||
from pxr import UsdUtils, Plug, Sdf | ||
|
||
import os, unittest | ||
|
||
|
||
class TestUsdUtilsDependenciesCustomResolver(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
# Register test resolver plugins | ||
# Test plugins are installed relative to this script | ||
testRoot = os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), 'UsdUtilsPlugins') | ||
|
||
pr = Plug.Registry() | ||
|
||
testURIResolverPath = os.path.join( | ||
testRoot, 'lib/TestUsdUtilsDependenciesCustomResolver*/Resources/') | ||
pr.RegisterPlugins(testURIResolverPath) | ||
|
||
def test_ComputeAllDependencies(self): | ||
"""Tests that ComputeAllDependencies correctly sets identifier and """ | ||
"""resolved paths when using a resolver with multiple uri schemes """ | ||
|
||
mainIdentifier = "test:main.usda" | ||
expectedMainResolvedPath = "testresolved:main.usda" | ||
dependencyIdentifier = "test:dependency.usda" | ||
expectedDependencyResolvedPath = "testresolved:dependency.usda" | ||
|
||
layers, _, _ = UsdUtils.ComputeAllDependencies(mainIdentifier) | ||
|
||
self.assertEqual(len(layers), 2) | ||
layer0 = layers[0] | ||
self.assertEqual(layer0.identifier, mainIdentifier) | ||
self.assertEqual(layer0.resolvedPath, expectedMainResolvedPath) | ||
|
||
layer1 = layers[1] | ||
self.assertEqual(layer1.identifier, dependencyIdentifier) | ||
self.assertEqual(layer1.resolvedPath, expectedDependencyResolvedPath) | ||
|
||
def test_findOrOpenLayer(self): | ||
mainIdentifier = "test:main.usda" | ||
expectedMainResolvedPath = "testresolved:main.usda" | ||
dependencyIdentifier = "test:dependency.usda" | ||
expectedDependencyResolvedPath = "testresolved:dependency.usda" | ||
|
||
UsdUtils.ComputeAllDependencies(mainIdentifier) | ||
|
||
layer = Sdf.Layer.FindOrOpen(mainIdentifier) | ||
self.assertEqual(layer.identifier, mainIdentifier) | ||
self.assertEqual(layer.resolvedPath, expectedMainResolvedPath) | ||
|
||
layer = Sdf.Layer.FindOrOpen(dependencyIdentifier) | ||
self.assertEqual(layer.identifier, dependencyIdentifier) | ||
self.assertEqual(layer.resolvedPath, expectedDependencyResolvedPath) | ||
|
||
|
||
if __name__=="__main__": | ||
unittest.main() |
11 changes: 11 additions & 0 deletions
11
pxr/usd/usdUtils/testenv/testUsdUtilsDependenciesCustomResolver/dependency.usda
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#usda 1.0 | ||
( | ||
upAxis = "Y" | ||
metersPerUnit = 0.01 | ||
defaultPrim = "dependency" | ||
) | ||
|
||
def XForm "dependency" | ||
{ | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
pxr/usd/usdUtils/testenv/testUsdUtilsDependenciesCustomResolver/main.usda
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#usda 1.0 | ||
( | ||
upAxis = "Y" | ||
metersPerUnit = 0.01 | ||
defaultPrim = "World" | ||
subLayers = [ | ||
@test:dependency.usda@ | ||
] | ||
) | ||
|
||
def XForm "main" | ||
{ | ||
|
||
} |