Latimerias Posted December 5, 2021 Share Posted December 5, 2021 (edited) I cannot seem to wrap my head around how to do this so I am asking here. Im looking for a way to "stack" values with VEX. If i simplify it I want to create a point and assign it a random value, then move it that value in the x direction. After that I want to create a second point, give it a new random value and move it that distance + the distance of the first point. The purpose is to create a point generator with random scale values that i can use with LOPs inside of an instancer to place books next to eachother at random scales. I made this in sops and it worked well on a smaller scale but I ended up doing a few thousand books and overloaded my ram. Currently what i have is this. int iter = chi("Iterations"); float minwidth = chf("Min_Width"); float maxwidth = chf("Max_Width"); for(int i = 0; i < iter; i++){ float currentwidth = fit01(rand(i), minwidth, maxwidth); float prevwidth = fit01(rand(i-1), minwidth, maxwidth); vector pos = set(prevwidth+currentwidth/2, 0, 0); int pt = addpoint(0, pos); } My thought process was to create a random value based on the iteration, this random number would be the book width scale value, which is just fitted so i dont get small values. Then to get the previous books width i would subtract the iteration by 1 which successfully returns the same value. Then i create a point and move it by the previous book width + the current book width/2 because i want the point to be centered. However this doesn't work at all because it can only access a single value back. Also i uploaded the sop book generator below if anyone was interested, its pretty flawed the more that i look at it i should have split it into separate HDAs and also you need to have your coordinates set to Z-up. Heres a demo of it through if anyones interested. jw_book_generator.1.0.hdanc Edited December 5, 2021 by Latimerias Quote Link to comment Share on other sites More sharing options...
animatrix Posted December 5, 2021 Share Posted December 5, 2021 Hi, You can use the Solver SOP to accumulate data from the previous frame. Alternatively you can also use a For Loop network in Feedback mode. 1 Quote Link to comment Share on other sites More sharing options...
Latimerias Posted December 5, 2021 Author Share Posted December 5, 2021 (edited) This is what I did in the sops method i attached, is there a way to do this in VEX? I realize i would be better using a while loop probably, because i want to stop once the total distance is greater than the length of the shelf. Edited December 5, 2021 by Latimerias Quote Link to comment Share on other sites More sharing options...
animatrix Posted December 5, 2021 Share Posted December 5, 2021 If you want to do that in VEX, you have to use a for loop inside VEX to do the accumulation. Quote Link to comment Share on other sites More sharing options...
Ziyad Posted December 5, 2021 Share Posted December 5, 2021 7 hours ago, Latimerias said: If i simplify it I want to create a point and assign it a random value, then move it that value in the x direction. After that I want to create a second point, give it a new random value and move it that distance + the distance of the first point. Hi, You can do this inside a SOP solver like Animatrix mentioned, through a for loop or if statements like what I provided in the example. Essentially you're targeting the last point created then adding a new point based on the last point's position + a new random X value. Also you can control the max distance to make sure the solver doesn't create points beyond a certain distance. generating_points.hiplc Quote Link to comment Share on other sites More sharing options...
vinyvince Posted December 6, 2021 Share Posted December 6, 2021 A for each will works as well or better 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.