View Full Version : Paint Attributes - Random rotation
12-14-2011, 05:19 AM
I've created a lot of objects in a very repetitive fashion. I simply copied and made rows / columns of the same object. Instead of hand tweaking rotation values to make the objects look slightly random, is there a way that I can use the paint attributes of Script paint tool to do this for me?
Thanks in advance for any help you can give.
12-14-2011, 12:33 PM
maybe? but surely something like:
float $deg = 45;
for ($object in `ls -sl -tr`)
rotate `rand (-$deg) $deg` `rand (-$deg) $deg` `rand (-$deg) $deg` $object;
is quicker and easier? or were you actually just looking for tips on scripting the script paint tool?
12-15-2011, 03:53 AM
Thanks man, I'll try that out and let you know how it goes.
12-15-2011, 04:05 AM
Hey Nathan, quick question. Is there any way to constraint the rotation snapping to increments of 90 degrees? The object themselves are blocks and need to still line up relatively close in a grid structure, but be randomly rotated in 90 degree increments.
Thanks for the help.
12-15-2011, 10:51 AM
sure, there are a couple of ways you could do it. I've decided the easiest in this case would be to pick a random integer between -4 and 4 and then rotate the objects by that * 90:
for ($object in `ls -sl -tr`)
rotate (90*int(`rand -4 4`)) (90*int(`rand -4 4`)) (90*int(`rand -4 4`)) $object;
@Nathan: if we're talking cubes, why random between -4 and 4?
4 = 0
3 = -1
2 = -2
1 = -3
So why not just random[0,3]?
Simply an excercise for my logic muscles, perhaps I've overlooked some reasoning behind this that you thought about (apart from rounding issues due to rand()'s float output)?
12-15-2011, 05:54 PM
Not sure if I'm following your logic. Are you suggesting randomizing the geometry itself? If not, how would rotation values work in your scenario? That is, if I need to rotate in multiples of 90 degrees in order to keep the cubes relatively in line with one another, how would rotational values work in a rand(0,3) scenario?
No, hehe, sorry for causing confusion. I'm not suggesting any different scenario, I was merely remarking on Nathan's choice of values.
You are using cubes for your setup, right? A cube has four sides on each axis. To show different sides of the cube, you rotate it by 90° or a multiple thereof (90, 180, 270, etc.). Nathan suggests picking a random integer number n where n can be [-4,-3,-2,-1,0,1,2,3,4] and rotating the cube by n * 90°. You'd end up with rotational values -360, -270, -180, -90, 0, 90, 180, 270, 360, depending on n.
My point in this case is that the following rotational values produce the same visual result:
-360° = 0° = 360°, or for n -4 = 0 = 4
-270° = 90°, or for n -3 = 1
-180° = 180°, or for n -2 = 2
-90° = 270°, or for n -1 = 3
So, I was implying that instead of choosing rotation multipliers n between -4 and 4, it is sufficient to pick values between 0 and 3. Say n=0=0° is the front face, then n=1=90° is the face to the left of that, n=2=180° is the face on the rear and n=3=270° is the face on the right (of the front face).
-360° is the front face, as is 0°, as is 360°, and so on.
That's my whole point :)
Long piece of text for a simple question, hehe.
12-16-2011, 12:02 AM
if you generate a random number between -4.0 and 4.0 (in MEL) the chances of hitting exactly -4 or 4 are extremely slim. Added to this, when you convert a float to an int it simply truncates the value, so even 3.9999999 becomes simply: 3
So basically if you want a random int between, for example, 1 and 10 you do: int(`rand 1 11`). I suppose if you wanted to be 100% sure you'd never ever hit the exact limit values you'd do something like:
int $minus3toplus3 = `rand -3.999 3.999`;but in the original scenario, it really wouldn't have mattered if 1 out of every 10000 runs generated a value of -4 or 4! ;)
You are right in that the negative numbers were visually irrelevent, but for no extra effort they do potentially add an extra dimension of randomness which may have been of some merit for something? For example, if you wanted to blend the cubes, or animate them back to zero, it may look better if they were blending or rotating in random directions rather than all clockwise or anti-clockwise, etc...
Yeah, I know about the truncation issue (can be worked around but truncation works perfectly fine in this case). Yes, if there's actually animation/transitioning going on between values then negative rotations make sense.
Was just making sure I wasn't missing something here :)
12-16-2011, 12:16 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.