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

Viewport hide objects #5381

Merged
merged 2 commits into from
Jul 11, 2023
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
6 changes: 6 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
1.2.x.x (relative to 1.2.9.0)
=======

Improvements
------------

- EditScopeUI : Added the ability to turn off visibility of selected objects in the viewer using the <kbd>Ctrl</kbd>+<kbd>H</kbd> shortcut.

Fixes
-----

Expand All @@ -9,6 +14,7 @@ Fixes
- Fixed bug causing the cursor position to be reset to the end if the number of digits in the plug value changed while incrementing/decrementing with the keyboard up/down arrow keys.
- Fixed bug causing the cursor position to be reset to the end when incrementing an animated plug.
- Fixed intermittent `---` values when drag-changing an animated plug value.
- EditScopes : Fixed bug where the enabled state of `AttributeEdits`, `OptionEdits` and `SetMembershipEdits` did not have any effect. This fix will only apply to newly created `AttributeEdits`, `OptionEdits` and `SetMembershipEdits`.

1.2.9.0 (relative to 1.2.8.0)
=======
Expand Down
39 changes: 20 additions & 19 deletions doc/source/Interface/ControlsAndShortcuts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,25 +227,26 @@ Pin to numeric bookmark | {kbd}`1` … {kbd}`9`

### 3D scenes ###

Action | Control or shortcut
-----------------------------------------------------|--------------------
Tumble | {kbd}`Alt` + {{leftClick}} and drag
Tumble, fine precision | Hold {kbd}`Shift` during action
Select objects | {{leftClick}} and drag marquee, then release
Add/remove object from selection | {kbd}`Ctrl` + {{leftClick}}
Add objects to selection | {kbd}`Shift` + {{leftClick}} and drag marquee, then release
Deselect objects | {kbd}`Ctrl` + {{leftClick}} and drag marquee, then release
Expand selection | {kbd}`↓`
Fully expand selection | {kbd}`Shift` + {kbd}`↓`
Collapse selection | {kbd}`↑`
Edit source node of selection | {kbd}`Alt` + {kbd}`E`
Edit tweaks node for selection | {kbd}`Alt` + {kbd}`Shift` + {kbd}`E`
Fit clipping planes to scene | {{rightClick}} > *Clipping Planes* > *Fit To Scene*
Fit clipping planes to selection | {{rightClick}} > *Clipping Planes* > *Fit To Selection*<br>or<br>{kbd}`Ctrl` + {kbd}`K`
Frame view, and fit clipping planes | {kbd}`Ctrl` + {kbd}`F`
Reset clipping planes | {{rightClick}} > *Clipping Planes* > *Default*
Toggle Inspector | {kbd}`I`
Prune selected objects from current EditScope | {kbd}`Ctrl` + {kbd}`Delete`<br>or<br>{kbd}`Ctrl` + {kbd}`Backspace`
Action | Control or shortcut
-----------------------------------------------------------------|--------------------
Tumble | {kbd}`Alt` + {{leftClick}} and drag
Tumble, fine precision | Hold {kbd}`Shift` during action
Select objects | {{leftClick}} and drag marquee, then release
Add/remove object from selection | {kbd}`Ctrl` + {{leftClick}}
Add objects to selection | {kbd}`Shift` + {{leftClick}} and drag marquee, then release
Deselect objects | {kbd}`Ctrl` + {{leftClick}} and drag marquee, then release
Expand selection | {kbd}`↓`
Fully expand selection | {kbd}`Shift` + {kbd}`↓`
Collapse selection | {kbd}`↑`
Edit source node of selection | {kbd}`Alt` + {kbd}`E`
Edit tweaks node for selection | {kbd}`Alt` + {kbd}`Shift` + {kbd}`E`
Fit clipping planes to scene | {{rightClick}} > *Clipping Planes* > *Fit To Scene*
Fit clipping planes to selection | {{rightClick}} > *Clipping Planes* > *Fit To Selection*<br>or<br>{kbd}`Ctrl` + {kbd}`K`
Frame view, and fit clipping planes | {kbd}`Ctrl` + {kbd}`F`
Reset clipping planes | {{rightClick}} > *Clipping Planes* > *Default*
Toggle Inspector | {kbd}`I`
Prune selected objects from current EditScope | {kbd}`Ctrl` + {kbd}`Delete`<br>or<br>{kbd}`Ctrl` + {kbd}`Backspace`
Turn off visibility for selected objects from current EditScope | {kbd}`Ctrl` + {kbd}`H`

### Transform tools ###

