diff --git a/pxr/usdImaging/lib/usdviewq/adjustDefaultMaterial.py b/pxr/usdImaging/lib/usdviewq/adjustDefaultMaterial.py index 546c11fd1f..a4b8c1afa7 100644 --- a/pxr/usdImaging/lib/usdviewq/adjustDefaultMaterial.py +++ b/pxr/usdImaging/lib/usdviewq/adjustDefaultMaterial.py @@ -73,7 +73,7 @@ def _specularChanged(self, val): self._dataModel.defaultMaterialSpecular = val def _reset(self, unused): - self._dataModel.setDefaultMaterial(0.2, 0.1) + self._dataModel.resetDefaultMaterial() def _done(self, unused): self.close() diff --git a/pxr/usdImaging/lib/usdviewq/appController.py b/pxr/usdImaging/lib/usdviewq/appController.py index 0636e7c813..db9695bdc7 100644 --- a/pxr/usdImaging/lib/usdviewq/appController.py +++ b/pxr/usdImaging/lib/usdviewq/appController.py @@ -389,8 +389,7 @@ def __init__(self, parserData): self._startingPrimCameraPath = None self._openSettings2(parserData.defaultSettings) - self._viewSettingsDataModel = ViewSettingsDataModel( - self._rootDataModel, self._settings2) + self._viewSettingsDataModel = ViewSettingsDataModel(self._settings2) self._viewSettingsDataModel.complexity = parserData.complexity settingsPathDir = self._outputBaseDirectory() @@ -2889,7 +2888,8 @@ def _updateOnFrameChange(self, refreshUI = True): if self._stageView: # this is the part that renders if self._rootDataModel.playing: - if self._viewSettingsDataModel.drawSelHighlights: + highlightMode = self._viewSettingsDataModel.selHighlightMode + if highlightMode == SelectionHighlightModes.ALWAYS: # We don't want to resend the selection to the renderer # every frame during playback unless we are actually going # to see the selection (which is only when highlight mode is diff --git a/pxr/usdImaging/lib/usdviewq/stageView.py b/pxr/usdImaging/lib/usdviewq/stageView.py index db0d324bb0..e1ce757ba8 100644 --- a/pxr/usdImaging/lib/usdviewq/stageView.py +++ b/pxr/usdImaging/lib/usdviewq/stageView.py @@ -39,7 +39,7 @@ from pxr import CameraUtil from common import (RenderModes, ShadedRenderModes, Timer, - GetInstanceIndicesForIds) + GetInstanceIndicesForIds, SelectionHighlightModes) from rootDataModel import RootDataModel from selectionDataModel import ALL_INSTANCES, SelectionDataModel @@ -1260,14 +1260,6 @@ def backLightEnabled(self): def highlightColor(self): return (1.0,1.0,0.0,0.8) # Yellow - @property - def drawSelHighlights(self): - return self._defaultDrawSelHighlights - - @drawSelHighlights.setter - def drawSelHighlights(self, value): - self._defaultDrawSelHighlights = value - ########### # Signals # ########### @@ -2228,8 +2220,20 @@ def paintGL(self): GL.glDepthFunc(GL.GL_LEQUAL) GL.glClear(GL.GL_COLOR_BUFFER_BIT) - self.renderSinglePass(self._renderModeDict[self._dataModel.renderMode], - self._dataModel.drawSelHighlights) + highlightMode = self._dataModel.selHighlightMode + if self._rootDataModel.playing: + # Highlight mode must be ALWAYS to draw highlights during playback. + drawSelHighlights = ( + highlightMode == SelectionHighlightModes.ALWAYS) + else: + # Highlight mode can be ONLY_WHEN_PAUSED or ALWAYS to draw + # highlights when paused. + drawSelHighlights = ( + highlightMode != SelectionHighlightModes.NEVER) + + self.renderSinglePass( + self._renderModeDict[self._dataModel.renderMode], + drawSelHighlights) self.DrawAxis(viewProjectionMatrix) diff --git a/pxr/usdImaging/lib/usdviewq/testenv/testUsdviewqViewSettingsDataModel.py b/pxr/usdImaging/lib/usdviewq/testenv/testUsdviewqViewSettingsDataModel.py index 74114559df..cd4844a19a 100644 --- a/pxr/usdImaging/lib/usdviewq/testenv/testUsdviewqViewSettingsDataModel.py +++ b/pxr/usdImaging/lib/usdviewq/testenv/testUsdviewqViewSettingsDataModel.py @@ -30,13 +30,6 @@ from pxr.Usdviewq.common import CameraMaskModes, SelectionHighlightModes -class FakeRootDataModel(object): - - def __init__(self): - - self.playing = False - - class SignalCounter(object): """Counts the number of times a signal is emitted.""" @@ -68,7 +61,7 @@ def test_DefaultMaterial(self): signalDefaultMaterialChanged is emitted properly. """ - vsDM = ViewSettingsDataModel(FakeRootDataModel(), None) + vsDM = ViewSettingsDataModel(None) counter = SignalCounter(vsDM.signalDefaultMaterialChanged) @@ -138,7 +131,7 @@ def test_DefaultMaterial(self): def test_Complexity(self): """Test that complexity stays within 1.0 and 2.0.""" - vsDM = ViewSettingsDataModel(FakeRootDataModel(), None) + vsDM = ViewSettingsDataModel(None) vsDM.complexity = 1.5 self.assertEquals(vsDM.complexity, 1.5) @@ -158,7 +151,7 @@ def test_ShowMask(self): showMask_Opaque. """ - vsDM = ViewSettingsDataModel(FakeRootDataModel(), None) + vsDM = ViewSettingsDataModel(None) # Check default. self.assertEquals(vsDM.cameraMaskMode, CameraMaskModes.NONE) @@ -180,7 +173,7 @@ def test_ShowMask(self): def test_ClearColor(self): """Test that setting clearColorText changes the value of clearColor.""" - vsDM = ViewSettingsDataModel(FakeRootDataModel(), None) + vsDM = ViewSettingsDataModel(None) # Check default. self.assertEquals(vsDM.clearColorText, ClearColors.DARK_GREY) @@ -202,7 +195,7 @@ def test_HighlightColor(self): highlightColor. """ - vsDM = ViewSettingsDataModel(FakeRootDataModel(), None) + vsDM = ViewSettingsDataModel(None) # Check default. self.assertEquals(vsDM.highlightColorName, HighlightColors.YELLOW) @@ -219,42 +212,6 @@ def test_HighlightColor(self): self.assertEquals(vsDM.highlightColorName, HighlightColors.CYAN) self.assertEquals(vsDM.highlightColor, (0.0, 1.0, 1.0, 0.5)) - def test_DrawSelHighlights(self): - """Test that drawSelHighlights is set properly based on the highlight - mode and the playing state. - """ - - rootDM = FakeRootDataModel() - vsDM = ViewSettingsDataModel(rootDM, None) - - - # Check all states while paused. - - rootDM.playing = False - - vsDM.selHighlightMode = SelectionHighlightModes.NEVER - self.assertEquals(vsDM.drawSelHighlights, False) - - vsDM.selHighlightMode = SelectionHighlightModes.ONLY_WHEN_PAUSED - self.assertEquals(vsDM.drawSelHighlights, True) - - vsDM.selHighlightMode = SelectionHighlightModes.ALWAYS - self.assertEquals(vsDM.drawSelHighlights, True) - - - # Check all states while paused. - - rootDM.playing = True - - vsDM.selHighlightMode = SelectionHighlightModes.NEVER - self.assertEquals(vsDM.drawSelHighlights, False) - - vsDM.selHighlightMode = SelectionHighlightModes.ONLY_WHEN_PAUSED - self.assertEquals(vsDM.drawSelHighlights, False) - - vsDM.selHighlightMode = SelectionHighlightModes.ALWAYS - self.assertEquals(vsDM.drawSelHighlights, True) - if __name__ == "__main__": unittest.main(verbosity=2) diff --git a/pxr/usdImaging/lib/usdviewq/viewSettingsDataModel.py b/pxr/usdImaging/lib/usdviewq/viewSettingsDataModel.py index 153d79fbf5..d607cf665d 100644 --- a/pxr/usdImaging/lib/usdviewq/viewSettingsDataModel.py +++ b/pxr/usdImaging/lib/usdviewq/viewSettingsDataModel.py @@ -60,6 +60,11 @@ class HighlightColors(ConstantGroup): HighlightColors.CYAN: (0.0, 1.0, 1.0, 0.5)} +# Default values for default material components. +DEFAULT_AMBIENT = 0.2 +DEFAULT_SPECULAR = 0.1 + + class ViewSettingsDataModel(QtCore.QObject, StateSource): """Data model containing settings related to the rendered view of a USD file. @@ -68,16 +73,14 @@ class ViewSettingsDataModel(QtCore.QObject, StateSource): # emitted when any aspect of the defaultMaterial changes signalDefaultMaterialChanged = QtCore.Signal() - def __init__(self, rootDataModel, parent): + def __init__(self, parent): QtCore.QObject.__init__(self) StateSource.__init__(self, parent, "model") - self._rootDataModel = rootDataModel - self._cameraMaskColor = tuple(self.stateProperty("cameraMaskColor", default=[0.1, 0.1, 0.1, 1.0])) self._cameraReticlesColor = tuple(self.stateProperty("cameraReticlesColor", default=[0.0, 0.7, 1.0, 1.0])) - self._defaultMaterialAmbient = self.stateProperty("defaultMaterialAmbient", default=0.2) - self._defaultMaterialSpecular = self.stateProperty("defaultMaterialSpecular", default=0.1) + self._defaultMaterialAmbient = self.stateProperty("defaultMaterialAmbient", default=DEFAULT_AMBIENT) + self._defaultMaterialSpecular = self.stateProperty("defaultMaterialSpecular", default=DEFAULT_SPECULAR) self._redrawOnScrub = self.stateProperty("redrawOnScrub", default=True) self._renderMode = self.stateProperty("renderMode", default=RenderModes.SMOOTH_SHADED) self._pickMode = self.stateProperty("pickMode", default=PickModes.PRIMS) @@ -212,6 +215,9 @@ def setDefaultMaterial(self, ambient, specular): self._defaultMaterialSpecular = specular self.signalDefaultMaterialChanged.emit() + def resetDefaultMaterial(self): + self.setDefaultMaterial(DEFAULT_AMBIENT, DEFAULT_SPECULAR) + @property def complexity(self): return self._complexity @@ -520,16 +526,6 @@ def selHighlightMode(self, value): raise ValueError("Unknown highlight mode: '{}'".format(value)) self._selHighlightMode = value - @property - def drawSelHighlights(self): - if self._rootDataModel.playing: - # Highlight mode must be ALWAYS to draw highlights during playback. - return (self._selHighlightMode == SelectionHighlightModes.ALWAYS) - else: - # Highlight mode can be ONLY_WHEN_PAUSED or ALWAYS to draw - # highlights when paused. - return (self._selHighlightMode != SelectionHighlightModes.NEVER) - @property def redrawOnScrub(self): return self._redrawOnScrub