Creating an integer array attribute with HDK?

   2293   2   1
User Avatar
Member
5 posts
Joined: 8月 2014
Offline
Using Attribute Create you can create an attribute with type “Integer Array” – is there a way to do this with c++ and the HDK?

The best I can do is to create an Integer attribute with size N but this results in N integer attributes (attr..attr) instead of one attribute with array data.

Just wondering if anyone has done this… thanks!
User Avatar
スタッフ
4200 posts
Joined: 9月 2007
Online
I tried dabbling with array attributes a bit over the summer (I'm a REALLY BAD programmer), but there is an array attrib example in the HDK:

$HFS/toolkit/samples/SOP/SOP_ArrayAttrib.C

I was also given this little snippet for Vec3 arrays:

UT_FloatArray fdata; 
UT_Vector3Array vdata; 

GA_Offset ptoff; 
GA_FOR_ALL_PTOFF(gdp, ptoff) 
{ 
    // Fetch array value 
    aif->get(attrib, ptoff, fdata); 

    // Convert UT_FloatArray to UT_Vector3Array 
    // NOTE: /3 for non-negative integers rounds down 
    // if fdata.size() isn't a multiple of 3, so it's safe for that possibility. 
    int vsize = fdata.size()/3; 
    vdata.setSize(vsize); 
    for (exint vi = 0, fi = 0; vi < vsize; ++vi, fi+=3) { 
        vdata[vi] = UT_Vector3(fdata[fi+0],fdata[fi+1],fdata[fi+2]); 
    } 

    // Do something with the vectors 
    for (exint vi = 0; vi < vsize; ++vi) { 
        // This is just an example of something to do 
        vdata[vi] *= 0.5f; 
    } 

    // Convert UT_Vector3Array to UT_FloatArray 
    for (exint vi = 0, fi = 0; vi < vsize; ++vi, fi+=3) { 
        fdata[fi+0] = vdata[vi][0]; // x 
        fdata[fi+1] = vdata[vi][1]; // y 
        fdata[fi+2] = vdata[vi][2]; // z 
    } 

    // Write back 
    aif->set(attrib, ptoff, fdata); 
} 

I can't find my little experiments. But hopefully those help a bit, and maybe someone more knowledgeable will chime in.
Edited by goldleaf - 2018年4月24日 23:59:17
I'm o.d.d.
User Avatar
Member
5 posts
Joined: 8月 2014
Offline
Hey goldleaf, thanks so much!

I was using H14 which did not include the code sample you pointed me at but I found it in H15 and was able to create an array attr.

Cheers!
  • Quick Links