Skip to content

Commit

Permalink
Add arguments for specifying detached layers in usdview
Browse files Browse the repository at this point in the history
Detached layers in usdview can be specified using the arguments
--detachLayers, --detachLayersInclude, and --detachLayersExclude.

Fixes #1852

(Internal change: 2247862)
  • Loading branch information
sunyab authored and pixar-oss committed Sep 3, 2022
1 parent 83878e9 commit ff5c0df
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 1 deletion.
44 changes: 44 additions & 0 deletions pxr/usdImaging/bin/testusdview/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ pxr_install_test_dir(
DEST testUsdviewAlive
)

pxr_install_test_dir(
SRC testenv/testUsdviewDetachedLayers
DEST testUsdviewDetachedLayers1
)

pxr_install_test_dir(
SRC testenv/testUsdviewDetachedLayers
DEST testUsdviewDetachedLayers2
)

pxr_install_test_dir(
SRC testenv/testUsdviewDetachedLayers
DEST testUsdviewDetachedLayers3
)

pxr_install_test_dir(
SRC testenv/testUsdviewDetachedLayers
DEST testUsdviewDetachedLayers4
)

pxr_install_test_dir(
SRC testenv/testUsdviewFileArguments
DEST testUsdviewFileArguments1
Expand Down Expand Up @@ -341,6 +361,30 @@ pxr_register_test(testUsdviewAlive
EXPECTED_RETURN_CODE 0
)

pxr_register_test(testUsdviewDetachedLayers1
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/testusdview --testScript testDetachedLayers_1.py --norender --detachLayers root.usd"
EXPECTED_RETURN_CODE 0
)

pxr_register_test(testUsdviewDetachedLayers2
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/testusdview --testScript testDetachedLayers_2.py --norender --detachLayersInclude 'foo,with spaces' root.usd"
EXPECTED_RETURN_CODE 0
)

pxr_register_test(testUsdviewDetachedLayers3
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/testusdview --testScript testDetachedLayers_3.py --norender --detachLayers --detachLayersExclude 'foo,with spaces' root.usd"
EXPECTED_RETURN_CODE 0
)

pxr_register_test(testUsdviewDetachedLayers4
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/testusdview --testScript testDetachedLayers_4.py --norender root.usd"
EXPECTED_RETURN_CODE 0
)

pxr_register_test(testUsdviewFileArguments1
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/testusdview --testScript testValidFileArg.py test.usda"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/pxrpythonsubst
#
# Copyright 2022 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.
#

def testUsdviewInputFunction(appController):
from pxr import Sdf

assert Sdf.Layer.Find('root.usd').IsDetached()
assert Sdf.Layer.Find('foo.usd').IsDetached()
assert Sdf.Layer.Find('bar.usd').IsDetached()
assert Sdf.Layer.Find('with spaces.usd').IsDetached()

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/pxrpythonsubst
#
# Copyright 2022 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.
#

def testUsdviewInputFunction(appController):
from pxr import Sdf

assert not Sdf.Layer.Find('root.usd').IsDetached()
assert Sdf.Layer.Find('foo.usd').IsDetached()
assert not Sdf.Layer.Find('bar.usd').IsDetached()
assert Sdf.Layer.Find('with spaces.usd').IsDetached()

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/pxrpythonsubst
#
# Copyright 2022 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.
#

def testUsdviewInputFunction(appController):
from pxr import Sdf

assert Sdf.Layer.Find('root.usd').IsDetached()
assert not Sdf.Layer.Find('foo.usd').IsDetached()
assert Sdf.Layer.Find('bar.usd').IsDetached()
assert not Sdf.Layer.Find('with spaces.usd').IsDetached()
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/pxrpythonsubst
#
# Copyright 2022 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.
#

def testUsdviewInputFunction(appController):
from pxr import Sdf

assert not Sdf.Layer.Find('root.usd').IsDetached()
assert not Sdf.Layer.Find('foo.usd').IsDetached()
assert not Sdf.Layer.Find('bar.usd').IsDetached()
assert not Sdf.Layer.Find('with spaces.usd').IsDetached()

Binary file not shown.
36 changes: 35 additions & 1 deletion pxr/usdImaging/usdviewq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,29 @@ def RegisterOptions(self, parser):
"regex separator operator. Alternatively the "
"argument may be used multiple times.")

group = parser.add_argument_group(
'Detached Layers',
'Specify layers to be detached from their serialized data source '
'when loaded. This may increase time to load and memory usage but '
'will avoid issues like open file handles preventing other '
'processes from safely overwriting a loaded layer.')

group.add_argument(
'--detachLayers', action='store_true', help=("Detach all layers"))

group.add_argument(
'--detachLayersInclude', action='store',
metavar='PATTERN[,PATTERN...]',
help=("Detach layers with identifiers containing any of the "
"given patterns."))

group.add_argument(
'--detachLayersExclude', action='store',
metavar='PATTERN[,PATTERN,...]',
help=("Exclude layers with identifiers containing any of the "
"given patterns from the set of detached layers specified "
"by the --detachLayers or --detachLayerIncludes arguments."))

def ParseOptions(self, parser):
'''
runs the parser on the arguments
Expand All @@ -271,11 +294,22 @@ def ValidateOptions(self, arg_parse_result):
overridden, derived classes should likely first call the base method.
'''

# split arg_parse_result.populationMask into paths.
# Split arg_parse_result.populationMask into paths.
if arg_parse_result.populationMask:
arg_parse_result.populationMask = (
arg_parse_result.populationMask.replace(',', ' ').split())

# Process detached layer arguments.
if arg_parse_result.detachLayersInclude:
arg_parse_result.detachLayersInclude = [
s for s in arg_parse_result.detachLayersInclude.split(',') if s
]

if arg_parse_result.detachLayersExclude:
arg_parse_result.detachLayersExclude = [
s for s in arg_parse_result.detachLayersExclude.split(',') if s
]

# Verify that the camera path is either an absolute path, or is just
# the name of a camera.
if arg_parse_result.camera:
Expand Down
21 changes: 21 additions & 0 deletions pxr/usdImaging/usdviewq/appController.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,27 @@ def __init__(self, parserData, resolverContextFn):
self._usdviewApi = UsdviewApi(self)
if not self._noPlugins:
self._configurePlugins()

# Set up detached layers if any have been specified before opening
# the stage.
detachedLayerRules = None
if self._parserData.detachLayers:
detachedLayerRules = Sdf.Layer.DetachedLayerRules().IncludeAll()
elif self._parserData.detachLayersInclude:
detachedLayerRules = Sdf.Layer.DetachedLayerRules()
if '*' in self._parserData.detachLayersInclude:
detachedLayerRules.IncludeAll()
else:
detachedLayerRules.Include(
self._parserData.detachLayersInclude)

if detachedLayerRules is not None:
if self._parserData.detachLayersExclude:
detachedLayerRules.Exclude(
self._parserData.detachLayersExclude)

Sdf.Layer.SetDetachedLayerRules(detachedLayerRules)

# read the stage here
stage = self._openStage(
self._parserData.usdFile, self._parserData.sessionLayer,
Expand Down

0 comments on commit ff5c0df

Please sign in to comment.