soumitra.goswami Posted November 5, 2015 Share Posted November 5, 2015 Hey all, I am having problems creating attributes in HDK. The attribute I create shows up on the first frame(which is when i create it) and then disappears in the rest of the frames. Please check the cookmySop function. I am pretty sure I am doing something stupid. Currently what I want is to take my geometry and create a spring force . So for the first step I am trying to setup my velocity, position and force attributes. So I copy my sourceGeometry into my gdp and try to manipulate the points there as per the examples. Please help me out as I am completely lost as to why this is happening. here is a snippet. mySource = inputGeo(0,context); duplicateSource(0,context); //gdp->copy(mySource,GEO_COPY_ONCE); flags().timeDep = 1; CH_Manager *chman = OPgetDirector()->getChannelManager(); fpreal frame = chman->getSample(context.getTime()); fpreal reset = STARTFRAME(); //frame = frame/30.0; if (frame<=reset || !mySource) { my_lastCookTime = reset; //initSystem(); myPos = GA_RWHandleV3(gdp->findAttribute(GA_ATTRIB_POINT, "P")); GA_RWHandleV3 attrib = gdp->findAttribute(GA_ATTRIB_POINT,"v"); if ( gdp->getPointMap().indexSize() > 0 || !mySource) { myVelocity = GA_RWHandleV3(gdp->addFloatTuple(GA_ATTRIB_POINT,"v",3)); //myVelocity = GA_RWHandleV3(gdp,GA_ATTRIB_POINT, "v"); if(myVelocity.isValid()){ myVelocity.getAttribute()->setTypeInfo(GA_TYPE_VECTOR); myVelocity->setTupleSize(3); UT_Vector3 V; for (GA_Iterator it(gdp->getPointRange()); !it.atEnd(); ++it) { GA_Offset offset = *it; UT_Vector3 V = UT_Vector3(0,0,0); myVelocity.set(offset,UT_Vector3(0,0,0)); cout << "velocity2: " << myVelocity->getTupleSize() <<endl; } } } } else { frame += 0.05;//tollerance //notifyGroupParmListeners(0,-1,mySource,NULL); while (my_lastCookTime < frame) { cout << "velocity3: " << myVelocity->getTupleSize() <<endl; timeStep(chman->getSample(my_lastCookTime)); my_lastCookTime += 1; } } Project4.zip Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted November 6, 2015 Share Posted November 6, 2015 In a SOP you can't create an attribute just on the first frame. You need to create it on every Cook. The way a SOP works is by re-evaluating the previous nodes geometry on every cook thus no data added from the current node will "loop" back around. You would need to cache the geometry on the first cook. However I would recommend if your insistent on doing simulations in SOPs instead of DOPs, I would simply create a std::unordered_map<GA_Offset, UT_Vector3> (as a member of your SOP_Node derived class) for each of the attributes. Or you could use a std::vector<UT_Vector3> which would be more efficient but when you loop through you should be sure to use Indices as offsets could have empty slots. Quote Link to comment Share on other sites More sharing options...
soumitra.goswami Posted November 8, 2015 Author Share Posted November 8, 2015 (edited) Hey MrScienceOfficer, Thank you for your reply. Really appreciate it. I figured out the problem I was having. My duplicateSource was being called every frame. Since my source didn't have a velocity attribute it kept copying its attribute onto my gdp. Hence my custom velocity attribute disappeared in my GDP after the first frame(since I was creating it only on the first frame). As soon as I moved my duplicateSource inside my first frame check ,it worked. I respectfully disagree that attribute needs to be created every frame. If you look at the S_Particle.C example file you will see them creating variable tuples only on the first frame. Since its added to the gdp, it handles it for the rest of the frames ( Unless it gets overwritten which was happening in my case). You are right that I needed to cache my geometry with the duplicateSource only on the first cook and that was the issue I was having as it was caching it on every frame. Thank you for pointing that out. I do use Vector<UT_Vector3> as a state variable to store my positions, velocities and Forces. Helps when calculating RK4 integration. I will post more updates soon. Edited November 8, 2015 by soumitra.goswami Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted November 9, 2015 Share Posted November 9, 2015 I respectfully disagree that attribute needs to be created every frame. If you look at the S_Particle.C example file you will see them creating variable tuples only on the first frame. Since its added to the gdp, it handles it for the rest of the frames ( Unless it gets overwritten which was happening in my case). You are right that I needed to cache my geometry with the duplicateSource only on the first cook and that was the issue I was having as it was caching it on every frame. Thank you for pointing that out. Yes one or the other, you must either cache the geo or recreate the attribute. Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted June 17, 2016 Share Posted June 17, 2016 On 11/5/2015 at 7:36 PM, MrScienceOfficer said: In a SOP you can't create an attribute just on the first frame. You need to create it on every Cook. The way a SOP works is by re-evaluating the previous nodes geometry on every cook thus no data added from the current node will "loop" back around. You would need to cache the geometry on the first cook. A little late, but it appears that I'm quite wrong about this, I just assumed a chain of nodes shares the same GU_Detail. But each node couldn't possible create a full copy of the GU_Detail for each cook, could it? There must be more complex rules for how Details are stored and copied, or does duplicateSource() literally do just that. Does anyone how this actually works? 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.