From f2f5e997be58d64f76a754ba703c7e0203bc0cc3 Mon Sep 17 00:00:00 2001 From: Paul Molodowitch Date: Fri, 21 Apr 2017 18:16:12 -0700 Subject: [PATCH 1/2] [usdview] add --camera cmdline arg --- pxr/usdImaging/lib/usdviewq/__init__.py | 4 ++++ pxr/usdImaging/lib/usdviewq/mainWindow.py | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pxr/usdImaging/lib/usdviewq/__init__.py b/pxr/usdImaging/lib/usdviewq/__init__.py index 30a6af5868..b6958ec147 100644 --- a/pxr/usdImaging/lib/usdviewq/__init__.py +++ b/pxr/usdImaging/lib/usdviewq/__init__.py @@ -79,6 +79,10 @@ def RegisterOptions(self, parser): dest='primPath', type=str, 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') + parser.add_argument('--mask', action='store', nargs='+', dest='populationMask', metavar='PRIMPATH', help='Limit stage population to these prims, ' diff --git a/pxr/usdImaging/lib/usdviewq/mainWindow.py b/pxr/usdImaging/lib/usdviewq/mainWindow.py index cb6e1e1124..fe550bf6d8 100644 --- a/pxr/usdImaging/lib/usdviewq/mainWindow.py +++ b/pxr/usdImaging/lib/usdviewq/mainWindow.py @@ -300,6 +300,7 @@ def __init__(self, parent, parserData): self._timeSamples = None self._stageView = None self._startingPrimCamera = None + self._startingPrimCameraName = parserData.camera self.setWindowTitle(parserData.usdFile) self._statusBar = QtGui.QStatusBar(self) @@ -2689,9 +2690,7 @@ def _refreshCameraListAndMenu(self, preserveCurrCamera): if not preserveCurrCamera: for camera in self._allSceneCameras: - # XXX This logic needs to be de-pixarified. Perhaps - # a "primaryCamera" attribute on UsdGeomCamera? - if camera.GetName() == "main_cam": + if camera.GetName() == self._startingPrimCameraName: self._startingPrimCamera = currCamera = camera if self._stageView: self._stageView.setCameraPrim(camera) From 7fa19c82f92c6154b5987a9ee544e8fcf09823bb Mon Sep 17 00:00:00 2001 From: Paul Molodowitch Date: Mon, 8 May 2017 12:42:44 -0700 Subject: [PATCH 2/2] [usdview] allow --camera arg to take full prim path --- pxr/usdImaging/lib/usdviewq/__init__.py | 40 +++++++++++++++++++-- pxr/usdImaging/lib/usdviewq/mainWindow.py | 42 +++++++++++++++++++---- 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/pxr/usdImaging/lib/usdviewq/__init__.py b/pxr/usdImaging/lib/usdviewq/__init__.py index b6958ec147..a83e01e8ab 100644 --- a/pxr/usdImaging/lib/usdviewq/__init__.py +++ b/pxr/usdImaging/lib/usdviewq/__init__.py @@ -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', @@ -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): diff --git a/pxr/usdImaging/lib/usdviewq/mainWindow.py b/pxr/usdImaging/lib/usdviewq/mainWindow.py index fe550bf6d8..52ae9e94c0 100644 --- a/pxr/usdImaging/lib/usdviewq/mainWindow.py +++ b/pxr/usdImaging/lib/usdviewq/mainWindow.py @@ -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) @@ -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: