Jump to content
Latimerias

How to do feedback loops in VEX to create a "Stacking" effect. Also free book generator/placer HDA.

Recommended Posts

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 by Latimerias

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
Share on other sites

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 by Latimerias

Share this post


Link to post
Share on other sites
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

image.thumb.png.f8432be2f839978776f88422ac32f9b2.png

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

×