Jump to content

Accessing gdp in callback function


Recommended Posts

Hello everyone,

I want to be able to write a callback function that sets the cd attribute to something but i couldn't manage to get a GU_Detail that allows attribute write. Even if i was able to modify the attribute handle, i couldnt manage to get it back to main scope. Pls take a look at my code. thanks.

PRM_Template(PRM_CALLBACK, 1 , &names[7] , 0 , 0 , 0, &setToPos),

//This crashes houdini

int SOP_myTest::setToPos(void *data, int index, float time, const PRM_Template *tplate){

SOP_myTest *me;

me = (SOP_myTest *) data;

OP_Context myContext(time);

GU_DetailHandle gdh(me->curGdh(index));

GU_Detail *gdp = gdh.writeLock();

GA_Offset ptoff;

UT_String string = NULL;

UT_Vector3 colorValue;

UT_Vector3 posValue;

GA_RWHandleV3 colorHandle(gdp , GA_ATTRIB_POINT , "Cd");

GA_ROHandleV3 normalHandle(gdp , GA_ATTRIB_POINT , "N");

GA_ROHandleV3 posHandle(gdp , GA_ATTRIB_POINT , "P");

GA_FOR_ALL_PTOFF(gdp, ptoff){

posValue = posHandle.get(ptoff);

colorHandle.set(ptoff, colorValue);

}

gdp->bumpAllDataIds();

return 1;

}

//This doesn't crash but does nothing..

GU_DetailHandleAutoWriteLock gdh(me->getCookedGeoHandle(myContext,0));

GU_Detail *gdp = gdh.getGdp();

//This also gets gdp but GA_RWHandleV3 colorHandle(gdp , GA_ATTRIB_POINT , "Cd"); does not accept const gdp.

const GU_Detail *gdp = me->curGdp(index);

//this crashes houdini too

const GU_DetailHandle gdh = me->curGdh(index);

GU_DetailHandle gdl = gdh.duplicateGeometry();

GU_Detail *gdp = gdl.writeLock();

//This gives me a const gdp too (can i convert from a const gdp to a write gdp ?)

const GU_Detail *gdp = me->getCookedGeo(myContext);

// This also does nothing

const GU_Detail *gdp = me->getCookedGeo(myContext);

GU_Detail *my_gdp = new GU_Detail;

my_gdp->duplicate(*gdp);

Edited by sergio
Link to comment
Share on other sites

My understanding is that you can't - gdp is recreated on every cook and your SOP acts like filter on the geometry.
May be you could create and store in your SOP a GA_Attribute on callback and then duplicate it in the GU_Detail on cook?

Sorry, seems I can't help.

Edited by millag
Link to comment
Share on other sites

Actually that helps, maybe i can create a global GA_Attribute and return the last value in cookme function. But everybody seems to tell that global variables are the spawn of satan and should never be used.

Link to comment
Share on other sites

Global variables are evil !
I still don't understand what you want to achieve exactly?
If the value you want to set as color doesn't vary per point/vertex why not store it as a spare parameter on the node (you may hide if you wish) and on cook read whatever is stored in the parameter...

 

Edited by millag
Link to comment
Share on other sites

  • 2 weeks later...

You could/should always keep the attribute creation work in the cookMySop function, then just have the callback call "cook()".  If you set up cookMySop to only deal with the attribute creation on that cook you should get the same results.

 

However *in theory* every cook you get the GU_Detail from the node's input, so all changes to that node are always destroyed.  Unless you don't get the input geo at all, in which case you simply ignore the input and so long as you don't call clearAndDestroy(), your geometry and attributes should remain unchanged.

 

However in your case it seems like you want create an attribute outside of the main gdp then merge it with your nodes input, the best way to handle that would probably be to create a UT_Array for your attributes data (which will work fine in a callback) then call setAttributeFromArray in cookMySop().  Probably the simplest and safest way to do it, should be fast too.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...