Skip to content

Commit

Permalink
SceneView : Add included purposes to the drawingMode menu
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Sep 21, 2023
1 parent 888d6c0 commit e018cd8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
Improvements
------------

- Viewer : Added per-purpose control over which locations are shown in the viewer, according to their `usd:purpose` attribute.
- The Drawing Mode dropdown menu can be used to to choose the visible purposes.
- The default purposes can be specified in a startup file using `Gaffer.Metadata.registerValue( GafferSceneUI.SceneView, "drawingMode.includedPurposes.value", "userDefault", IECore.StringVectorData( [ "default", "proxy" ] ) )`.
- StandardOptions : Added `includedPurposes` plug, to control which locations are included in a render based on the value of their `usd:purpose` attribute.

API
Expand Down
28 changes: 28 additions & 0 deletions python/GafferSceneUI/SceneViewUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,34 @@ def __menuDefinition( self ) :

m.append( "/ComponentsDivider", { "divider" : True } )

includedPurposes = self.getPlug()["includedPurposes"]["value"].getValue()
includedPurposesEnabled = self.getPlug()["includedPurposes"]["enabled"].getValue()
allPurposes = [ "default", "render", "proxy", "guide" ]
for purpose in allPurposes :
newPurposes = IECore.StringVectorData( [
p for p in allPurposes
if
( p != purpose and p in includedPurposes ) or ( p == purpose and p not in includedPurposes )
] )
m.append(
"/Purposes/{}".format( purpose.capitalize() ),
{
"checkBox" : purpose in includedPurposes,
"active" : includedPurposesEnabled,
"command" : functools.partial( self.getPlug()["includedPurposes"]["value"].setValue, newPurposes ),
}
)
m.append( "/Purposes/SceneDivider", { "divider" : True } )
m.append(
"/Purposes/From Scene",
{
"checkBox" : not includedPurposesEnabled,
"command" : lambda checked : self.getPlug()["includedPurposes"]["enabled"].setValue( not checked ),
}
)

m.append( "/PurposesDivider", { "divider" : True } )

lightDrawingModePlug = self.getPlug()["light"]["drawingMode"]
for mode in ( "wireframe", "color", "texture" ) :
m.append(
Expand Down
49 changes: 30 additions & 19 deletions src/GafferSceneUI/SceneView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,9 @@ class SceneView::DrawingMode : public Signals::Trackable
DrawingMode( SceneView *view )
: m_view( view )
{
// We can implement many drawing mode controls via render options.
// They simply modify the state used to render existing
// renderables. Visualisers however, may generate different
// renderables all together and so we need to modify the in-scene
// attribute values rather than any renderer option, which will
// cause the visualisers to be re-evaluated. We use a general
// purpose CustomAttributes preprocessor to set globals attributes
// with the desired values. This allows them to be overridden at
// specific locations in the user's graph if desired.

// Global attributes preprocessor

m_preprocessor = new CustomAttributes();
m_preprocessor->globalPlug()->setValue( true );
CompoundDataPlug *attr = m_preprocessor->attributesPlug();

// View plugs controlling renderer options
// Plugs controlling OpenGL render options. We use these to
// drive `SceneGadget::setOpenGLOptions()` directly.

ValuePlugPtr drawingMode = new ValuePlug( "drawingMode" );
m_view->addChild( drawingMode );
Expand All @@ -323,9 +309,34 @@ class SceneView::DrawingMode : public Signals::Trackable
drawingMode->addChild( points );
points->addChild( new BoolPlug( "useGLPoints", Plug::In, true ) );

// View plugs controlling attribute values
// A preprocessor which modifies the scene before it is displayed by
// the SceneGadget. We use this for drawing settings that aren't
// simple OpenGL options.

m_preprocessor = new SceneProcessor();

CustomAttributesPtr customAttributes = new CustomAttributes();
m_preprocessor->addChild( customAttributes );
customAttributes->inPlug()->setInput( m_preprocessor->inPlug() );
customAttributes->globalPlug()->setValue( true );
CompoundDataPlug *attr = customAttributes->attributesPlug();

// General :
StandardOptionsPtr standardOptions = new StandardOptions();
m_preprocessor->addChild( standardOptions );
standardOptions->inPlug()->setInput( customAttributes->outPlug() );
m_preprocessor->outPlug()->setInput( standardOptions->outPlug() );

// Included purposes

auto *includedPurposesPlug = standardOptions->optionsPlug()->getChild<NameValuePlug>( "includedPurposes" );
auto viewIncludedPurposesPlug = boost::static_pointer_cast<NameValuePlug>(
includedPurposesPlug->createCounterpart( "includedPurposes", Plug::In )
);
viewIncludedPurposesPlug->enabledPlug()->setValue( true );
drawingMode->addChild( viewIncludedPurposesPlug );
includedPurposesPlug->setInput( viewIncludedPurposesPlug );

// Visualiser settings.

ValuePlugPtr visualiser = new ValuePlug( "visualiser" );
drawingMode->addChild( visualiser );
Expand Down Expand Up @@ -431,7 +442,7 @@ class SceneView::DrawingMode : public Signals::Trackable
sceneGadget()->setOpenGLOptions( options.get() );
}

CustomAttributesPtr m_preprocessor;
SceneProcessorPtr m_preprocessor;

SceneView *m_view;

Expand Down
2 changes: 2 additions & 0 deletions startup/gui/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def __sceneView( plug ) :

GafferUI.View.registerView( GafferScene.ScenePlug.staticTypeId(), __sceneView )

Gaffer.Metadata.registerValue( GafferSceneUI.SceneView, "drawingMode.includedPurposes.value", "userDefault", IECore.StringVectorData( [ "default", "proxy" ] ) )

# Add items to the viewer's right click menu

def __viewContextMenu( viewer, view, menuDefinition ) :
Expand Down

0 comments on commit e018cd8

Please sign in to comment.