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?




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

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.

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