6 Replies Latest reply on Aug 29, 2017 6:24 PM by jeffs12515676

    Maintaining scale when moving an object in Z space

    andrewhalasz

      I'm surprised that this isn't a popular question.  It's something I've done often and easily in Apple Motion and I can't believe it is not easy with AE.

       

      Is there a way to maintain the scale of an object when you move it in Z space?  In other words, suppose you import a PSD and want to place the layers at different depths in Z space, but still want to maintain the proportions of each layer.

       

      I'd appreciate any advice.

       

      Thanks!

        • 1. Re: Maintaining scale when moving an object in Z space
          Todd_Kopriva Level 8

          See this page for a link to a script by Paul Tuersley that does what you describe.

          • 2. Re: Maintaining scale when moving an object in Z space
            Rick Gerard Adobe Community Professional & MVP

            This is easy to do with an expression. Here's the theory:

             

            Vector math will measure the distance between any two layer's. The default position of the camera is the the negative zoom value. IOW a camera with a 600 pixel zoom value will have a default z position of -600 pixels. The ratio between the camera's zoom value and the distance to any layer will give you the effective scale of that layer.

             

            All you have to do is to take the distance between the camera and the layer and divide that by the zoom value, then multiply that by 100 to keep the layer at an effective 100% scale. I've split up this expression into more parts than are necessary just so that you can see what's going on.

             

            c = thisComp.layer("Camera 1");
            point1 = position;
            point2 = c.position;
            d = length(point1, point2);
            s = (d/c.zoom) * 100;
            [s, s, 100]
            
            

             

            The first line just seta a variable for the camera so you don't have to type it out

            The second line defines point1 as the layer's position

            The second line defines point2 as the camera (c) position

            The third defines d as the distance between the camera and the layer using vector math straight from the Expression Language Menu

            The fourth line defines a value for scale by dividing the distance between the layer and the camera by the camera's zoom value then multiplying that by 100

             

            The last line sets up an array for the x y and z scale values. The reason that the z value in the array is set to 100 is to keep the layer from moving around in funny ways if you have moved the anchor point in Z space. If you don't move the anchor point in Z then you could write the array like this: [s, s, s]

             

            I hope this makes sense, and I hope it gives you an idea of how expressions can be written. Once you understand the language they are a powerful tool that will make your life much easier.

            1 person found this helpful
            • 3. Re: Maintaining scale when moving an object in Z space
              Navarro Parker Level 3

              This expression seems to not work if I have a layer with this expression parented to a 3D Null.

               

              Sound I change point1 = thisComp.layer("Null").transform.position;  ?

               

               

              Or is there a way to incorporate the parent transforms within the expression?

              • 4. Re: Maintaining scale when moving an object in Z space
                Dan Ebberts Level 5

                To account for any parenting, try changing the 2nd and 3rd lines to:

                 

                point1 = toWorld(anchorPoint);

                point2 = c.toWorld([0,0,0]);

                 

                 

                Dan

                2 people found this helpful
                • 5. Re: Maintaining scale when moving an object in Z space
                  eclecticscribe Level 1

                  I know this is a really old post, but I had been looking for the answer to this question as well. I don't remember where I finally found it, but it works for me so I though I would put it here for people who come across this question.

                   

                  This script should be placed in the Scale field of the layer that will retain its size (make sure 3D is activated before using).

                   

                  zoom=thisComp.layer("Primary Camera").cameraOption.zoom;

                  transform.scale*(1+transform.position[2]/zoom)

                   

                  “Primary Camera” is the name you give to the camera layer you want the expression to respond to.

                  1 person found this helpful
                  • 6. Re: Maintaining scale when moving an object in Z space
                    jeffs12515676

                    This worked perfectly, thank you!