Skip to content
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

[usdview] add --camera cmdline arg #210

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions pxr/usdImaging/lib/usdviewq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ 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 - 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',
help='Limit stage population to these prims, '
Expand Down Expand Up @@ -141,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
43 changes: 35 additions & 8 deletions pxr/usdImaging/lib/usdviewq/mainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ def __init__(self, parent, parserData):
self._timeSamples = None
self._stageView = None
self._startingPrimCamera = None
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 @@ -2688,14 +2694,35 @@ def _refreshCameraListAndMenu(self, preserveCurrCamera):
preserveCurrCamera = False

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":
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