When I was just about to write a similar script as above, I thought, this should bee doable without any Python at all.
So, here you go, a scene using Fields in order to achieve a random reveal of cubes:
test_random_cube_reveal.c4d (248.6 KB)
I did this in R21, but I don’t think I used any R21 specific features, so I hope it works in R20 (where Fields got introduced) as well. In earlier versions you could probably achieve it similarly with falloffs, but I’m actually no MoGraph expert at all.
I already said, I’m not an expert in MoGraph, so there are surely smarter ways to achieve this. Anyway, it works like this (actually going bottom up in object hierarchy):
- As I assumed, your cubes might not originally stem from a MoGraph cloner, I used the good ol’ array to create a bunch of cubes.
- The Fracture (mode: Explode Segments and Connect) makes the cubes accessible from MoGraph, so we can influence them with Effectors and thus Fields.
- A simple Plain effector is used to hide all the clones/cubes. Therefore it’s set to scale relatively and uniformly to -1 (sounds strange and it is, but it is indeed a way to hide clones with Mograph).
- The Plain effector is now influenced by three Fields (really simple, no worries). Basically the Fields will provide values between 0.0 and 1.0, determining the influence of the Plain effector at each point in space. A value of 1.0 means it has full effect (in our case the clones are hidden, fully scaled to -1) and 0.0 means the effector has no influence at all (tthe clones have the original size). Now, letts build these fields:
a. A random field as a base. The noise provided by this field serves as your random values, basically values between 0.0 and 1.0 scattered in space. I don’t think I changed any parameter in there.
b. A Time Field, which is added (Blending: Add) on top of the random noise. The Remapping Strength needs to be inverted, so it will start with 1.0 at frame zero and then transition to 0.0 over time (duration is specified by Layer Controls: Rate parameter). So, at frame zero the Time Field “floods” the space with 1.0, which is simply added to the noise value at each point in space. The resulting Field consists of values ranging from 1.0 to 2.0. And as time progresses, the Time Fields value decreases so the value range in the Field will transition to 0.0 to 1.0, as the Time Field will add less and less. Important: The Time Field must not be clamped in this case. Because we need it to produce negative values as well, until the entire Field’s summed value range is between 0.0 and -1.0. So, it takes actually to times the frames set in the Rate parameter. Not sure, I have the feeling my explanation rather over complicates it.
c. Lastly, I added a Quantize Modifier Field Layer set to quantize into just one single step. It basically takes values of the Field and… well quantizes it, in this case in just two values: 0.0 and 1.0. This will fix all the badness introduced with values ranging from up to 2.0 (at the beginning) down to -1.0 (and even less as time progresses), while MoGrapg actually works in the range 0.0 to 1.0. The Quantify (with Steps set to 1) simply compares each Field value with 0.5. Values below will result in 0.0 and values above, well, you guessed it, will result in 1.0.
I’m pretty sure, if Per would be listening here, he’d be rolling on the floor, seeing my approach. Maybe one of our pros (@noseman? Per?) could show how to do it with one single field.
Anyway, I’m aware you asked for a script. No Python in my solution, sorry! But I thought, it might nevertheless be interesting to see a different approach (which by the way is pretty flexible).
Edit: In the first post I wrote “nodeman”, who probably is also a pretty cool super villain, shooting all those nodes and stuff. But here of course I was referencing to our living polygon wrecking ball noseman.