Random value at random time
11060 17 1- SpaceCraft
- Member
- 7 posts
- Joined: Feb. 2014
- Offline
- sepu
- Member
- 436 posts
- Joined: Feb. 2012
- Offline
- SpaceCraft
- Member
- 7 posts
- Joined: Feb. 2014
- Offline
- BabaJ
- Member
- 2048 posts
- Joined: Sept. 2015
- Offline
- SpaceCraft
- Member
- 7 posts
- Joined: Feb. 2014
- Offline
- BabaJ
- Member
- 2048 posts
- Joined: Sept. 2015
- Offline
In Python Source Editor:
In Scatters Global Seed Parameter:
Just be ‘warned’ that the code I'm showing you is basically making a type of ‘global’…sometimes doing things this way can result in having to do a lot of clicking to get your scene to reset at the beginning with values that can be used.
You know this is happening if you only ever get zero in your global seed paramter of the scatter node.
This is the reason I put the default of Result = 0.
And, because you asked for it to be random, everytime you open your file you will get a different range of frames that will randomize - if this is the behaviour you want.
Also, while the file is open and you want it to change with a ‘reset’ when you rewind to the beginning just go into Python Source Editor and click on Reload and Apply then reset on the playbar.
However, if this is too much randomness, you could just make how many frames in total that will end up being randomized, ie. say you only want it to randomize 5 different times although at different times ( random ), you could do that too. I think if you look at the code you should be able to figure out how to do that if that's your wish.
Thanks for the ‘challenge’…I don't think it's the most ‘elagant’…but the best I can do…maybe someone could show a more clever way to do this
import hou
import random
Hold_Value = 0
Frames_That_Randomize = []
Number_Of_Changes = int(random.random() * hou.playbar.playbackRange()[1])
def Randomize_Number_Of_Changes(int):
for Count in range(hou.session.Number_Of_Changes):
hou.session.Frames_That_Randomize.append(random.random() * hou.playbar.playbackRange()[1])
Randomize_Number_Of_Changes(Number_Of_Changes)
In Scatters Global Seed Parameter:
import random
Result = hou.session.Hold_Value
Desired_Seed_Range = 5
for Count in range(hou.session.Number_Of_Changes):
if( hou.frame() == int(hou.session.Frames_That_Randomize[Count])):
Result = random.random() * Desired_Seed_Range
hou.session.Hold_Value = Result
return hou.session.Hold_Value
Just be ‘warned’ that the code I'm showing you is basically making a type of ‘global’…sometimes doing things this way can result in having to do a lot of clicking to get your scene to reset at the beginning with values that can be used.
You know this is happening if you only ever get zero in your global seed paramter of the scatter node.
This is the reason I put the default of Result = 0.
And, because you asked for it to be random, everytime you open your file you will get a different range of frames that will randomize - if this is the behaviour you want.
Also, while the file is open and you want it to change with a ‘reset’ when you rewind to the beginning just go into Python Source Editor and click on Reload and Apply then reset on the playbar.
However, if this is too much randomness, you could just make how many frames in total that will end up being randomized, ie. say you only want it to randomize 5 different times although at different times ( random ), you could do that too. I think if you look at the code you should be able to figure out how to do that if that's your wish.
Thanks for the ‘challenge’…I don't think it's the most ‘elagant’…but the best I can do…maybe someone could show a more clever way to do this
- neil_math_comp
- Member
- 1743 posts
- Joined: March 2012
- Offline
One trick that seems to work: Scatter based on density on a line that represents the frame range, count the points that occur before a certain x value, and use that as the seed.
In the attached example, I put a parameter on a Null SOP that lets you control on average how many frames between the transitions (i.e. 1 over the average number of changes per frame). If the intervals vary a bit too much, you can turn on Relax Iterations on the Scatter SOP scattering on the line to something small.
In the attached example, I put a parameter on a Null SOP that lets you control on average how many frames between the transitions (i.e. 1 over the average number of changes per frame). If the intervals vary a bit too much, you can turn on Relax Iterations on the Scatter SOP scattering on the line to something small.
Edited by neil_math_comp - March 7, 2017 17:30:53
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
- SpaceCraft
- Member
- 7 posts
- Joined: Feb. 2014
- Offline
- neil_math_comp
- Member
- 1743 posts
- Joined: March 2012
- Offline
SpaceCraftCould you be more specific? For example, does the file not load at all, or does the seed not change when you play the scene?
ndickson, it seems that you file doesn't work. I don't know why.
In case it's a licensing issue, here are an Indie (hiplc) and an Apprentice (hipnc) file.
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
- BabaJ
- Member
- 2048 posts
- Joined: Sept. 2015
- Offline
Yeah..I had a look at your file too ndickson because I was interested in doing it a different way.
In your point wrangle node you don't do anything with P vector assigned in the while loop; Other than breaking when a condition is met. But the end result is that you just keep on looping through the for loop until it's finished with no ‘event’ happening. I'm assuming the P value assigned was meant to be @P or something else and to be used elswhere ?
is a local variable to the point wrangle and doesn't get used, so why is it being assigned a value?
Seems to me this is where the problem lies.
In your point wrangle node you don't do anything with P vector assigned in the while loop; Other than breaking when a condition is met. But the end result is that you just keep on looping through the for loop until it's finished with no ‘event’ happening. I'm assuming the P value assigned was meant to be @P or something else and to be used elswhere ?
vector P
Seems to me this is where the problem lies.
int nframechanges = `$RFEND-$RFSTART`;
int npointsless = 0;
int npointstotal = npoints(1);
for (int i = 0; i < nframechanges+1; ++i) {
int pt = addpoint(geoself(),{0,0,0});
setpointattrib(geoself(),"seed",pt,npointsless);
while (npointsless < npointstotal) {
vector P = point(1,"P",npointsless);
if (P.x >= i+1) {
break;
}
++npointsless;
}
}
Edited by BabaJ - March 8, 2017 13:40:27
- neil_math_comp
- Member
- 1743 posts
- Joined: March 2012
- Offline
BabaJThe purpose of the while loop is to update npointsless. It's just counting the number of points whose x coordinate is less than i+1, (i.e. the number of seed changes that occur before the next frame), so it exits the loop once some P.x is >= i+1. The only attribute written-to by that Attribute Wrangle is “seed”. The positions of the nframechanges+1 added points are not used, so I kept them all at zero. You could set them to set(i,0,0) instead of {0,0,0} if you like, but it's not necessary.
you don't do anything with P vector assigned in the while loop; Other than breaking when a condition is met.
The file works correctly for me in 16.0.539. Does it not work for you?
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [www.youtube.com]
- SpaceCraft
- Member
- 7 posts
- Joined: Feb. 2014
- Offline
I'm on H15, not H16. the seed doesn't change at all. I get error when opening the file (I wasn't able to see them before). Apparantly it can't recognize some vex stuff (vex_inplace, vex_selectiongroup, and Mat operator)
In any case, someone helped me to do it with a small wrangle. This is the thing to put in an Attribute Wrangle with Detail mode.
And you put the f@seed attribute to where you want it. It's not a random value (it just add 1) but it works.
Thanks for the help, I'm still looking at your scene to learn other way to do it !
In any case, someone helped me to do it with a small wrangle. This is the thing to put in an Attribute Wrangle with Detail mode.
float s = ch(“seed”);
int min = int(ch(“min”));
int max = int(ch(“max”));
float r = rand(s);
int period = int(fit01(r, min, max));
f@seed = 0;
while (@Frame > period) {
f@seed += 1;
r = rand((s+.31456) * f@seed);
period += int(fit01(r, min, max));
}
And you put the f@seed attribute to where you want it. It's not a random value (it just add 1) but it works.
Thanks for the help, I'm still looking at your scene to learn other way to do it !
Edited by SpaceCraft - March 8, 2017 13:55:25
- BabaJ
- Member
- 2048 posts
- Joined: Sept. 2015
- Offline
Ay..my bad…I overlooked the…++npointsless;
…Actually, because I don't typically use the break statement…one of those old school things I picked up long ago where it was suggested using break generally is not considered good coding practice…not that I hold that to be true, but as a beginner just sort of adopted the practice of not using it if I can help it.
As such I forget how break works…looking at your code I assumed wrongly that you were only breaking from the if statement…which is absurd to think that since it is only depending on a single comparison.
Ok..yeah..so I had the default open file from forum set to H15 and it doesn't work. But selected H16 and it does work.
Thanks for this example.
…Actually, because I don't typically use the break statement…one of those old school things I picked up long ago where it was suggested using break generally is not considered good coding practice…not that I hold that to be true, but as a beginner just sort of adopted the practice of not using it if I can help it.
As such I forget how break works…looking at your code I assumed wrongly that you were only breaking from the if statement…which is absurd to think that since it is only depending on a single comparison.
Ok..yeah..so I had the default open file from forum set to H15 and it doesn't work. But selected H16 and it does work.
Thanks for this example.
Edited by BabaJ - March 8, 2017 14:08:32
- jsmack
- Member
- 7846 posts
- Joined: Sept. 2011
- Offline
- SpaceCraft
- Member
- 7 posts
- Joined: Feb. 2014
- Offline
- BabaJ
- Member
- 2048 posts
- Joined: Sept. 2015
- Offline
….If your ok with ‘fixed’ random values, instead of chops…
you could just make a simple list in the global seed parameter itself.
No other external sources like chops, vex nodes or like in my original example, python source editor.
Making changes is simple too for more or less frames and values…just delete or copy/paste.
you could just make a simple list in the global seed parameter itself.
No other external sources like chops, vex nodes or like in my original example, python source editor.
Making changes is simple too for more or less frames and values…just delete or copy/paste.
Edited by BabaJ - March 9, 2017 10:11:44
- SpaceCraft
- Member
- 7 posts
- Joined: Feb. 2014
- Offline
Well, in that particular case, since I'm dealing with Seed value, just changing the value, no matter how (random or fixed increment) will give me a random scatter result. So the vex code I gave with fixed random value is doing the trick.
The chop solution give a visual result wich is usefull and I think I should look into chops a bit more.
I thought about doing a manual list, but it needed to be a procedural thing.
thanks for all of your answers
The chop solution give a visual result wich is usefull and I think I should look into chops a bit more.
I thought about doing a manual list, but it needed to be a procedural thing.
thanks for all of your answers
- BabaJ
- Member
- 2048 posts
- Joined: Sept. 2015
- Offline
Manual List not procedural?
The list is defined by the sequence of frames.
Also, it is self contained in the paramater so nodes before and after are also procedural.
But if what you are using with the vex is working as you like…that's all that matters
And yes chops is very good for that. Giving a visual feedback.
It is definitely worthwhile to learn chops…you can actually ‘art-direct’ many different elements just by looking in the MotionFx window with your different channels without ever having to look at your scene view.
And chops doesn't limit you to not using code like expressions or vex. Actually after you get to know chops you will likely combine both.
The list is defined by the sequence of frames.
Also, it is self contained in the paramater so nodes before and after are also procedural.
But if what you are using with the vex is working as you like…that's all that matters
And yes chops is very good for that. Giving a visual feedback.
It is definitely worthwhile to learn chops…you can actually ‘art-direct’ many different elements just by looking in the MotionFx window with your different channels without ever having to look at your scene view.
And chops doesn't limit you to not using code like expressions or vex. Actually after you get to know chops you will likely combine both.
-
- Quick Links