Sebastian H. Schmidt | FX - Technical Director | Research & Development
home

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 ...

  1. int help = ((GEO_Detail*)gdp)->findPointAttrib("test", sizeof(int), GB_ATTRIB_INDEX);
  2. // If it does not exist
  3. if (help <0)
  4. {
  5.      // Create it ... it stores for every entity only the index ... thats why sizeof(int)
  6.      ((GEO_Detail*)gdp)->addPointAttrib("test", sizeof(int), GB_ATTRIB_INDEX,0);
  7.      // find the offset of the attribute for access later
  8.      help = ((GEO_Detail*)gdp)->findPointAttrib("test", sizeof(int), GB_ATTRIB_INDEX);
  9. }
  10.  
  11. //when you iterate over the points/primitives whatever
  12.  
  13. // [iterator]
  14.      // get the string array
  15.      GB_Attribute *stringAttr = gdp->pointAttribs().find( "test", GB_ATTRIB_INDEX );
  16.      // get the index pointer where the data from the current point is stored in the string array
  17.      int *aValue =    (int*)ppt->getAttribData(help);
  18.      // fill in a value into a string
  19.      char value[255];
  20.      sprintf(value, "value%d", ppt->getNum()%10);
  21.      // add the string into the string array and receive its index,
  22.      // this automaticaly updates the point index, since it is piped in the pointer aValue
  23.      *aValue = stringAttr->addIndex(value);