In an HDA you click "add parameter" and it is there.
In an HDK node, the interface is code you write, one parameter at a time.
I will be honest: this is the part of C++ nodes I like least.
Two parameters, nine lines
Here are Count and Radius from the ring node in the last article:
static PRM_Name theCountName("count", "Count");
static PRM_Name theRadiusName("radius", "Radius");
static PRM_Default theCountDefault(12);
static PRM_Default theRadiusDefault(1.0);
PRM_Template Hello_Ring::myTemplateList[] = {
PRM_Template(PRM_INT, 1, &theCountName, &theCountDefault),
PRM_Template(PRM_FLT, 1, &theRadiusName, &theRadiusDefault),
PRM_Template(),
};Each parameter needs a name object, a default object and a template line, and the list ends with an empty template.
That is nine lines for two parameters, and I have not even given them a range yet.
The folder trap
When the list gets long, you group it into folders.
In the plain API, a folder strip is a switcher that you give the number of parameters in each folder:
PRM_Default theCounts[] = {PRM_Default(2, "Main"), PRM_Default(2, "Extra")}; // a b | c dYou can see where this is going.
I added a fourth parameter to the end of the second folder and left its count at 1.
Houdini said nothing at all, and the parameter ended up outside both folders, showing under every tab.
Nothing crashed and nothing warned me, and that is exactly why it is nasty.
The helper that saves me
So my repo has a small builder in the common layer, and I use it almost everywhere.
The same two parameters, now with ranges:
b.addInt("count", "Count", 12).range(3, 256);
b.addFloat("radius", "Radius", 1.0f).range(0.0f, 100.0f);Two lines instead of nine.
Folders are opened and closed instead of counted:
b.beginSimpleFolder("f_main", "Main");
b.addFloat("a", "A", 0.f);
b.addFloat("b", "B", 0.f);
b.endSimpleFolder();No numbers to keep in sync, so the trap above is gone.
178 of the 246 SOP source files use it now, and the real edge-damage node from the first article defines 38 parameters in about 140 lines.
It is not magic
The builder fixes the counting, but a few chores are still on you:
- Forget to close a folder and nothing complains. The builder has a check for it, but the check is an assert, and Houdini removes asserts from release builds. When I tried it, the node built fine and all the parameters just showed up flat, with no folders at all.
- Showing and hiding is done with strings. The node swaps whole pages with conditions like
"{ damagetype != 1 }", which name another parameter by its token. The compiler cannot check a string, so a typo only shows up when you look at the node. - A ramp is expensive. The one ramp in the edge-damage node, a two-key curve, takes about 33 lines of its own. That is about as much as nine ordinary parameters.
And every change means a rebuild
Want to rename a label or change a default?
That is an edit, a build and a restart of Houdini, about 26 seconds for the real node.
In an HDA it is a dialog and a click.
So why put up with it?
Because the interface sits in the repo right next to the code, and 230 nodes share the same builder, so they all behave the same way.
For a lot of nodes written by one person, that consistency is worth more than the convenience of a dialog.
Next
Next time I want to talk about the thing that started all of this: speed, and how to make a cook use all the cores of your machine without breaking it.
Comments