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

Merged
merged 15 commits into from
Jan 29, 2025
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
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 : Chooses the most appropriate mode based on the data and primitive type.
- 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.

Fixes
-----

Expand Down Expand Up @@ -41,20 +53,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
80 changes: 68 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,29 @@
"toolbarLayout:section", "Bottom",
"toolbarLayout:width", 100,

],
"mode" : [

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

- Auto : Chooses the most appropriate mode based on the data and primitive type.
- Color : Values are remapped from the range `[valueMin, valueMax]` to `[0, 1]`.
- Color (Auto Range) : Float, integer, V2f and color data is displayed without
modification. Vector data is remapped from `[-1, 1]` to `[0, 1]`.
""",

"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 +129,8 @@
"toolbarLayout:section", "Bottom",
"toolbarLayout:width", 175,

"toolbarLayout:visibilityActivator", "modeIsColor",

],
"valueMax" : [

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

"toolbarLayout:visibilityActivator", "modeIsColor",

],
"size": [

Expand All @@ -130,18 +164,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 +200,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 ) :
if not isinstance( primitive, IECoreScene.Primitive ) :
continue

for v in primitive.keys() :
Expand All @@ -188,25 +230,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