Syrux Posted November 22, 2014 Share Posted November 22, 2014 I realize that there is some inheritance/hierarchy witchcraft that is stopping my code from compiling properly (undeclared identifier). I have tried many snippets of code that are supposed to create attributes, but they only work inside the cookmysop function. So, how can I create an attribute outside cookmysop() that is at the same time accessible by the cookmysop function and avoids inheritance problems? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted November 23, 2014 Share Posted November 23, 2014 It's not true. You can add attributes anywhere, all you need is a pointer to your geometry. Basically you get your geometry in cookMySop by calling duplicateSource(), then you can pass gdp pointer anywhere you want.I'm not sure, but i think you can also do something with a geometry in a constructor of your SOP_Node. Quote Link to comment Share on other sites More sharing options...
Syrux Posted November 23, 2014 Author Share Posted November 23, 2014 Edward in the sidefx forum replied that it is not allowed. I really don't want to create an attribute everytime the sop cooks. I am working right now with the CPP_Wave example. If you know how to create the attribute, please tell me. Quote Link to comment Share on other sites More sharing options...
Syrux Posted November 23, 2014 Author Share Posted November 23, 2014 It's not true. You can add attributes anywhere, all you need is a pointer to your geometry. Basically you get your geometry in cookMySop by calling duplicateSource(), then you can pass gdp pointer anywhere you want. I'm not sure, but i think you can also do something with a geometry in a constructor of your SOP_Node. Edward in the sidefx forum replied that it is not allowed. I really don't want to create an attribute everytime the sop cooks. I am working right now with the CPP_Wave example. If you know how to create the attribute, please tell me. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted November 23, 2014 Share Posted November 23, 2014 You are writing SOP? If not, of course it's not allowed to modify geometry outside your operator, although you can do it, it's just a very bad idea. So, if you are writing sop, whats a problem to add attributes in cookMySop? Quote Link to comment Share on other sites More sharing options...
Syrux Posted November 23, 2014 Author Share Posted November 23, 2014 (edited) You are writing SOP? If not, of course it's not allowed to modify geometry outside your operator, although you can do it, it's just a very bad idea. So, if you are writing sop, whats a problem to add attributes in cookMySop? Yes, I am writing a SOP. The problem is that I need to create a initial value/attribute. Imagine you have a grid then each point checks its neighbours (like the game of life), if that neighbour is blue then the point that its checking neighbours also becomes blue, and so on. So, If I create the attribute each time the sop cooks, the points will never change, because they will always have the initial value. I have tried the folllowing snipet that doesn't work. but I am really out of ideas: void createAttr(GU_Detail *gdp){ GA_RWAttributeRef attr; // This two lines attr = gdp->addFloatTuple(GA_ATTRIB_POINT, "Normal",3); // work perfectly inside the cookmysop() } I found this SOP code that creates a geometry pointer and adds atributters outside the cookmysop, I tried to do the same but I get the same errors. bool SOP_Centroid::createBaseGdp() { m_baseGdp = new GU_Detail; m_baseGdpHdl.allocateAndSet(m_baseGdp,true); bool ret_val = true; if (m_addBBoxDimension) { //UT_Vector3 *sizeDef = new UT_Vector3(1,1,1); GU_DetailHandleAutoWriteLock wLock(m_baseGdpHdl); m_dimID = wLock.getGdp()->addFloatTuple(GA_ATTRIB_POINT,GA_SCOPE_PUBLIC,sizeAttrName.buffer(),3,GA_Defaults(1.0f)); ............. Edited November 23, 2014 by Syrux Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 23, 2014 Share Posted November 23, 2014 I found this SOP code that creates a geometry pointer and adds atributters outside the cookmysop... No it doesn't. This method is executed inside cookMySop() in line 1018. To create something SOP have to cook. Quote Link to comment Share on other sites More sharing options...
Syrux Posted November 23, 2014 Author Share Posted November 23, 2014 (edited) No it doesn't. This method is executed inside cookMySop() in line 1018. To create something SOP have to cook. Well, that was my last resource. Any ideas? What if I create two cookmysop: one time dependant and the other time independent? Edited November 23, 2014 by Syrux Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 23, 2014 Share Posted November 23, 2014 (edited) Why do you have to create attribute and compare it in the same SOP? That assumes that you expect that geometry on your input comes with something that you want to compare. So why not add second input that will be used as a comparision value, and then in you SOP use it to walk thru your geometry and set values? And if you insists, you can compare you newly created attribute with you input geometry, which is const, and apply modification only to duplicated geometry. This gets const geometry from first input auto gdp0 = inputGeo(0, context); This creates gdp in current SOP. duplicateSource(); Ude gdp0 as a lookup, and set values in gdp. Edited November 23, 2014 by mantragora Quote Link to comment Share on other sites More sharing options...
Syrux Posted November 23, 2014 Author Share Posted November 23, 2014 (edited) @Mantra Why do you have to create attribute and compare it in the same SOP? That assumes that you expect that geometry on your input comes with something that you want to compare. So why not add second input that will be used as a comparision value, and then in you SOP use it to walk thru your geometry and set values? Interesting solution. But unfortunately, I don't need to compare attributes, I just need to create the attribute. Like in the Game of Life. You don't compare initial values, you call the current value of neighbors. But as I explained before, I can't create the attribute if I need that attribute to change over time, that's why I need to create the attribute only one time (outside cookmysop). Edited November 23, 2014 by Syrux Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 23, 2014 Share Posted November 23, 2014 That means you need something time dependent. Maybe it's time to look into POPs/DOPs? Quote Link to comment Share on other sites More sharing options...
Syrux Posted November 23, 2014 Author Share Posted November 23, 2014 @Mantra Temporal solution: fpreal frame = OPgetDirector()->getChannelManager()->getSample(context.getTime()); if (frame == 1){ create attribute; } Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 24, 2014 Share Posted November 24, 2014 (edited) You could also check if the attribute already exists, if so, just get it, otherwise create it. I'm not sure which attribute creation method you will take, but it should look something along those lines: auto normalRef = gdp->findFloatTuple(GA_ATTRIB_POINT, "N", 3); if (normalRef.isInvalid()) normalRef = gdp->addFloatTuple(GA_ATTRIB_POINT, "N", 3); auto normalTuple = normalRef.getAIFTuple(); Edited November 24, 2014 by mantragora 1 Quote Link to comment Share on other sites More sharing options...
Syrux Posted November 24, 2014 Author Share Posted November 24, 2014 (edited) Ok, That's basically my code, Another thing I want to get the bounding box, do I have to do it the same way? UT_BoundingBox bbox; gdp->getPointBBox(&bbox, 0); cout << bbox.ymax(); This works, but inside (again) cookmysop(). I know that there are some classes that allows you to define it outside the cook, like the VRAY procedural. But unfortunately, I'm working with point clouds. Edited November 24, 2014 by Syrux Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 24, 2014 Share Posted November 24, 2014 Why are you so afraid of cookMySop()? This is you Main() method. It's like you would like to create program, but to run it you would like to use everything but Main() No other class will solve your problem. VRAY is for rendertime procedural generation. It has nothing to do with SOPs, beside that it takes the data they create. 1 Quote Link to comment Share on other sites More sharing options...
Syrux Posted November 24, 2014 Author Share Posted November 24, 2014 (edited) @Mantra Funny thing is that I just started with HDK few days ago (when I made the first question), I now I am talking with you about these things, thank you for sharing your knowledge with me. Have a good night/day! Edited November 24, 2014 by Syrux Quote Link to comment Share on other sites More sharing options...
Syrux Posted November 26, 2014 Author Share Posted November 26, 2014 (edited) That means you need something time dependent. Maybe it's time to look into POPs/DOPs? Does this means that I cant make a simple Game of Life or a Flood Fill algoritm in HDK, using SOP? Edited November 26, 2014 by Syrux Quote Link to comment Share on other sites More sharing options...
Syrux Posted November 26, 2014 Author Share Posted November 26, 2014 @Mantra, found it! Oh my gosh what a headache, look at the code in this question: http://forums.odforce.net/topic/4310-hdk-sop-sim-cook-problem/?hl=timedep Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 26, 2014 Share Posted November 26, 2014 I'm not familiar with any of those two algorithms, so I'm not sure what to look for to solve this problem. If the code works for you, that's cool. Just make sure that you don't write code using deprecated stuff. Does this means that I cant make a simple Game of Life or a Flood Fill algoritm in HDK, using SOP? @Mantra, found it! Oh my gosh what a headache, look at the code in this question: http://forums.odforce.net/topic/4310-hdk-sop-sim-cook-problem/?hl=timedep Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted November 26, 2014 Share Posted November 26, 2014 http://www.sidefx.com/index.php?option=com_forum&Itemid=172&page=viewtopic&p=30428&highlight=&sid=0303e22b4cd9addeceb2d85a30d1bc97 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.