Houdini geometry can carry attributes on four things: points, vertices, primitives (faces and the like) and the geometry as a whole (detail). This "where it lives" is called the owner.
A group is a way to bundle points or faces under a name. In C++ you read and write attributes through a container called a handle.
This article covers the usage I made into rules in my repo, and four places where I actually got stuck.
1. Build handles outside the loop
Looking up an attribute by name is too heavy to repeat per point, so I build the handle once before the loop.
And if the attribute could not be created or the name is wrong, the handle is invalid, so I check isValid() before using it (shortened here).
GA_RWHandleS jointH(gdp, GA_ATTRIB_POINT, kGuideJointAttrib);
GA_RWHandleF weightH(gdp, GA_ATTRIB_POINT, kGuideWeightAttrib);
for (const AnimGuide &g : guides) {
const GA_Offset off = gdp->appendPointOffset();
gdp->setPos3(off, g.pos);
if (jointH.isValid()) jointH.set(off, g.joint.c_str());
if (weightH.isValid()) weightH.set(off, SYSclamp(g.weight, 0.0f, 1.0f));
}
gdp->bumpAllDataIds();To create a new attribute and wrap it in one go, it is a single line:
GA_RWHandleF huPos(geo.addFloatTuple(GA_ATTRIB_POINT, name, 1));2. Say that you changed it
The last line, bumpAllDataIds(), is the second rule.
Call it after you change topology or attributes. Houdini looks at the IDs on the data to decide what changed, so you advance the ID to tell downstream nodes.
So that I do not forget, my repo's rules file says: always call it after changing topology or attributes.
3. Group names collide
When you make a temporary group, a group with the same name may already be lying around.
So before creating one, I look for a group with that name and destroy it. Also, newPointGroup returns null on failure, so I check for that.
static void destroyTempGroup(GU_Detail &gdp, const char *name, bool is_edge) {
// ...
if (GA_PointGroup *g = gdp.findPointGroup(UT_StringHolder(name)))
gdp.destroyPointGroup(g);
}
destroyTempGroup(*gdp, kTempPointGroup, false);
GA_PointGroup *grp = gdp->newPointGroup(UT_StringHolder(kTempPointGroup));
if (!grp) { err = "Failed to create point group."; return false; }Temporary group names look like __pts_before_start, a form unlikely to collide with anything else.
4. Do not keep the same name on points and vertices
In the node that joins a stone wall to a roof, the UVs and normals were on points.
If you create a vertex attribute with the same name there, things get hard to reason about. So before creating the vertex attribute, I save the point UVs and normals separately as plain values. After the join stretches or cuts the shape and the values are interpolated, I keep each normal's direction and renormalize its length.
This kind of mix-up makes the result only slightly wrong, so it is hard to notice.
The safest approach is to decide up front whether something lives on points or on vertices, and never switch midway.
Summary
All four take little code, and forgetting any of them breaks things in ways that are hard to see.
So I do not rely on thinking about it each time; I write it into the rules file and make it a standing rule.
Next: UVs, the place where the difference between points and vertices shows most.
Comments