← BACK TO NOTES
2026-10-10 |
HDK HOUDINI

Nodes You Can Touch in the Viewport: Python States

Typing numbers into parameters is sometimes a poor way to decide a position or an area.
Clicking and dragging directly in the viewport is far easier. Houdini's "viewer state" is what you use for that.

What a viewer state is

It is a Python class that Houdini runs when you select a node and press Enter in the viewport.
It receives mouse and key input, draws guide shapes and shows prompts. In my repo, the state that makes a node operable is called a PVS (Python Viewer State).

Who does what, C++ or Python

The C++ side has no viewport code at all.
C++ defines the parameters and cooks from them, nothing more. The viewport interaction reaches the node by the Python side reading and writing those parameters.

The only link is a name.
The state file is {NodeName}State.py, and the state's name equals the node type's name. Houdini automatically calls createViewerStateTemplate() from the viewer_states/ folder.

def createViewerStateTemplate():
    template = hou.ViewerStateTemplate(
        STATE_NAME, "UE Collision Multi", hou.sopNodeTypeCategory()
    )
    template.bindFactory(UECollisionPVSState)
    template.bindIcon("SOP_collision")
    template.bindNodeChangeEvent(
        [hou.nodeEventType.ParmTupleChanged,
         hou.nodeEventType.InputDataChanged])
    return template

Data passes only through parameters.
For example, Python writes the numbers of the selected faces into a string parameter, and C++ reads it as a list of numbers. Because the parameters are the single source of truth, nothing is lost when you save and reopen.

What you can actually do

UE Collision Multi (UE_Collision_PVS) lets you click mesh faces to select them and commit each selection as one convex-hull collision set.
Left click toggles a face, Shift adds, Enter commits, Delete removes a committed set and Esc cancels the selection. If the mouse moves 5.0 pixels or more, it is not counted as a click.

PRIME Blueprint draws rectangles and circles in the viewport, and you change width, depth, height and radius with arrow and cube handles.
Shift plus scroll switches the shape type (rectangle, circle, curve).

A shared handle kit

Handles are not built per node. They come from shared parts (Common/Viewer/hdk_viewer/handles/).
It holds discs, height, ramps, scale, tilt and more, and the rule is to import them, not copy them.

The interaction rules are also uniform.
Ctrl plus click places (drag sets the radius), click selects, a cyan diamond moves, Delete removes and Esc cancels. Only the handles relevant to the current operation are shown, and rows that do not apply become a dim disc.

What I learned and banned

The causes of broken interactions are written straight into a "Forbidden" section of the rules.

  • SideFX handles: to move multiparm items, do not use bindViewerHandle or the translate manipulators. Use a cyan diamond of fixed pixel size.
  • Coordinates: a node can be transformed, so convert hits from ui_event.ray() between world and node space.
  • Heightfields: do not call geo.intersect on the volume. Clamp XZ to the bounding box and then call Volume.sample.
  • Drawing: rebuild drawables only when something changed or on interaction, not on every onDraw.
  • Undo: wrap edits in hou.undos.group(...) so they undo as one step.

Summary

The repo has 92 *State.py files.
A node you can operate is far easier to use than one you type numbers into. The rule is a single one: if you build a SOP that moves several things in the viewport, build its state in the same change. One reference sample (TEMP_Template) is fixed, and you copy it.

Next, as a wrap-up of everything so far, I will write about what was good about the HDK.

Related articles

2026-10-05

Rigs and Motion as C++ Nodes

How my animation nodes (prefix ANIM, 13 of them) are built. An external process that makes motion from text, a solver that fixes motion with guides, retargeting, building rigs from meshes, and the KineFX rules that tripped me up.

2026-10-19

HDK Limit 1: Waiting for Compiles

The biggest price of the HDK is the wait for compiles. The time after each edit, the weight of 230-plus DLLs, the limits of incremental builds, and the procedure when Houdini is holding a DLL, with real numbers.

2026-10-01

Water and Clouds in C++

How my water and cloud nodes (prefix ELEM, seven of them) are built. A shore node that solves wave arrival time, caustics that gather light, how clouds are made, and what I decided not to build.

Comments