|
Houdini HDK - Add String Attribute to Points etc.
to add a string attribute to a point or other type of geometry in a SOP node, dont use GB_ATTRIB_STRING, use GB_ATTRIB_INDEX instead. and here is how to set it up.
I Hope this helps someone ...
int help = ((GEO_Detail*)gdp)->findPointAttrib("test", sizeof(int), GB_ATTRIB_INDEX);
// If it does not exist
if (help <0)
{
// Create it ... it stores for every entity only the index ... thats why sizeof(int)
((GEO_Detail*)gdp)->addPointAttrib("test", sizeof(int), GB_ATTRIB_INDEX,0);
// find the offset of the attribute for access later
help = ((GEO_Detail*)gdp)->findPointAttrib("test", sizeof(int), GB_ATTRIB_INDEX);
}
//when you iterate over the points/primitives whatever
// [iterator]
// get the string array
GB_Attribute *stringAttr = gdp->pointAttribs().find( "test", GB_ATTRIB_INDEX );
// get the index pointer where the data from the current point is stored in the string array
int *aValue = (int*)ppt->getAttribData(help);
// fill in a value into a string
char value[255];
sprintf(value, "value%d", ppt->getNum()%10);
// add the string into the string array and receive its index,
// this automaticaly updates the point index, since it is piped in the pointer aValue
*aValue = stringAttr->addIndex(value);
|