Skip to content

Commit

Permalink
VisualiserTool : VertexLabel mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Jan 14, 2025
1 parent e1db57e commit d853320
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ Improvements
- Changed `dataName` input widget for choosing the primitive variable to visualise to a list of available variable names for the current selection.
- Changed naming requirements for visualising primitive variables. Values in `dataName` now prefix the primitive variable name with `primVar:`. Setting `dataName` to `vertex:index` will display vertex indices.
- Added `mode` plug. The available modes are :
- Auto : Vertex indices and integers are displayed as a label next to each vertex. Other data is displayed as `Color (Type Range)`.
- Auto : Vertex indices and integers are displayed `Vertex Label`. Other data is displayed as `Color (Type Range)`.
- Color (Type Range) : Float, integer, V2f and color data is displayed without modification. Vector data is remapped from `[-1, 1]` to `[0, 1]`.
- Color (Manual Range) : 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.
- Tweaks nodes : Moved list of tweaks to a collapsible "Tweaks" section in the NodeEditor.
- Viewer :
Expand Down
3 changes: 2 additions & 1 deletion include/GafferSceneUI/Private/VisualiserTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ class GAFFERSCENEUI_API VisualiserTool : public SelectionTool
Auto,
ColorTypeRange,
ColorManualRange,
VertexLabel,

First = Auto,
Last = ColorManualRange
Last = VertexLabel
};

Gaffer::StringPlug *dataNamePlug();
Expand Down
8 changes: 5 additions & 3 deletions python/GafferSceneUI/VisualiserToolUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@
"""
The method for displaying the data.
- Auto : Vertex indices and integer data are displayed as a label next to each vertex.
Integer data must have an interpolation type of `Vertex` to be displayed. Other data
is displayed as `Color (Type Range)`.
- Auto : Vertex indices and integer data 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
Expand All @@ -111,11 +110,14 @@
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 (Type Range)", GafferSceneUI.VisualiserTool.Mode.ColorTypeRange,
"preset:Color (Manual Range)", GafferSceneUI.VisualiserTool.Mode.ColorManualRange,
"preset:Vertex Label", GafferSceneUI.VisualiserTool.Mode.VertexLabel,

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

Expand Down
92 changes: 90 additions & 2 deletions src/GafferSceneUI/VisualiserTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,14 @@ class VisualiserGadget : public Gadget
{
// Get the name of the primitive variable to visualise
const std::string name = primVarFromDataName( m_tool->dataNamePlug()->getValue() );
if( name.empty() )
if(
name.empty() ||
(
mode != VisualiserTool::Mode::Auto &&
mode != VisualiserTool::Mode::ColorManualRange &&
mode != VisualiserTool::Mode::ColorTypeRange
)
)
{
return;
}
Expand Down Expand Up @@ -806,6 +813,15 @@ class VisualiserGadget : public Gadget
void renderColorValue( const ViewportGadget *viewportGadget, const Style *style, VisualiserTool::Mode mode ) const
{
if(
mode != VisualiserTool::Mode::Auto &&
mode != VisualiserTool::Mode::ColorManualRange &&
mode != VisualiserTool::Mode::ColorTypeRange
)
{
return;
}
// Display value at cursor as text
const Data *value = m_tool->cursorValue();
Expand Down Expand Up @@ -841,7 +857,7 @@ class VisualiserGadget : public Gadget
void renderVertexLabelValue( const ViewportGadget *viewportGadget, const Style *style, VisualiserTool::Mode mode ) const
{
if( mode != VisualiserTool::Mode::Auto )
if( mode != VisualiserTool::Mode::Auto && mode != VisualiserTool::Mode::VertexLabel )
{
return;
}
Expand Down Expand Up @@ -984,6 +1000,10 @@ class VisualiserGadget : public Gadget
{
continue;
}
if( mode == VisualiserTool::Mode::Auto && vIt->second.data->typeId() != IntVectorDataTypeId )
{
continue;
}
switch( vIt->second.data->typeId() )
{
Expand All @@ -994,6 +1014,34 @@ class VisualiserGadget : public Gadget
false /* throwIfInvalid */
);
break;
case FloatVectorDataTypeId :
vData = primitive->expandedVariableData<FloatVectorData>(
primVarName,
IECoreScene::PrimitiveVariable::Vertex,
false /* throwIfInvalid */
);
break;
case V2fVectorDataTypeId :
vData = primitive->expandedVariableData<V2fVectorData>(
primVarName,
IECoreScene::PrimitiveVariable::Vertex,
false /* throwIfInvalid */
);
break;
case V3fVectorDataTypeId :
vData = primitive->expandedVariableData<V3fVectorData>(
primVarName,
IECoreScene::PrimitiveVariable::Vertex,
false /* throwIfInvalid */
);
break;
case Color3fVectorDataTypeId :
vData = primitive->expandedVariableData<Color3fVectorData>(
primVarName,
IECoreScene::PrimitiveVariable::Vertex,
false /* throwIfInvalid */
);
break;
default : break;
}
if( !vData )
Expand Down Expand Up @@ -1238,6 +1286,46 @@ class VisualiserGadget : public Gadget
data->writable() = iData->readable()[i];
vertexValue = data;
}
if( auto fData = runTimeCast<const FloatVectorData>( vData.get() ) )
{
auto data = runTimeCast<FloatData>( vertexValue );
if( !data )
{
data.reset( new FloatData() );
}
data->writable() = fData->readable()[i];
vertexValue = data;
}
if( auto v2fData = runTimeCast<const V2fVectorData>( vData.get() ) )
{
auto data = runTimeCast<V2fData>( vertexValue );
if( !data )
{
data.reset( new V2fData() );
}
data->writable() = v2fData->readable()[i];
vertexValue = data;
}
if( auto v3fData = runTimeCast<const V3fVectorData>( vData.get() ) )
{
auto data = runTimeCast<V3fData>( vertexValue );
if( !data )
{
data.reset( new V3fData() );
}
data->writable() = v3fData->readable()[i];
vertexValue = data;
}
if( auto c3fData = runTimeCast<const Color3fVectorData>( vData.get() ) )
{
auto data = runTimeCast<Color3fData>( vertexValue );
if( !data )
{
data.reset( new Color3fData() );
}
data->writable() = c3fData->readable()[i];
vertexValue = data;
}
}
// Update cursor value
Expand Down
1 change: 1 addition & 0 deletions src/GafferSceneUIModule/ToolBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ void GafferSceneUIModule::bindTools()
.value( "Auto", VisualiserTool::Mode::Auto )
.value( "ColorTypeRange", VisualiserTool::Mode::ColorTypeRange )
.value( "ColorManualRange", VisualiserTool::Mode::ColorManualRange )
.value( "VertexLabel", VisualiserTool::Mode::VertexLabel )
;
}

Expand Down

0 comments on commit d853320

Please sign in to comment.