Skip to content

Commit

Permalink
[usdview] allow --camera arg to take full prim path
Browse files Browse the repository at this point in the history
  • Loading branch information
pmolodo committed May 8, 2017
1 parent f2f5e99 commit 7fa19c8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 9 deletions.
40 changes: 38 additions & 2 deletions pxr/usdImaging/lib/usdviewq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ def RegisterOptions(self, parser):
help='A prim path to initially select and frame')

parser.add_argument('--camera', action='store', default="main_cam",
type=str, help='Which camera to set the view to on '
'open')
type=str, help="Which camera to set the view to on "
"open - may be given as either just the camera's "
"prim name (ie, just the last element in the prim "
"path), or as a full prim path. Note that if only "
"the prim name is used, and more than one camera "
"exists with the name, which is used will be"
"effectively random")

parser.add_argument('--mask', action='store', nargs='+',
dest='populationMask', metavar='PRIMPATH',
Expand Down Expand Up @@ -145,6 +150,37 @@ def ValidateOptions(self, arg_parse_result):
print >> sys.stderr, "WARNING: complexity %.1f is out of range [1.0, 2.0], using %.1f instead" % \
(arg_parse_result.complexity, newComplexity)
arg_parse_result.complexity = newComplexity

# convert the camera result to an sdf path, if possible, and verify
# that it is "just" a prim path
if arg_parse_result.camera:
from pxr import Sdf
camPath = Sdf.Path(arg_parse_result.camera)
if camPath.isEmpty:
print >> sys.stderr, "ERROR: invalid camera path - %r" % \
(arg_parse_result.camera,)
return False
if not camPath.IsPrimPath():
print >> sys.stderr, "ERROR: invalid camera path - must be a " \
"raw prim path, without variant " \
"selections, relational attributes, etc " \
"- got: %r" % \
(arg_parse_result.camera,)
return False

# check if it's a path, or just a name...
if camPath.name != arg_parse_result.camera:
# it's a "real" path, store the SdfPath version
if not camPath.IsAbsolutePath():
# perhaps we should error here? For now just pre-pending
# root, and printing warning...
print >> sys.stderr, "WARNING: camera path %r was not " \
"absolute, prepending %r to make " \
"it absolute" % \
(str(camPath),
str(Sdf.Path.absoluteRootPath))
camPath = camPath.MakeAbsolutePath(Sdf.Path.absoluteRootPath)
arg_parse_result.camera = camPath
return True

def __LaunchProcess(self, arg_parse_result):
Expand Down
42 changes: 35 additions & 7 deletions pxr/usdImaging/lib/usdviewq/mainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,12 @@ def __init__(self, parent, parserData):
self._timeSamples = None
self._stageView = None
self._startingPrimCamera = None
self._startingPrimCameraName = parserData.camera
if isinstance(parserData.camera, Sdf.Path):
self._startingPrimCameraName = None
self._startingPrimCameraPath = parserData.camera
else:
self._startingPrimCameraName = parserData.camera
self._startingPrimCameraPath = None

self.setWindowTitle(parserData.usdFile)
self._statusBar = QtGui.QStatusBar(self)
Expand Down Expand Up @@ -2689,12 +2694,35 @@ def _refreshCameraListAndMenu(self, preserveCurrCamera):
preserveCurrCamera = False

if not preserveCurrCamera:
for camera in self._allSceneCameras:
if camera.GetName() == self._startingPrimCameraName:
self._startingPrimCamera = currCamera = camera
if self._stageView:
self._stageView.setCameraPrim(camera)
break
cameraWasSet = False
def setCamera(camera):
self._startingPrimCamera = currCamera = camera
if self._stageView:
self._stageView.setCameraPrim(camera)
cameraWasSet = True

if self._startingPrimCameraPath:
prim = self._stage.GetPrimAtPath(self._startingPrimCameraPath)
if not prim.IsValid():
msg = sys.stderr
print >> msg, "WARNING: Camera path %r did not exist in " \
"stage" % (str(self._startingPrimCameraPath),)
self._startingPrimCameraPath = None
elif not prim.IsA(UsdGeom.Camera):
msg = sys.stderr
print >> msg, "WARNING: Camera path %r was not a " \
"UsdGeom.Camera" % \
(str(self._startingPrimCameraPath),)
self._startingPrimCameraPath = None
else:
setCamera(prim)

if not cameraWasSet and self._startingPrimCameraName:
for camera in self._allSceneCameras:
if camera.GetName() == self._startingPrimCameraName:
setCamera(camera)
break

# Now that we have the current camera and all cameras, build the menu
self._ui.menuCamera.clear()
for camera in self._allSceneCameras:
Expand Down

0 comments on commit 7fa19c8

Please sign in to comment.