ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# 3d line between to nulls - REVISITED

FAQ   •   VIEW ALL
 3d line between to nulls - REVISITED on Jan 1, 2011 at 3:56:31 pm

Howdy Folks,

I've been looking for the ultimate way to draw a simple line between 2 nulls moving around in 3d space. Dan E. and Roland K. created some great expressions to help out with this using the Beam plugin. Awesome and genius and thank you!

But might there be a way to calculate the distance between the nulls, and then create a line at that length using a simple shape, then 3D that layer, and use a fancy expression to position and rotate/orient the layer so that it was the correct angle between the nulls in 3D space? It seems like that would take care of most of the stacking and perspective problems, and technically you could even use shapes and layers and stuff that weren't even lines.

I remember a great expression I used to calculate the angle between to objects in 2D that worked like a charm because I wanted a funky animated line to stay connected to two objects moving around. Maybe that's possible in 3d?

Any thoughts?

thanks and happy new year!

Tom

 Re: 3d line between to nulls - REVISITEDon Jan 1, 2011 at 6:17:25 pm

This thread has what I think that you're looking for:

---------------------------------------------------------------------------------------------------------
Technical Support for professional video software
After Effects Help & Support
Premiere Pro Help & Support
---------------------------------------------------------------------------------------------------------

 Re: 3d line between to nulls - REVISITEDon Jan 1, 2011 at 6:31:29 pm

That's a super solution. But I'm hoping there's a way to make something magic like that work in 3D...

YOU can help save TimeSpace. Join the Chronos Protectorate!

http://www.95ers.com
http://www.SpaceAceMedia.com

 Re: 3d line between to nulls - REVISITEDon Jan 1, 2011 at 8:29:36 pm

Here's my solution...

Not elegant maybe, but works great. I'd love any feedback or enhancements.

This set of expressions will allow you to make a 3D line between any two 3d layers you stick it between. It will respond to depth of field, moving layers, etc. with no stacking issues and no need to use beam filter. The nice thing is that you can modify it so your line could have all kinds of effects or change shape, etc.

1) Stick a rectangular shape layer (with 3D checked and position dimensions separated) between any two 3D layers (that have position dimensions separated). The anchor of your shape layer should be (0,0,0).

2) Make the width of your rectangle exactly match the distance between those layers with this expression. (You need to apply this expression to JUST the width parameter of the rectangle.) I did it this way:

In a SLIDER:

point1=this_comp.layer(thisLayer, -1).position;
point2=this_comp.layer(thisLayer, 1).position;
length(point1, point2)

In my rectangle in the size parameter:

temp = effect("Slider Control")("Slider");
[temp[0], value[1]]

3) Put the shape exactly between the two layers in 3D space.

In X:
(thisComp.layer(thisLayer,-1).transform.xPosition+thisComp.layer(thisLayer, 1).transform.xPosition)/2

In Y:
(thisComp.layer(thisLayer,-1).transform.yPosition+thisComp.layer(thisLayer,1).transform.yPosition)/2

In Z:
(thisComp.layer(thisLayer,-1).transform.zPosition+thisComp.layer(thisLayer,1).transform.zPosition)/2

4) Orient the layer so it exactly connects the two other layers:

In ORIENTATION:

lookAt (thisComp.layer(thisLayer,-1).transform.position, thisComp.layer(thisLayer,1).transform.position)

Again, I'd love any suggestions. Thanks!

================================================
YOU can help save TimeSpace. Join the Chronos Protectorate!

http://www.95ers.com
http://www.SpaceAceMedia.com

 Re: 3d line between to nulls - REVISITEDon Jan 1, 2011 at 8:41:02 pm

PS. And change the line's y rotation to 90.

================================================
YOU can help save TimeSpace. Join the Chronos Protectorate!

http://www.95ers.com
http://www.SpaceAceMedia.com

 Re: 3d line between to nulls - REVISITEDon Nov 22, 2011 at 7:50:14 pm

Hi Tom!

I'm a newbie in expressions and I'm trying to do your 3D "rope", but I get an error when i get to the XYZ positioning saying: "Class ‘Group’ has no property or method named ‘xPosition’".
Any thoughts on how i could resolve this would be much appreciated!

Thanks a lot

 Re: 3d line between to nulls - REVISITEDon Nov 22, 2011 at 7:58:59 pm

Be sure to right click on your position transformation and tell it to "separate dimensions"... Then your x,y,z will turn into three separate values that the expression wants.

================================================
YOU can help save TimeSpace. Join the Chronos Protectorate!

http://www.95ers.com
http://www.SpaceAceMedia.com

 Re: 3d line between to nulls - REVISITEDon Nov 22, 2011 at 8:16:16 pm

I did that before, sorry if I wasn't clear. Do you have any other idea why it isn't working?

The Slider and the Orientation expressions are working.
I'm running CS5

Thanks

 Re: 3d line between to nulls - REVISITEDon Nov 22, 2011 at 8:31:08 pm

I won't be able to check into it for a few days... But I'd be happy to.

================================================
YOU can help save TimeSpace. Join the Chronos Protectorate!

http://www.95ers.com
http://www.SpaceAceMedia.com

 Re: 3d line between to nulls - REVISITEDon Dec 14, 2011 at 11:16:32 am

Greetings Joao,

Sorry it took so long to get back to you. Hopefully this is still helpful. I've just revamped these expressions for a 3d line and maybe it will help.

First, create a shape rectangle layer, make it 3d, give it a fill, place it between any two 3d layers (so for example layer 1 is a 3d layer, layer would be this layer, and layer 3 would be another 3d layer).

Next, give it two expression sliders. Call the first one LINE LENGTH MODIFIER, the second LINE WIDTH. For now, give those the values 1 and 4 respectively.

To the rectangle's size property:

x = (effect("LINE LENGTH MODIFIER")("Slider"));
point1 = ((thisComp.layer(this_layer,-1).position)*x);
point2 = ((thisComp.layer(this_layer,1).position)*x);
y = (length(point1, point2))*(x);
w = effect("LINE WIDTH")("Slider");

[y, w]

To the position property of the layer:

a = thisComp.layer(this_layer,-1).transform.position[0];
b = thisComp.layer(this_layer,1).transform.position[0];
c = (a+b)/2;
d = thisComp.layer(this_layer,-1).transform.position[1];
e = thisComp.layer(this_layer,1).transform.position[1];
f = (a+b)/2;
g = thisComp.layer(this_layer,-1).transform.position[2];
h = thisComp.layer(this_layer,1).transform.position[2];
i = (a+b)/2;

[c, f, i]

On the layer's orientation property:

lookAt (thisComp.layer(this_layer,-1).transform.position, thisComp.layer(this_layer,1).transform.position)

FINALLY, set the layer's rotation to 90.

You can copy and paste the whole line layer between any two 3d layers and it will automatically adjust to the new layers.

Viola.

================================================
YOU can help save TimeSpace. Join the Chronos Protectorate!

http://www.95ers.com
http://www.SpaceAceMedia.com

 Re: 3d line between to nulls - REVISITEDon Feb 9, 2012 at 8:18:40 pm

Great expression Tom; thanks! There's just a couple typos in there that I fixed so people can just copy/paste:

a = thisComp.layer(this_layer,-1).transform.position[0];
b = thisComp.layer(this_layer,1).transform.position[0];
c = (a+b)/2;
d = thisComp.layer(this_layer,-1).transform.position[1];
e = thisComp.layer(this_layer,1).transform.position[1];
f = (d+e)/2;
g = thisComp.layer(this_layer,-1).transform.position[2];
h = thisComp.layer(this_layer,1).transform.position[2];
i = (g+h)/2;'>i = (g+h)/2;

[c, f, i]

 Re: 3d line between to nulls - REVISITEDon Mar 17, 2012 at 10:19:32 am

I don´t know if u can help me.. but ive been trying to make it work in CS3 with no luck...
i even tryed with separate XYZ script...
any hints??

 Re: 3d line between to nulls - REVISITEDon Mar 19, 2012 at 9:34:39 pm

Seems like it should work with a few tweaks... I don't have CS3 so I'm not sure what the problems might be! Sorry! :)

================================================
YOU can help save TimeSpace. Join the Chronos Protectorate!

http://www.95ers.com
http://www.SpaceAceMedia.com

 Re: 3d line between to nulls - REVISITEDon May 20, 2018 at 3:54:35 pm

hi tom
this thread is very old but maybe you come around again.
i am trying the same thing at the moment, but with my setup and I think with your setup aswell, there is still the problem that the layer isn´t orientated automatically towards the camera. Under specific circumstances you see that layer from the "side" and it disappears.

Did you find a solution to improve the orientation expression to always have the layer stay fully visible? It seems to be a quite tricky math calculation.