Em_Fn Posted January 16, 2018 Share Posted January 16, 2018 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? Quote Link to comment Share on other sites More sharing options...
toadstorm Posted January 16, 2018 Share Posted January 16, 2018 might be some details lost in your exact setup? hard to tell without a HIP. here's a working example. Quote Link to comment Share on other sites More sharing options...
toadstorm Posted January 16, 2018 Share Posted January 16, 2018 duhhh, forgot to attach file. prev_P_example.hip Quote Link to comment Share on other sites More sharing options...
Em_Fn Posted January 17, 2018 Author Share Posted January 17, 2018 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? Quote Link to comment Share on other sites More sharing options...
toadstorm Posted January 17, 2018 Share Posted January 17, 2018 (edited) 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 Edited January 17, 2018 by toadstorm Quote Link to comment Share on other sites More sharing options...
Em_Fn Posted January 17, 2018 Author Share Posted January 17, 2018 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.