February 17, 2010

Fly around CC Sphered layer in After Effects

From motion graphics eXchange is an expression by Filip Vandueren in Ultimate CC Sphere/Light/Comp Camera linker: 'Ever wanted to fly around a "CC Sphered" Layer? Linking CC Sphere to a Light and Camera is the way to do it.'

It's a variant of solutions also by Dan Ebberts in various places, once upon a time by Chris Meyer, and explained one way by Andrew Kramer in his After Effects tutorial video
41b. The Blue Planet in 3D. Here's the expression from Motion Graphics Exchange:

"Here are the expressions for X, Y & Z-rotation:

CC Sphere Rotation X:
// change camera & effect names as needed...
campos=thisComp.activeCamera.toWorld([0,0,0]);
planetpos=thisLayer.toWorld(effect("CC Sphere")("Offset"));
x=length([planetpos[0],planetpos[1]], [campos[0],campos[2]]);
y=campos[1]-planetpos[1];
alpha=Math.atan2(y,x)
value+radiansToDegrees(alpha) ;

CC Sphere Rotation Y:
// change camera & effect names as needed...
campos=thisComp.activeCamera.toWorld([0,0,0]);
planetpos=thisLayer.toWorld(effect("CC Sphere")("Offset"));
x=campos[0]-planetpos[0];
y=planetpos[1]-campos[2];
beta=Math.atan2(y,x)
value+radiansToDegrees(beta) - 90;

CC Sphere Rotation Z:
No expression

And here are the expressions for the light.

Step1: create your lightsource, and make it an adjustment layer, make sure all the planets are above the light-adj., because we want them to be only lit by the CC Sphere plugin, not receive light. If there are other 3d-layers that do need the shading, put them below the adj.-light. You can just pickwhip the light color and light-intensity from the lightsource to the light-settings of CC Sphere.

CC Sphere Light Height
// change camera & light names as needed...
campos=thisComp.activeCamera.toWorld([0,0,0]);
planetpos=thisLayer.toWorld(effect("CC Sphere")("Offset"));
sunpos=thisComp.layer("Light 1").toWorld([0,0,0]);
camvector=normalize(campos-planetpos);
sunvector=normalize(sunpos-planetpos);
angle=Math.acos(dot(camvector, sunvector));
100 - (angle/Math.PI)*200


CC Sphere Light Direction
// change light name as needed...
thesun=thisComp.layer("Light 1");
xy=thisLayer.fromWorld(thesun.position) - effect("CC Sphere")("Offset");
angle=Math.atan2(xy[1],xy[0]);
radiansToDegrees(angle) + 90;


by Filip Vandueren
"

3 comments:

Anonymous said...

Hi there,
the links aren't correct: It's not the http://www.themotionexchange.com , but http://www.motion-graphics-exchange.com ... it's a bit confusing ;)

Rich said...

Thanks, fixed it! I got them switched around when copying from the sidebar.

Anonymous said...

thank pal,it was very help full to me