Jump to content

Issues with creating attributes


Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by soumitra.goswami
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 7 months later...
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?

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...