Jump to content
eko

Do simulation in Sop

Recommended Posts

Hi, I got a question about doing simulation in sop.(Because I don't have a master license).
Accoding to the thread http://forums.odforce.net/topic/4310-hdk-sop-sim-cook-problem/?hl=timedep.I rewrite the code.

OP_ERROR
SOP_TEST::cookMySop(OP_Context &context)
{
    long frame;
    int initframe;
    UT_Interrupt *boss;
    myGroup=0;
    fpreal now = context.getTime();
    frame = context.getFrame();

    GA_Offset ptoff;
    fpreal mx = MaxDis(now);
    if (lockInputs(context) >= UT_ERROR_ABORT)
	   return error();

    OP_Node::flags().timeDep = 1;   /////////

    initframe = 1;

    if (error() < UT_ERROR_ABORT)
    {
	   if(frame == initframe)
	   {
		  boss = UTgetInterrupt();
		  boss->opStart("Initializing");
	 	  gdp->clearAndDestroy();
	 	  duplicateSource(0, context);
		  boss->opEnd();
	   }

	   else
	   {
		  boss = UTgetInterrupt();
		  boss->opStart("Setting new grid positions");

		  GA_FOR_ALL_GROUP_PTOFF(gdp, myGroup, ptoff)
		  {
			 if (boss->opInterrupt())
			    break;

			  UT_Vector3 pos=gdp->getPos3(ptoff);
			  pos[1]+=mx;
			  gdp->setPos3(ptoff,pos);
		  }
		  boss->opEnd();
	   }
    }

    unlockInputs();
    myCurrPoint = -1;
    return error();

}

This all works fine when I play though the frames sequentially. If I jump forward in the time bar 20 frames, right now it only cooks the 20th frame and doesn't automatically cook all the frames in between(like the particle sop does)(like the particle sop does). It seemed like it only do a cook when the frame changes.

 

What I got to do is to cook all the frame between the 20 frames.I got some ideas from HDK documents

cook_time = myLastCookTime;
for ( ; cook_time <= now ; cook_time += frame_inc)
{
context.setTime(cook_time);
.........
}

But I dont know how to get the "myLastCooktime". Does Anyone got a Idea?

 

And another strange thing is when I change the Parameter((MaxDis), it will also do the cook which I dont want.

 

Thanks

Edited by eko

Share this post


Link to post
Share on other sites

I've never actually tried this so I don't know if fundamentally what you are doing is the right way to do it. But purely from what you have already posted, wouldn't you just say myLastCookTime starts at 1 or some user defined sim start point, and then once your cook loop has run just set it equal to "now" ready for the next jump in time. You'll probably need to reset it to 1 again if myLastCookTime > now.

Share this post


Link to post
Share on other sites

Thanks for your reply.

if myLastCookTime > now. I will do nothing. I need to keep the lastest cook result. It's just like the spring sop node. If I jump forward to 120f. It will automatically cook all the frames in between 120f and then When I jump back to 50f. It will keep the result same with 120f

Share this post


Link to post
Share on other sites

Hi,there

I find the way! myLastCookTime=CHgetEvalTime();  It works fine to me.

Another question, does anyone knows how to get the points connected to the given point in hdk13?

Thanks!

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

×