Skip to content

Commit

Permalink
[Usdview] Removed ViewSettingsDataModel's dependency on RootDataModel…
Browse files Browse the repository at this point in the history
… and added default values for default material setting.

(Internal change: 1817631)
  • Loading branch information
abau171 authored and pixar-oss committed Jan 11, 2018
1 parent 21276ef commit 1937009
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 78 deletions.
2 changes: 1 addition & 1 deletion pxr/usdImaging/lib/usdviewq/adjustDefaultMaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions pxr/usdImaging/lib/usdviewq/appController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions pxr/usdImaging/lib/usdviewq/stageView.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 #
###########
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -68,7 +61,7 @@ def test_DefaultMaterial(self):
signalDefaultMaterialChanged is emitted properly.
"""

vsDM = ViewSettingsDataModel(FakeRootDataModel(), None)
vsDM = ViewSettingsDataModel(None)
counter = SignalCounter(vsDM.signalDefaultMaterialChanged)


Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -202,7 +195,7 @@ def test_HighlightColor(self):
highlightColor.
"""

vsDM = ViewSettingsDataModel(FakeRootDataModel(), None)
vsDM = ViewSettingsDataModel(None)

# Check default.
self.assertEquals(vsDM.highlightColorName, HighlightColors.YELLOW)
Expand All @@ -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)
26 changes: 11 additions & 15 deletions pxr/usdImaging/lib/usdviewq/viewSettingsDataModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1937009

Please sign in to comment.