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

VisualiserTool : Vertex Labels #6212

Open
wants to merge 21 commits into
base: 1.5_maintenance
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
910a3b2
VisualiserTool : Add visualiser modes
ericmehl Dec 11, 2024
48f236d
VisualiserTool : Separate color visualiser
ericmehl Dec 18, 2024
add87f9
VisualiserTool : No color for Auto mode + integers
ericmehl Dec 18, 2024
94c71f8
VisualiserTool : Add per-vertex label shaders
ericmehl Dec 23, 2024
5217a97
VisualiserTool : `primitiveVariable:` prefix
ericmehl Dec 23, 2024
f1b8b63
VisualiserTool : Add vertex index label
ericmehl Dec 19, 2024
06edf1b
VisualiserTool : Closest vertex index
ericmehl Dec 24, 2024
dd417ff
VisualiserTool : Vertex IDs with stroked text
ericmehl Dec 27, 2024
20c526b
VisualiserTool : Use `fmt::format` for values
ericmehl Dec 27, 2024
043073a
VisualiserTool : Show `int` data in `Auto` mode
ericmehl Dec 31, 2024
13ed0cb
VisualiserTool : VertexLabel mode
ericmehl Jan 6, 2025
d68d46d
VisualiserTool : Remove unclear comments
ericmehl Jan 22, 2025
b6b6913
VisualiserTool : Remove misleading ref assignment
ericmehl Jan 23, 2025
55ef9b0
VisualiserTool : Use `std::variant`
ericmehl Jan 27, 2025
19f549b
VisualiserTool : Support points and curves
ericmehl Jan 27, 2025
a97c8f1
fixup! VisualiserTool : Add visualiser modes
ericmehl Jan 28, 2025
41316ae
fixup! VisualiserTool : Menu items for points and curves
ericmehl Jan 28, 2025
6034578
fixup! VisualiserTool : Use `std::variant`
ericmehl Jan 28, 2025
5ee942d
fixup! VisualiserTool : Closest vertex index
ericmehl Jan 28, 2025
269d03e
fixup! VisualiserTool : Support points and curves
ericmehl Jan 28, 2025
e078806
fixup! VisualiserTool : VertexLabel mode
ericmehl Jan 28, 2025
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
26 changes: 12 additions & 14 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
1.5.x.x (relative to 1.5.4.0)
=======

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

- VisualiserTool :
- Changed naming requirements for visualising primitive variables. Values in `dataName` now prefix the primitive variable name with `primitiveVariable:`. Setting `dataName` to `vertex:index` will display vertex indices.
- Added `mode` plug. The available modes are :
- Auto : Vertex indices and integers on meshes are displayed `Vertex Label`. All data for curves and points objects are displayed as `Vertex Label`. Other data is displayed as `Color (Auto Range)`.
- Color (Auto Range) : Float, integer, V2f and color data is displayed without modification. Vector data is remapped from `[-1, 1]` to `[0, 1]`.
- Color : Values are remapped from the range `[valueMin, valueMax]` to `[0, 1]`.
- Vertex Label : Values are displayed as a label next to each vertex.
- When visualising data as vertex labels, the value for the vertex nearest the mouse cursor gets visual emphasis. This value is also used for drag and drop.

1.5.4.0 (relative to 1.5.3.0)
=======

Expand Down Expand Up @@ -36,20 +48,6 @@ API
- ScriptNodeAlgo : Added functions for managing VisibleSet bookmarks.

1.5.3.0 (relative to 1.5.2.0)
=======

Features
--------

- PrimitiveVariableTweaks : Added node for tweaking primitive variables. Can affect just part of a primitive based on ids or a mask.
- Menu Bar : Added a "Render Pass" menu to the Menu Bar that can be used to choose the current render pass from those provided by the focus node.

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

- Shader, ShaderPlug : Added support for ContextProcessor, Loop and Spreadsheet nodes to be used inline between shader nodes and as the terminal node connected to
ShaderAssignment and other shader-consuming nodes.
- VisualiserTool : Changed `dataName` input widget for choosing the primitive variable to visualise to a list of available variable names for the current selection.
- Tweaks nodes : Moved list of tweaks to a collapsible "Tweaks" section in the NodeEditor.
- Viewer :
- The shading mode menu icon now updates to indicate when a non-default shading mode is in use.
Expand Down
29 changes: 23 additions & 6 deletions include/GafferSceneUI/Private/VisualiserTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#include "Gaffer/NumericPlug.h"
#include "Gaffer/StringPlug.h"