Expand Down
8 changes: 8 additions & 0 deletions python/GafferSceneTest/EditScopeAlgoTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def testPruning( self ) :
self.assertFalse( GafferScene.EditScopeAlgo.getPruned( scope, "/group/cube" ) )
self.assertEqual( len( list( GafferScene.SceneProcessor.Range( scope ) ) ), 1 )
self.assertEqual( scope["PruningEdits"]["paths"].getValue(), IECore.StringVectorData( [ "/group/plane" ] ) )
self.assertEqual( scope["PruningEdits"]["Prune"]["enabled"].getInput(), scope["PruningEdits"]["enabled"] )
self.assertFalse( GafferScene.SceneAlgo.exists( scope["out"], "/group/plane" ) )
self.assertTrue( GafferScene.SceneAlgo.exists( scope["out"], "/group/cube" ) )

Expand Down Expand Up @@ -162,6 +163,7 @@ def testTransform( self ) :
self.assertIsInstance( edit, GafferScene.EditScopeAlgo.TransformEdit )
self.assertTrue( GafferScene.EditScopeAlgo.hasTransformEdit( editScope, "/plane" ) )
self.assertIsNotNone( GafferScene.EditScopeAlgo.acquireTransformEdit( editScope, "/plane", createIfNecessary = False ) )
self.assertEqual( editScope["TransformEdits"]["Transform"]["enabled"].getInput(), editScope["TransformEdits"]["enabled"] )
self.assertEqual( editScope["out"].transform( "/plane" ), imath.M44f() )
edit.translate.setValue( imath.V3f( 2, 3, 4 ) )
self.assertEqual( editScope["out"].transform( "/plane" ), imath.M44f().translate( imath.V3f( 2, 3, 4 ) ) )
Expand Down Expand Up @@ -318,6 +320,7 @@ def testParameterEdits( self ) :
self.assertEqual( edit["mode"].getValue(), Gaffer.TweakPlug.Mode.Replace )
self.assertEqual( edit["value"].getValue(), imath.Color3f( 0 ) )
self.assertEqual( edit["enabled"].getValue(), False )
self.assertEqual( editScope["LightEdits"]["ShaderTweaks"]["enabled"].getInput(), editScope["LightEdits"]["enabled"] )

edit["enabled"].setValue( True )
edit["value"].setValue( imath.Color3f( 1 ) )
Expand Down Expand Up @@ -667,6 +670,7 @@ def testAttributeEdits( self ) :
self.assertEqual( edit["mode"].getValue(), Gaffer.TweakPlug.Mode.Create )
self.assertEqual( edit["value"].getValue(), 1.0 )
self.assertEqual( edit["enabled"].getValue(), False )
self.assertEqual( editScope["AttributeEdits"]["AttributeTweaks"]["enabled"].getInput(), editScope["AttributeEdits"]["enabled"] )

edit["enabled"].setValue( True )
edit["value"].setValue( 2.0 )
Expand Down Expand Up @@ -1084,6 +1088,9 @@ def testSetMembership( self ) :

GafferScene.EditScopeAlgo.setSetMembership( scope, IECore.PathMatcher( ["/group/cube"] ), "A", membership.Added )

self.assertEqual( scope["SetMembershipEdits"]["Set"]["enabled"].getInput(), scope["SetMembershipEdits"]["enabled"] )
self.assertEqual( scope["SetMembershipEdits"]["Set1"]["enabled"].getInput(), scope["SetMembershipEdits"]["enabled"] )

for path, set, status in (
( "/group/plane", "A", membership.Unchanged ),
( "/group/plane", "B", membership.Unchanged ),
Expand Down Expand Up @@ -1272,6 +1279,7 @@ def testOptionEdits( self ) :
self.assertEqual( edit["mode"].getValue(), Gaffer.TweakPlug.Mode.Create )
self.assertEqual( edit["value"].getValue(), 10 )
self.assertEqual( edit["enabled"].getValue(), False )
self.assertEqual( editScope["OptionEdits"]["OptionTweaks"]["enabled"].getInput(), editScope["OptionEdits"]["enabled"] )

edit["enabled"].setValue( True )
edit["value"].setValue( 20 )
Expand Down
53 changes: 53 additions & 0 deletions python/GafferSceneUI/EditScopeUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#
##########################################################################

import IECore

import Gaffer
import GafferUI
import GafferScene
Expand All @@ -44,6 +46,11 @@ def addPruningActions( editor ) :
if isinstance( editor, GafferUI.Viewer ) :
editor.keyPressSignal().connect( __pruningKeyPress, scoped = False )

def addVisibilityActions( editor ) :

if isinstance( editor, GafferUI.Viewer ) :
editor.keyPressSignal().connect( __visibilityKeyPress, scoped = False )

def __pruningKeyPress( viewer, event ) :

if event.key not in ( "Backspace", "Delete" ) :
Expand Down Expand Up @@ -101,3 +108,49 @@ def __pruningKeyPress( viewer, event ) :
GafferScene.EditScopeAlgo.setPruned( editScope, selection, True )

return True

def __visibilityKeyPress( viewer, event ) :

if not ( event.key == "H" and event.Modifiers.Control ) :
return False

if not isinstance( viewer.view(), GafferSceneUI.SceneView ) :
return False

editScope = viewer.view().editScope()
if editScope is None or Gaffer.MetadataAlgo.readOnly( editScope ) :
return True

sceneGadget = viewer.view().viewportGadget().getPrimaryChild()
selection = sceneGadget.getSelection()

if selection.isEmpty() :
return True

inspector = GafferSceneUI.Private.AttributeInspector(
viewer.view()["in"].getInput(),
viewer.view()["editScope"],
"scene:visible"
)

with viewer.getContext() as context :
attributeEdits = editScope.acquireProcessor( "AttributeEdits", createIfNecessary = False )
if not editScope["enabled"].getValue() or ( attributeEdits is not None and not attributeEdits["enabled"].getValue() ) :
# Spare folks from hiding something when it won't be
# apparent what they've done until they reenable the
# EditScope or processor.
return True

with Gaffer.UndoScope( editScope.ancestor( Gaffer.ScriptNode ) ) :
for path in selection.paths() :
context["scene:path"] = IECore.InternedStringVectorData( path.split( "/" )[1:] )
inspection = inspector.inspect()

if inspection is None or not inspection.editable() :
continue

tweakPlug = inspection.acquireEdit()
tweakPlug["enabled"].setValue( True )
tweakPlug["value"].setValue( False )

return True
7 changes: 5 additions & 2 deletions src/GafferScene/EditScopeAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace
/// in clients of history related APIs such as `AttributeInspector`.
using CreatableRegistry = std::unordered_map<std::string, const IECore::DataPtr>;
CreatableRegistry g_attributeRegistry {
{ "scene:visible", new BoolData( true ) },
{ "gl:visualiser:scale", new IECore::FloatData( 1.0f ) },
{ "gl:visualiser:maxTextureResolution", new IECore::IntData( 512 ) },
{ "gl:visualiser:frustum", new IECore::StringData( "whenSelected" ) },
Expand Down Expand Up @@ -683,7 +684,7 @@ SceneProcessorPtr attributeProcessor( const std::string &name )
result->addChild( attributeTweaks );
attributeTweaks->inPlug()->setInput( result->inPlug() );
attributeTweaks->filterPlug()->setInput( pathFilter->outPlug() );
attributeTweaks->enabledPlug()->setValue( result->enabledPlug() );
attributeTweaks->enabledPlug()->setInput( result->enabledPlug() );
attributeTweaks->localisePlug()->setValue( true );
attributeTweaks->ignoreMissingPlug()->setValue( true );

Expand Down Expand Up @@ -901,6 +902,7 @@ SceneProcessorPtr setMembershipProcessor()
addSet->filterPlug()->setInput( addPathFilter->outPlug() );
addSet->namePlug()->setInput( spreadsheet->enabledRowNamesPlug() );
addSet->modePlug()->setValue( GafferScene::Set::Mode::Add );
addSet->enabledPlug()->setInput( result->enabledPlug() );
addSet->setVariablePlug()->setValue( "setMembership:set" );

GafferScene::SetPtr removeSet = new GafferScene::Set();
Expand All @@ -909,6 +911,7 @@ SceneProcessorPtr setMembershipProcessor()
removeSet->filterPlug()->setInput( removePathFilter->outPlug() );
removeSet->namePlug()->setInput( spreadsheet->enabledRowNamesPlug() );
removeSet->modePlug()->setValue( GafferScene::Set::Mode::Remove );
removeSet->enabledPlug()->setInput( result->enabledPlug() );
removeSet->setVariablePlug()->setValue( "setMembership:set" );

auto rowsPlug = static_cast<Spreadsheet::RowsPlug *>(
Expand Down Expand Up @@ -1101,7 +1104,7 @@ SceneProcessorPtr optionProcessor( const std::string &name )
OptionTweaksPtr optionTweaks = new OptionTweaks;
result->addChild( optionTweaks );
optionTweaks->inPlug()->setInput( result->inPlug() );
optionTweaks->enabledPlug()->setValue( result->enabledPlug() );
optionTweaks->enabledPlug()->setInput( result->enabledPlug() );
optionTweaks->ignoreMissingPlug()->setValue( true );

PlugAlgo::promoteWithName( optionTweaks->tweaksPlug(), "edits" );
Expand Down
1 change: 1 addition & 0 deletions startup/gui/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,4 @@ def __loadRendererSettings( fileName ) :
# Add catalogue hotkeys to viewers, eg: up/down navigation
GafferUI.Editor.instanceCreatedSignal().connect( GafferImageUI.CatalogueUI.addCatalogueHotkeys, scoped = False )
GafferUI.Editor.instanceCreatedSignal().connect( GafferSceneUI.EditScopeUI.addPruningActions, scoped = False )
GafferUI.Editor.instanceCreatedSignal().connect( GafferSceneUI.EditScopeUI.addVisibilityActions, scoped = False )
Loading