Jump to content

Sop solver previous frame data as attribute

Recommended Posts

I am currently using a sop solver to update the position the position of some points based on the current position. I need to save the current position as a new attribute to calculate the distance between the new position and the current position. 

My approach was to save the attribute out before I do the calculation, so that each position will be saved as an attribute before the calculation. 

However, the doesn't seem to work

I did :


my calculation which is v@P+=@V*timestep; 



as you can see, the @prevPos in frame 2 should equal to @P in frame 1, but it doesn't?




Share this post

Link to post
Share on other sites

might be some details lost in your exact setup? hard to tell without a HIP.

here's a working example.

Share this post

Link to post
Share on other sites

I just compared my file and yours, I realised the problem is the substeps, I used a substep of 10 in your file and the same issue happened, how could I fix this problem?

Share this post

Link to post
Share on other sites

There might be an easier way to do this; I would love to see one.

The problem is that `v@prev_P` was being set on each substep, including the last one right before the frame is done, so `v@prev_P` is returning the value 9/10ths of the way along. In order to fix this, `v@prev_P` has to only be set on the first substep of each frame.

The expression to determine the step number looks like this:
`i@stepnum += int( rint( (1/(@TimeInc * steps) * steps) * @TimeInc ) );`

where `steps` is the number of substeps on the SOP Solver.

Next, I check if we're on the first substep of a frame:
`if(((i@stepnum - 1) % steps) == 1) {
    v@prev_P = @P;

The `i@stepnum - 1` is necessary because the SOP Solver is set to cook on creation frame.

I'm attaching an example file. 


Edited by toadstorm

Share this post

Link to post
Share on other sites

Thank you so much ! That solved my problem , caching the position every 10 substeps 

I had to also add || @Frame == ch("../../../startframe") in order to get the position before the start frame, as I was using the intersect function and it was firing the ray from the origin to my starting positions.

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