#include <variant>

namespace
{

Expand All @@ -68,12 +70,26 @@ class GAFFERSCENEUI_API VisualiserTool : public SelectionTool

GAFFER_NODE_DECLARE_TYPE( GafferSceneUI::VisualiserTool, VisualiserToolTypeId, SelectionTool );

enum class Mode
{
Auto,
ColorAutoRange,
Color,
VertexLabel,

First = Auto,
Last = VertexLabel
};

Gaffer::StringPlug *dataNamePlug();
const Gaffer::StringPlug *dataNamePlug() const;

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

Gaffer::IntPlug *modePlug();
const Gaffer::IntPlug *modePlug() const;

Gaffer::V3fPlug *valueMinPlug();
const Gaffer::V3fPlug *valueMinPlug() const;

Expand Down Expand Up @@ -109,9 +125,11 @@ class GAFFERSCENEUI_API VisualiserTool : public SelectionTool

const std::vector<Selection> &selection() const;

Imath::V2f cursorPos() const;
using CursorPosition = std::optional<Imath::V2f>;
CursorPosition cursorPos() const;

const IECore::Data *cursorValue() const;
using CursorValue = std::variant<std::monostate, int, float, Imath::V2f, Imath::V3f, Imath::Color3f>;
const CursorValue cursorValue() const;

GafferScene::ScenePlug *internalScenePlug();
const GafferScene::ScenePlug *internalScenePlug() const;
Expand Down Expand Up @@ -146,13 +164,12 @@ class GAFFERSCENEUI_API VisualiserTool : public SelectionTool

GafferUI::GadgetPtr m_gadget;
mutable std::vector<Selection> m_selection;
Imath::V2i m_cursorPos;
bool m_cursorPosValid;
IECore::DataPtr m_cursorValue;
CursorPosition m_cursorPos;
CursorValue m_cursorValue;
bool m_gadgetDirty;
mutable bool m_selectionDirty;
bool m_priorityPathsDirty;
IECore::DataPtr m_valueAtButtonPress;
CursorValue m_valueAtButtonPress;
bool m_initiatedDrag;

static ToolDescription<VisualiserTool, SceneView> m_toolDescription;
Expand Down
90 changes: 78 additions & 12 deletions python/GafferSceneUI/VisualiserToolUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,29 @@

"description",
"""
Tool for displaying named primitive variables of type float, V2f or V3f as a colored overlay.
Tool for displaying object data.
""",

"viewer:shortCut", "O",
"viewer:shouldAutoActivate", False,
"order", 8,
"tool:exclusive", False,

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

plugs = {

"dataName" : [

"description",
"""
Specifies the name of the primitive variable to visualise. Variables of
The name of the data to visualise. Primitive variable names must be
prefixed by `primitiveVariable:`. For example, `primitiveVariable:uv`
would display the `uv` primitive variable. Primitive variables of
type int, float, V2f, Color3f or V3f can be visualised.

To visualise vertex indices instead of a primitive variable, use the
value `vertex:index`.
""",

"toolbarLayout:section", "Bottom",
Expand All @@ -85,6 +92,39 @@
"toolbarLayout:section", "Bottom",
"toolbarLayout:width", 100,

],
"mode" : [

"description",
"""
The method for displaying the data.

- Auto : Vertex indices and integers on meshes are displayed `Vertex Label`. All
data for curves and points objects are displayed as `Vertex Label`. Other data is
displayed as `Color (Type Range)`.
- Color (Type Range) : Float and integer data are displayed as grayscale. V2f data
is displayed with the `x` value for red, `y` value for green and `0` for blue. Vector
data is displayed with the `x` value for red, `y` value for green and `z` value for
blue. Color data is displayed directly.

Float, integer, V2f and color values are displayed without modification. Vector
values are remapped from `[-1, 1]` to `[0, 1]`.
- Color (Manual Range) : Data is displayed as with `Color (Type Range)`. Values
are remapped from the range `[valueMin, valueMax]` to `[0, 1]`.
- Vertex Label : Data is displayed as a label next to each vertex. Data must have
an interpolation type of `Vertex` to be displayed.
""",

"preset:Auto", GafferSceneUI.VisualiserTool.Mode.Auto,
"preset:Color", GafferSceneUI.VisualiserTool.Mode.Color,
"preset:Color (Auto Range)", GafferSceneUI.VisualiserTool.Mode.ColorAutoRange,
"preset:Vertex Label", GafferSceneUI.VisualiserTool.Mode.VertexLabel,

"plugValueWidget:type", "GafferUI.PresetsPlugValueWidget",

"toolbarLayout:section", "Bottom",
"toolbarLayout:width", 150,

],
"valueMin" : [

Expand All @@ -99,6 +139,8 @@
"toolbarLayout:section", "Bottom",
"toolbarLayout:width", 175,

"toolbarLayout:visibilityActivator", "modeIsColor",

],
"valueMax" : [

Expand All @@ -113,6 +155,8 @@
"toolbarLayout:section", "Bottom",
"toolbarLayout:width", 175,

"toolbarLayout:visibilityActivator", "modeIsColor",

],
"size": [

Expand All @@ -130,18 +174,26 @@

class _DataNameChooser( GafferUI.PlugValueWidget ) :

__primitiveVariablePrefix = "primitiveVariable:"
__primitiveVariablePrefixSize = len( __primitiveVariablePrefix )
__vertexIndexDataName = "vertex:index"

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

self.__menuButton = GafferUI.MenuButton(
text = plug.getValue(),
menu = GafferUI.Menu( Gaffer.WeakMethod( self.__menuDefinition ) )
)

GafferUI.PlugValueWidget.__init__( self, self.__menuButton, plug, **kw )

def _updateFromValues( self, values, exception ) :

self.__menuButton.setText( sole( values ) or "None" )
singleValue = sole( values )
text = "None"
if singleValue is not None :
text = "Vertex Index" if singleValue == self.__vertexIndexDataName else self.__primitiveVariableFromDataName( singleValue )

self.__menuButton.setText( text )

def __menuDefinition( self ) :

Expand All @@ -158,14 +210,14 @@ def __menuDefinition( self ) :
with node.view().context() :
selection = GafferSceneUI.ScriptNodeAlgo.getSelectedPaths( scriptNode )

primVars = set()
primitiveVariables = set()

for path in selection.paths() :
if not scenePlug.exists( path ) :
continue

primitive = scenePlug.object( path )
if not isinstance( primitive, IECoreScene.MeshPrimitive ) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to check that we have a Primitive, because the code below assumes looks for primitive variables. Try selecting a camera and you get this error :

  File "/home/john/dev/build/gaffer-1.5/python/GafferSceneUI/VisualiserToolUI.py", line 220, in __menuDefinition
    for v in primitive.keys() :
AttributeError: 'Camera' object has no attribute 'keys'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 41316ae

if not isinstance( primitive, IECoreScene.Primitive ) :
continue

for v in primitive.keys() :
Expand All @@ -188,25 +240,39 @@ def __menuDefinition( self ) :
) :
continue

primVars.add( v )
primitiveVariables.add( v )

if len( primVars ) == 0 :
if len( primitiveVariables ) == 0 :
menuDefinition.append( "/None Available", { "active" : False } )

else :
for v in reversed( sorted( primVars ) ) :
for v in reversed( sorted( primitiveVariables ) ) :
menuDefinition.prepend(
"/" + v,
{
"command" : functools.partial( Gaffer.WeakMethod( self.__setDataName ), v ),
"checkBox" : self.getPlug().getValue() == v,
"command" : functools.partial( Gaffer.WeakMethod( self.__setDataName ), self.__primitiveVariablePrefix + v ),
"checkBox" : self.__primitiveVariableFromDataName( self.getPlug().getValue() ) == v,
}
)

menuDefinition.prepend( "/PrimVarDivider", { "divider" : True, "label" : "Primitive Variables" } )
menuDefinition.prepend( "/PrimitiveVariableDivider", { "divider" : True, "label" : "Primitive Variables" } )

menuDefinition.append( "/Other", { "divider" : True, "label" : "Other" } )
menuDefinition.append(
"/Vertex Index",
{
"command" : functools.partial( Gaffer.WeakMethod( self.__setDataName ), self.__vertexIndexDataName ),
"checkBox" : self.getPlug().getValue() == self.__vertexIndexDataName,
}
)

return menuDefinition

def __setDataName( self, value, *unused ) :

self.getPlug().setValue( value )

def __primitiveVariableFromDataName( self, name ) :

return name[self.__primitiveVariablePrefixSize:] if (
name.startswith( self.__primitiveVariablePrefix ) ) else ""
Loading
Loading