ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Distribute 3D Objects Randomly Inside Sphere or Ellipsoid

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Noel Powell
Distribute 3D Objects Randomly Inside Sphere or Ellipsoid
on Jul 23, 2017 at 2:20:42 pm

Hi... I wrote this simple expression to randomly distribute 3D layers, but then realized that with enough objects, you can start to notice that they form a cube. What I want is more of a spherical dispersion - but with control over the height, width, and depth - so technically an ellipsoid.

I saw Dan's expression, Random Motion on a Sphere, but I would need objects distributed inside the sphere rather than on the surface. Also, how hard would it be to control the distribution, so you can make a higher concentration in the middle than on the outside?

Thank you Dan and the other expression guru's, for your amazing contribution and support to the AE community over the years!

xSpread = thisComp.layer("Control").effect("Spread Horizontal")("Slider");
ySpread = thisComp.layer("Control").effect("Spread Vertical")("Slider");
zSpread = thisComp.layer("Control").effect("Spread Depth")("Slider");
seedRandom(1, true);
[random(xSpread, -xSpread), random(ySpread, -ySpread), random(zSpread, -zSpread)];


After Effects Templates - digital glitch effects, 80s VHS effects, old film effects, art effects, and more: http://CreationEffects.com


Return to posts index

Liran Tabib
Re: Distribute 3D Objects Randomly Inside Sphere or Ellipsoid
on Jul 23, 2017 at 3:22:27 pm
Last Edited By Liran Tabib on Jul 23, 2017 at 3:24:29 pm

Hi Noel
I believe that a simple wiggle() expression could solve this, assuming the layers are 3D.
Since the Amplitude value you enter is relative to the original 3D position of the layers they will disperse in a sphere which the Amplitude value is actually the sphere's radius.

spreadRadius = thisComp.layer("Control").effect("Spread Radius")("Slider");
wiggle(0,spreadRadius)


Liran Tabib
http://www.vdodna.com


Return to posts index

Noel Powell
Re: Distribute 3D Objects Randomly Inside Sphere or Ellipsoid
on Jul 23, 2017 at 6:26:46 pm

Brilliant - I expected a lot of math, and that is such a simple solution! And the results look really nice for what I'm doing. The objects are a little more dense in the core, and more sparse in the outer edges. Thanks so much, Liran!

Here's the full expression that separates the x,y,z, if anyone's interested:

xSpread = wiggle(0, thisComp.layer("CONTROL LAYER").effect("Spread Horizontal")("Slider"));
ySpread = wiggle(0, thisComp.layer("CONTROL LAYER").effect("Spread Vertical")("Slider"));
zSpread = wiggle(0, thisComp.layer("CONTROL LAYER").effect("Spread Depth")("Slider"));
[xSpread[0], ySpread[1], zSpread[2]]


After Effects Templates - digital glitch effects, 80s VHS effects, old film effects, art effects, and more: http://CreationEffects.com


Return to posts index


Liran Tabib
Re: Distribute 3D Objects Randomly Inside Sphere or Ellipsoid
on Jul 23, 2017 at 8:12:43 pm
Last Edited By Liran Tabib on Jul 23, 2017 at 8:14:07 pm

Glad I could Help!

Liran Tabib
http://www.vdodna.com


Return to posts index

Gerhard Human
Re: Distribute 3D Objects Randomly Inside Sphere or Ellipsoid
on Jul 25, 2017 at 7:43:34 am

Hi, thanks for sharing that! It's pretty much exactly what I was looking for as well ☺

Just something else... I want to achieve this same effect... but I want my layers to also wiggle a bit where they are in space (like they're a bit unstable) but if I want to add another wiggle to the layer it will over-write the distribution ☹
I'm planning on duplicating this layer a lot (50+) so want to avoid adding nulls and stuff..

Is there a way I can "add" to the position by adding a secondary wiggle expression?

Thanks so much!


Return to posts index

Liran Tabib
Re: Distribute 3D Objects Randomly Inside Sphere or Ellipsoid
on Jul 25, 2017 at 12:51:41 pm
Last Edited By Liran Tabib on Jul 25, 2017 at 12:53:36 pm

If I remember correctly adding wiggles on the same value create a mess.
but you have a few things you can do instead (without creating additional nulls):

1. Create three additional Slider Controls on the layer, wiggle them, and add the result to the existing expression instead of the last line of code:
[xSpread[0]+SliderX, ySpread[1]+SliderY, zSpread[2]+SliderZ]

2. If the wiggle can be 2D you can add a Transform effect to the layer and wiggle it's Position value.

3. Wiggle the Anchor point of the layer (I recommend this one).

Best Regards

Liran Tabib
http://www.vdodna.com


Return to posts index


Gerhard Human
Re: Distribute 3D Objects Randomly Inside Sphere or Ellipsoid
on Jul 25, 2017 at 12:54:52 pm

Hey thanks Liran! Sorry the post took so long to clear on the forum that I actually figured it out myself ☺

I have a few sliders to animate the distance the elements travel out (Dist) and the amplitudes of all the wiggles (Amp)
I ended up just doing this:

Freq = random(2,8);
Tempamp = thisComp.layer("Dotts_wiggler_cntrls").effect("Amp")("Slider");
Amp = random(Tempamp/2, Tempamp*2);
W = wiggle(Freq, Amp)-value;

xSpread = wiggle(0, (thisComp.layer("Dotts_wiggler_cntrls").effect("Dist")("Slider"))*2);
ySpread = wiggle(0, thisComp.layer("Dotts_wiggler_cntrls").effect("Dist")("Slider"));
zSpread = wiggle(0, thisComp.layer("Dotts_wiggler_cntrls").effect("Dist")("Slider"));
[xSpread[0]+W[0], ySpread[1]+W[1], zSpread[2]+W[2]]


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]