Search - User list
Full Version: Access primitive in HDK
Root » Technical Discussion » Access primitive in HDK
maxpayne
Hi everyone. I'm learning hdk and I'm stuck with primitives. The goal is to loop over all the primitives on a geo and perform pointevaluate to get world position based on uv (so it's like primuv function in vex). THen apply that value to a primitive attribute.

What I found so far is that I can run pointevaluate only from GEO_primitive.

I'm running a loop using GA_FOR_ALL_PRIMOFF (gdp, primoff) but I can't find a function that get me GEO_primitive object from that.

In sample files I found a code using GA_FOR_ALL_PRIMITIVES that seems like return GEO_primitive but then how do I get offset based on that and assign a value to a primitive ?
I'm a bit lost with all those concepts.

Little explanation would be very helpful.

Thank you.
Umang_Raj
HDK uses cpp's object oriented programming alot. All of the upper level primitive classes do contain a ga_primitive interface.

For the primoff you get from the first macro, you can easily use the getPrimitive function on the detail, and then use the function it provides or cast it to other upper level classes you know it has using implicit casting or explicit static_cast, or if you are not sure, use dynamic_cast which returns nullptr if it doesn't have that class object like this-
GA_Primitive *primPtr = gdp->getPrimitive(primOffset);
// static cast, if prim isn't polygon then it will give undefined behaviour
// GEO_PrimPoly *geoPrimPtr = static_cast<GEO_PrimPoly*>(primPtr);
// dynamic cast for verification
GEO_PrimPoly *geoPrimPtr = static_cast<GEO_PrimPoly*>(primPtr);
if (!geoPrimPtr)
    // return error, and/or do your quitting logic
or you can just use getPrimitivesOfType function.

and for your second question, you can use getMapOffset function on the primitive you get from that macro, to get it's offset.
maxpayne
Umang_Raj
Umang_Raj
Hi. Thank you for the reply. It's quite helpful. I was able to get GEO_primitive using gdp->getGEOPrimitive(primoff); and then using my logic so it's all working now.

I'm facing an issue with compiling though. I'm able to compile for 21 but not for 20. Version of MSVC seems to be matching the one from the documentation but houdini ignores my dll for some reason and I get an error saying using incompatible compiler. I've already installed 3 different version of MSVC and tried to compile with each one but h20 still won't see my dll and h21 works just fine.
Any ideas on why that might happen?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB