• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Control camera in other comps

Community Beginner ,
Jan 11, 2024 Jan 11, 2024

Copy link to clipboard

Copied

Hi, I am trying to control the camera in my nested comp with the camera in my "Main" comp, I have the following expression applied to the nested comps camera's position-

 

CL = comp("Main").layer("Camera 1"); CL.toWorld([0,0,0]);

 

And, this to it's orientation:

 

CL = comp("Main").layer("Camera 1");
getGlobal Orientation(CL, time);
function getGlobalOrientation(aLayer, aTime) {
C = aLayer;
aTime = (aTime ? aTime : time);
ghi=normalize(C.toWorldVec([1,0,0], aTime));
def=normalize(C.toWorldVec([0,1,0], aTime));
abc=normalize(C.toWorldVec([0,0,1], aTime));
A=abc[0];B=abc[1];C=abc[2]; D=def[0];E=def[1];F=def[2]; G=ghi[0];H=ghi[1];I=ghi[2];
OrX=Math.atan2(-B,C);OrY=Math.asin(A);OrZ=Math.atan2(-D,G);
degr=180/Math.PI;OrX=OrXdegr;OrY=OrYdegr;OrZ=OrZ*degr;OrX+value;
return([OrX, OrY, OrZ]);
}

 

The position works, but the orientation is throwing up an error on line 2. Have tried changing settings to Java from legacy

 

Thanks for any help

 

 

TOPICS
Expressions

Views

206

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jan 11, 2024 Jan 11, 2024

For me the error is at line 11:

 

degr=180/Math.PI;OrX=OrXdegr;OrY=OrYdegr;OrZ=OrZ*degr;OrX+value;

 

You forgot to add the * sign (OrX = OrXdegr; OrY = OrYdegr).

Also, at the end, the = sign is missing too (OrX + value should be OrX += value).

Moreover, since 'value' is an array [x, y, z] and 'OrX' should represent an angle, adding 'OrX' with 'value' doesn't make sense.

Try this:

 

CL = comp("Main").layer("Camera 1");
function getGlobalOrientation(aLayer, aTime) {
  C = aLayer;
  aTime = (aTime ? aTime :
...

Votes

Translate

Translate
Enthusiast ,
Jan 11, 2024 Jan 11, 2024

Copy link to clipboard

Copied

For me the error is at line 11:

 

degr=180/Math.PI;OrX=OrXdegr;OrY=OrYdegr;OrZ=OrZ*degr;OrX+value;

 

You forgot to add the * sign (OrX = OrXdegr; OrY = OrYdegr).

Also, at the end, the = sign is missing too (OrX + value should be OrX += value).

Moreover, since 'value' is an array [x, y, z] and 'OrX' should represent an angle, adding 'OrX' with 'value' doesn't make sense.

Try this:

 

CL = comp("Main").layer("Camera 1");
function getGlobalOrientation(aLayer, aTime) {
  C = aLayer;
  aTime = (aTime ? aTime : time);
  ghi = normalize(C.toWorldVec([1, 0, 0], aTime));
  def = normalize(C.toWorldVec([0, 1, 0], aTime));
  abc = normalize(C.toWorldVec([0, 0, 1], aTime));
  A = abc[0];
  B = abc[1];
  C = abc[2];
  D = def[0];
  E = def[1];
  F = def[2];
  G = ghi[0];
  H = ghi[1];
  I = ghi[2];
  OrX = radiansToDegrees(Math.atan2(-B, C)) + value[0];
  OrY = radiansToDegrees(Math.asin(A));
  OrZ = radiansToDegrees(Math.atan2(-D, G));
  return [OrX, OrY, OrZ];
}
getGlobalOrientation(CL, time);

 

 

 

 

 

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 11, 2024 Jan 11, 2024

Copy link to clipboard

Copied

This is perfect, thanks!

 

DO you know if it would be possible to also tether it to the zoom function on the camera?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2024 Jan 11, 2024

Copy link to clipboard

Copied

If you Collapse Transformations, any 3D layers in a nested comp will be looked at with the main comp camera and lit with the main comp lights. 

 

It looks like you are trying to use the main comp camera to match the view with the camera in a nested comp without collapsing transformations. The only possible reason I can see to do this would be to use different lights in the nested comp or a different 3D rendering engine.

 

It would help us help you figure out the most efficient workflow if you were to explain exactly what you are trying to do. A simple Copy with Property links and a paste to a nested comp will give you a camera in the nested comp that perfectly matches the camera moves in the main comp. You can do the same with any layer, including lights.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 11, 2024 Jan 11, 2024

Copy link to clipboard

Copied

Hi,

Ideally I would use Coll Tran, but as you guessed, the problem I have is I have 3d objects in "Advanced 3d" world with an environment light, but want other objects in the 3d world that use classic 3d (mainly so the light doesnt affect them, and I can use blend modes etc).  Open to tips/suggestions here if there is another way! 

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2024 Jan 11, 2024

Copy link to clipboard

Copied

LATEST

All you need to do then is select the camera, choose Edit/Copy with Property links, and then paste the camera in the Advanced 3D comp. Every change in every camera property in the main comp will be reflected in the nested comp. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines