Skip to content

Commit

Permalink
Merge pull request #6276 from ericmehl/vectorVisualiser
Browse files Browse the repository at this point in the history
VisualiserTool : Vector visualiser
  • Loading branch information
ericmehl authored Feb 26, 2025
2 parents e47c979 + 03df46b commit 9c2ba12
Show file tree
Hide file tree
Showing 6 changed files with 574 additions and 26 deletions.
5 changes: 5 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Improvements

- 3Delight : Added light muting support.
- Arnold : Added support for specifying the name of a shader in the node menu using Arnold's `ui.name` metadata. This improves the formatting of the OpenPBR Surface menu item.
- VisualiserTool : Added new visualisation for vector (V3f) data.
- The `vectorScale` plug can be used to scale the vector line. The <kbd>Shift</kbd> + <kbd>+</kbd> and <kbd>Shift</kbd> + <kbd>-</kbd> keyboard shortcuts can also be used to change the scale.
- The `vectorColor` plug can be used to change the color of the vector line.
- The vector value being visualised for the vertex nearest the cursor is shown next to the vertex.
- ColorSwatchPlugValueWidget : Changed the display transform of the color chooser dialogue to match that of the `ColorSwatchPlugValueWidget` creating it instead of the script window.

Fixes
-----
Expand Down
12 changes: 12 additions & 0 deletions include/GafferSceneUI/Private/VisualiserTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ class GAFFERSCENEUI_API VisualiserTool : public SelectionTool
Gaffer::FloatPlug *sizePlug();
const Gaffer::FloatPlug *sizePlug() const;

Gaffer::FloatPlug *vectorScalePlug();
const Gaffer::FloatPlug *vectorScalePlug() const;

Gaffer::Color3fPlug *vectorColorPlug();
const Gaffer::Color3fPlug *vectorColorPlug() const;

private:

friend VisualiserGadget;
Expand All @@ -108,17 +114,20 @@ class GAFFERSCENEUI_API VisualiserTool : public SelectionTool
{
Selection(
const GafferScene::ScenePlug &scene,
const GafferScene::ScenePlug &uniformPScene,
const GafferScene::ScenePlug::ScenePath &path,
const Gaffer::Context &context
);

const GafferScene::ScenePlug &scene() const;
const GafferScene::ScenePlug &uniformPScene() const;
const GafferScene::ScenePlug::ScenePath &path() const;
const Gaffer::Context &context() const;

private:

GafferScene::ConstScenePlugPtr m_scene;
GafferScene::ConstScenePlugPtr m_uniformPScene;
GafferScene::ScenePlug::ScenePath m_path;
Gaffer::ConstContextPtr m_context;
};
Expand All @@ -134,6 +143,9 @@ class GAFFERSCENEUI_API VisualiserTool : public SelectionTool
GafferScene::ScenePlug *internalScenePlug();
const GafferScene::ScenePlug *internalScenePlug() const;

GafferScene::ScenePlug *internalSceneUniformPPlug();
const GafferScene::ScenePlug *internalSceneUniformPPlug() const;

void connectOnActive();
void disconnectOnInactive();
bool mouseMove( const GafferUI::ButtonEvent &event );
Expand Down
41 changes: 40 additions & 1 deletion python/GafferSceneUI/VisualiserToolUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"tool:exclusive", False,

"toolbarLayout:activator:modeIsColor", lambda node : node["mode"].getValue() == GafferSceneUI.VisualiserTool.Mode.Color,
"toolbarLayout:activator:modeIsAuto", lambda node : node["mode"].getValue() == GafferSceneUI.VisualiserTool.Mode.Auto,

plugs = {

Expand Down Expand Up @@ -90,7 +91,7 @@
""",

"toolbarLayout:section", "Bottom",
"toolbarLayout:width", 100,
"toolbarLayout:width", 45,

],
"mode" : [
Expand Down Expand Up @@ -158,10 +159,48 @@
"plugValueWidget:type", ""

],
"vectorScale" : [

"description",
"""
The scale factor to apply to vectors.
""",

"toolbarLayout:section", "Bottom",
"toolbarLayout:width", 45,

"toolbarLayout:visibilityActivator", "modeIsAuto",

],

"vectorColor" : [

"description",
"""
The colour to use for drawing vectors.
""",

"toolbarLayout:section", "Bottom",
"toolbarLayout:width", 175,

"toolbarLayout:visibilityActivator", "modeIsAuto",
"colorPlugValueWidget:colorChooserButtonVisible", False,

"plugValueWidget:type", "GafferSceneUI.VisualiserToolUI._UntransformedColorWidget",

],

},
)

class _UntransformedColorWidget( GafferUI.ColorPlugValueWidget ) :

def __init__( self, plugs, **kw ) :

GafferUI.ColorPlugValueWidget.__init__( self, plugs, **kw )

self.setDisplayTransform( GafferUI.Widget.identityDisplayTransform )

class _DataNameChooser( GafferUI.PlugValueWidget ) :

__primitiveVariablePrefix = "primitiveVariable:"
Expand Down
11 changes: 9 additions & 2 deletions python/GafferUI/ColorPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__( self, plugs, **kw ) :
sole( Gaffer.Metadata.value( plug, "colorPlugValueWidget:colorChooserVisible" ) for plug in self.getPlugs() )
)

self.__chooserButton.setVisible( not any( p.direction() == Gaffer.Plug.Direction.Out for p in self.getPlugs() ) )
self.__chooserButton.setVisible( self.__chooserButtonVisible() )

self.__blinkBehaviour = None

Expand Down Expand Up @@ -122,7 +122,7 @@ def setPlugs( self, plugs ) :
self.__swatch.setPlugs( plugs )

# Update widget visibility if the plug directions changed
self.__chooserButton.setVisible( not any( p.direction() == Gaffer.Plug.Direction.Out for p in self.getPlugs() ) )
self.__chooserButton.setVisible( self.__chooserButtonVisible() )
self.setColorChooserVisible( self.__colorChooserVisible )

def setHighlighted( self, highlighted ) :
Expand Down Expand Up @@ -163,6 +163,13 @@ def __chooserButtonClicked( self, widget ) :
for plug in self.getPlugs() :
Gaffer.Metadata.registerValue( plug, "colorPlugValueWidget:colorChooserVisible", visible, persistent = False )

def __chooserButtonVisible( self ) :

return (
not any( p.direction() == Gaffer.Plug.Direction.Out for p in self.getPlugs() ) and
not any( Gaffer.Metadata.value( p, "colorPlugValueWidget:colorChooserButtonVisible" ) == False for p in self.getPlugs() )
)

GafferUI.PlugValueWidget.registerType( Gaffer.Color3fPlug, ColorPlugValueWidget )
GafferUI.PlugValueWidget.registerType( Gaffer.Color4fPlug, ColorPlugValueWidget )

Expand Down
11 changes: 6 additions & 5 deletions python/GafferUI/ColorSwatchPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __buttonRelease( self, widget, event ) :
if not self._editable() :
return False

_ColorPlugValueDialogue.acquire( self.getPlugs() )
_ColorPlugValueDialogue.acquire( self.getPlugs(), self.displayTransform() )

return True

Expand All @@ -125,11 +125,12 @@ def _colorFromPlugs( plugs ) :
# actually be functionality of CompoundEditor?
class _ColorPlugValueDialogue( GafferUI.ColorChooserDialogue ) :

def __init__( self, plugs, parentWindow ) :
def __init__( self, plugs, parentWindow, displayTransform ) :

GafferUI.ColorChooserDialogue.__init__(
self,
color = _colorFromPlugs( plugs )
color = _colorFromPlugs( plugs ),
displayTransform = displayTransform
)

# we use these to decide which actions to merge into a single undo
Expand Down Expand Up @@ -192,7 +193,7 @@ def __init__( self, plugs, parentWindow ) :
parentWindow.addChildWindow( self, removeOnClose = True )

@classmethod
def acquire( cls, plugs ) :
def acquire( cls, plugs, displayTransform ) :

plug = next( iter( plugs ) )

Expand All @@ -212,7 +213,7 @@ def acquire( cls, plugs ) :
window.setVisible( True )
return window

window = _ColorPlugValueDialogue( plugs, scriptWindow )
window = _ColorPlugValueDialogue( plugs, scriptWindow, displayTransform )
window.setVisible( True )
return False

Expand Down
Loading

0 comments on commit 9c2ba12

Please sign in to comment.