Activity › Forums › Adobe After Effects Expressions › addressing each point position in a polystar
-
addressing each point position in a polystar
Posted by Seb Melm on May 31, 2010 at 7:59 amIs there a way in AE to be able to address (through an expression) the individual points of a polystar shape layer ..? eg… if you create a shape layer with a 5 point star – can I address the location of each of the points of the star to, eg. create spot lights at each point …?
Now there’s a question ….
cheers,Mooooooooooo…!
Sebastian Melmott replied 16 years, 2 months ago 4 Members · 15 Replies -
15 Replies
-
Dan Ebberts
May 31, 2010 at 4:55 pmPath points aren’t individually accessible to expressions. You can get close using a script (which can access the points). In your case you’d need a little script that goes through the comp frame by frame and sets keyframes for the lights to keep them attached to the points. The downside is that you need to make sure and run your script each time you change the animation. If you’re not actually animating the shape itself, you could just attach the lights via parenting.
Dan
-
Filip Vandueren
May 31, 2010 at 5:38 pmHey Paul,
The actual math to calculate where the points of the stars is not too hard, but we have to do some work to figure out where the center of the star actually is.
The problem to overcome is that a shape-layer is a complex-beast:
- the polystar Path has it’s own position, radius and rotation.
- the polystar Path (by default) is contained in a group (“Polystar 1”) with stroke and fill settings, but that also has a transform control with anchor point/position/scaling/rotation, and even Skew
- this group can in theory be contained within a bunch of other groups, each with their own transformation, acting as a sort of parent-child and making the transform complexer.
- Then we come to the layer itself, with again it’s own transformation parameters.
This is not just a theoretical problem, because, if you just take the polystar or any shape tool and click to draw on screen, you’ll notice that the anchorpoint of the layer is not at the center of the star (this actually really bugs me !)
With parented layers, we can ‘bypass’ all these complex transformations with layer-space transforms to just get to a coördinate: l.toComp([100,100]) will tell us where the point 100,100 on the layer ended up in the comp, no matter how many parent-scaling and rotations happened.
Unfortunately there’s no way to do the same within the grouping structure of shapes, so we would have to do a lot of calculations. But there’s a solution I came up with by using an extra Null layer.
Since you mentioned Spotlights, I think you need a 3d solution, and the Shapelayer itself is also on a 3D, right ?
Here are the steps, please bare with me.
- create a Null Layer, make it 3D, and parent it to the shape-layer
- we’re going to add an expression to each of the null’s transform properties, so they mirror the properties of the “Transform: Polystar 1”
you should end up with something like this:
Null’s anchorpoint:temp = thisComp.layer("Shape Layer 1").content("Polystar 1").transform.anchorPoint; [temp[0], temp[1], 0]Null’s position
temp = thisComp.layer("Shape Layer 1").content("Polystar 1").transform.position; [temp[0], temp[1], 0]Null’s Scale
temp = thisComp.layer("Shape Layer 1").content("Polystar 1").transform.scale; [temp[0], temp[1], temp[1]]Null’s Z-rotation
thisComp.layer("Shape Layer 1").content("Polystar 1").transform.zRotationYou can do this by pickwhipping, but you have to edit anchorpoint and position so the third value = 0 !
Now this might have moved the null to the center of the polystar (unless the polystar itself has a different position than the default [0,0]) But if it didn’t, that’s no big deal.This null is a vehicle through which we’ll use layer-space transform methods that correlate with the shape’s transform.
NB: if there is more than 1 group/transform, we would need to set up as many child-nulls with pickwhipped properties as there are child-groups. But I assume this is not the case.
NB2: If you’ve used a Skew on the group… well, don’t that will make it a lot harder to calculuate the positions, again, I assume this isn’t the case. - now here’s the expression to get to the position of the 1st point of the polystar. You should aplly this to the position of a spotlight.
thisPoint=1;
l=thisComp.layer("Null 1");
polystar=thisComp.layer("Shape Layer 1").content("Polystar 1").content("Polystar Path 1");pts=polystar.points;
pos=polystar.position;
rot=polystar.rotation;
rds=polystar.outerRadiusa=(360*(thisPoint/pts))+rot;
a=degreesToRadians(180-a);x=Math.sin(a)*rds;
y=Math.cos(a)*rds;l.toWorld(pos+[x,y]);
you’ll have to edit the first three lines, but they’re pretty self-explanatory.
If you want the position of the inner points, use rds=polystar.innerRadius and subtract .5 from thisPoint. (for example thisPoint=1.5)
-
Seb Melm
May 31, 2010 at 7:28 pmOoooooooooooooooomphf……. Must express large gratitude for all this generous technical information.
I shall attempt to digest and revert.
Many Moos Filip: back soon.
Mooooooooooo…!
-
Seb Melm
May 31, 2010 at 10:59 pmFilip- all is well until I tried to address the 2nd point in the polystar . ..
DO you feel up to walking me through the code for point no. 2 ..??? ( I must have goofed when trying to edit the “first three lines”…. (sometimes I’m slow – and it’s late here…)Moo!
Z z z z z z z z z z z z z z . . . . .
thisPoint=2;
2=thisComp.layer("Null 1");
polystar=thisComp.layer("Shape Layer 1").content("Polystar 1").content("Polystar Path 1");pts=polystar.points;
pos=polystar.position;
rot=polystar.rotation;
rds=polystar.outerRadiusa=(360*(thisPoint/pts))+rot;
a=degreesToRadians(180-a);x=Math.sin(a)*rds;
y=Math.cos(a)*rds;2.toWorld(pos+[x,y]);
Mooooooooooo…!
-
Sebastian Melmott
June 1, 2010 at 5:35 amHi Filip –
I had to change my e-mail address – if it’s easier use that: sebmelm@gmail.com
many thanks,
Paul
Moooooooo….!
-
Filip Vandueren
June 1, 2010 at 5:12 pmHey there,
you only needed to change the first line to thisPoint=2;
the first character on the next line is actually a lowercase L, not a “one”, so you erroneously changed all the L-s into 2’s which makes no sense.
I only said you might need to change the other two lines, because you would if the naming of your layers was different from the default “Null 1” and “Shape Layer 1”
But if the first example worked, all is well.
-
Sebastian Melmott
June 2, 2010 at 9:54 amYup Filip – it works a dream …. Thanks for your genius ( how DO YOU KNOW SO MUCH ABOUT THE INTERNALS OF AE..!!)
I have another logical follow-up question – May I bother you with it …?
Moooooooo….!
-
Sebastian Melmott
June 10, 2010 at 9:04 amHi Filip –
Another interesting question:
Assuming I have a light at each external point on the polystar using the addressing algorithm you suggested…. Now I want to be able to turn off or on each light (e.g. by keyframing their individual opacity percentages to either 0% –> 100% or 100%–> 0%) when a circulating null layer passes.
In other words, assume also that I have a Null Layer which circles around the polystar points (at the same radius as the polystar points) and as it passes it can ither turn on or off the light at each polystar point….
Any ideas …?
Many thanks,
Paul
Moooooooo….!
-
Filip Vandueren
June 12, 2010 at 5:51 pmLot of questions:
How is it circling? Is it just rotating with the anchor point offset from centre, or do you have an expression set up with sine and cosines?
Are the lights supposed to switch on for just the frame that the null is at the same angle ad the light, or is it toggles on, then toggles off at the next round?
Does the light intensity fade in and out slowly or just flick on/off ?
Is the rotation at a steady pace, or is it key framed ?
Is it absolutely necessary to do with an expression, because this might get complicated -
Sebastian Melmott
June 14, 2010 at 8:15 amThanks for the reply, FIlip..
(1) The Null layer is rotating using an expression, the 3D Orbit pre-set:
Radius = effect(“Radius”)(“Slider”);
Speed = effect(“Speed”)(“Slider”);
RotationOffset = effect(“Rotation Offset”)(“Angle”);//
center = [this_comp.width/2,this_comp.height/2,0];
radius = 200;
angle = time * Speed RotationOffset;
x = Radius * Math.cos(degreesToRadians(angle));
z = Radius * Math.sin(degreesToRadians(angle));
add(center, [x,0,z]);(2) The lights are supposed to be “activated ” by the passing of the null layer which “magically” turns them on on the first pass… then on the 2nd pass (i.e. the second time the Null passes each light point) it turns them off.
(3) Lights should flick on and stay on after first pass.
(4) upon 2nd pass, lights should be turned off.
(5) It would also be nice to vary the intensity of the lights….
(6) Fom the 3D expression above, you can see that the rotation is at the pace set by the sliderNoow if you can help here, I would definitely buy you a Belgian beer!
Thanks,Paul
Moooooooo….!
Reply to this Discussion! Login or Sign Up