sergio Posted March 9, 2016 Share Posted March 9, 2016 (edited) 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 March 10, 2016 by sergio Quote Link to comment Share on other sites More sharing options...
millag Posted March 14, 2016 Share Posted March 14, 2016 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? Quote Link to comment Share on other sites More sharing options...
sergio Posted March 14, 2016 Author Share Posted March 14, 2016 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 Quote Link to comment Share on other sites More sharing options...
millag Posted March 15, 2016 Share Posted March 15, 2016 (edited) 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 March 15, 2016 by millag Quote Link to comment Share on other sites More sharing options...
sergio Posted March 15, 2016 Author Share Posted March 15, 2016 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. Quote Link to comment Share on other sites More sharing options...
millag Posted March 16, 2016 Share Posted March 16, 2016 (edited) 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 March 16, 2016 by millag Quote Link to comment Share on other sites More sharing options...
sergio Posted March 16, 2016 Author Share Posted March 16, 2016 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. Quote Link to comment Share on other sites More sharing options...
millag Posted March 17, 2016 Share Posted March 17, 2016 May be this thread will answer your question:https://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&t=35230&sid=999ba8f96ccf0d8105782f48e174640a Quote Link to comment Share on other sites More sharing options...
sergio Posted March 17, 2016 Author Share Posted March 17, 2016 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 ? Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted March 31, 2016 Share Posted March 31, 2016 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.