Welcome to od|forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

sergio

Accessing gdp in callback function

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

Share this post


Link to post
Share on other sites

Houdini crashes because you are not releasing the detail lock.
I might be wrong but I think the detail (including all attributes) gets overwritten on the next cook. Have you tried setting the "Cd" attribute on cook?

Share this post


Link to post
Share on other sites

I can set the attribute in cookMySop's scope but what im really wandering if it is possible to do it in a function or callback

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Im just curious if heavy tasks as attribute creation can be done when user asks for it. And it may as well be a per point varying attribute.

Share this post


Link to post
Share on other sites

Thanks Mila, that really helped. I wanna try the gdp->notifyCache(GU_CACHE_ALL) but seems it doesn't have a GA equivalent. Is it refreshCachedHandles ?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now