Jump to content

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
Link to comment
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.

Link to comment
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

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