# 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 :

v@prevPos=@P;

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

v@nextPos=@P;

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

##### 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 on other sites

duhhh, forgot to attach file.

prev_P_example.hip

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

prev_P_example_substeps.hip

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

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×