script idea - Z distribute while keeping visual size

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
funksmaname
Posts: 3174
Joined: Tue May 29, 2007 11:31 am
Location: New Zealand

script idea - Z distribute while keeping visual size

Post by funksmaname »

I have a plugin in after fx that lets me distrubute objects in z space while keeping them visually the same size. I'm not very good at maths but I assume this can be worked out with numbers... essentially it could be a button that asks for a z offset from you, and when you click 'go' it does the z offset on the layer and at the sime time adjusts the layer scale so that the object remains visually identical to the viewer (until you move the camera)

This would probably save a bunch of time when you lay out a scene flat and then just want to distribute it in space.

let me know your thoughts! :)
ponysmasher
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles
Contact:

Post by ponysmasher »

I actually have a script exactly like this for when I make animatics. I import the layers of a photoshop and then use this tool to put things at different Z depths while not visually changing size.

The reason to why I have never uploaded it is because it's not 100% done. It will currently only work on layers that haven't already been moved in Z, but it has worked for my purposes.

When I get back from vacation I can upload it and take another look at it. Maybe I've learned enough new Lua tricks to be able to finish it.
User avatar
funksmaname
Posts: 3174
Joined: Tue May 29, 2007 11:31 am
Location: New Zealand

Post by funksmaname »

cool, that sounds great! I never use z depth and being able to spread stuff after it's already layed out would be cool :)

I assume from your description that once adjusted you can't re-adjust at this point, or will it work as long as you haven't manually changed a z translation?

Thanks dude!
ponysmasher
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles
Contact:

Post by ponysmasher »

As long as you haven't manually changed it, it works I think. But I will have a new look at the code and see if I can't make it better.
Karhu
Posts: 18
Joined: Tue Dec 27, 2011 9:28 pm
Location: Finland
Contact:

Re: script idea - Z distribute while keeping visual size

Post by Karhu »

Heya,

I ran into the similar "problem" as funksmaname, wondering if there is a script for aiding on that tedious scaling.
Is this script still alive and would it be possible to get it uploaded?

Thanks!

-Karhu
User avatar
ulrik
Posts: 1087
Joined: Thu Aug 11, 2005 10:32 pm
Location: Stockholm Sweden
Contact:

Re:

Post by ulrik »

ponysmasher wrote:I actually have a script exactly like this for when I make animatics. I import the layers of a photoshop and then use this tool to put things at different Z depths while not visually changing size.

The reason to why I have never uploaded it is because it's not 100% done. It will currently only work on layers that haven't already been moved in Z, but it has worked for my purposes.

When I get back from vacation I can upload it and take another look at it. Maybe I've learned enough new Lua tricks to be able to finish it.
Hi Ponysmasher, this script sounds indeed interesting, I would like to try it when you feel ready to share it with us.

All the best / Ulrik
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Re: script idea - Z distribute while keeping visual size

Post by heyvern »

Is this a Tool script or a menu script? I had originally posted that it could be a tool script to link z and scale while using it.

-vern
User avatar
funksmaname
Posts: 3174
Joined: Tue May 29, 2007 11:31 am
Location: New Zealand

Re: script idea - Z distribute while keeping visual size

Post by funksmaname »

Vern, that would be cool! I have an addon for afterFX that lets me do that too... i think it makes sense to have it as a tool mod for moving layers in Z while maintinging visual size... :)
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Re: script idea - Z distribute while keeping visual size

Post by heyvern »

Just for "fun" and education, I tried to figure out what kind of math is involved based on the relationship of z translation to scale... good grief, I can't for the life of me figure out how to calculate scale based on z translation. There has to be a formula for this obviously since someone HERE has already done it.

Basically I set up a document with .5 z translation offsets on a bunch of layers (0, .5, 1.5, etc), and then scaled each layer to be the "same size" visually. I have the numbers but can't figure out how that can be done automatically.

Can't wait to find out what that mystery number is. :)

-vern
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Re: script idea - Z distribute while keeping visual size

Post by heyvern »

Hah!

I did it! It works. A new translate tool that scales to compensate for z index changes. The really hysterically funny part of this was that the crazy ratio or relationship of the z translation to scale is A FREAKIN STRAIGHT LINE! It's just a linear regression. Got the code I needed from this site:

http://www.sooeet.com/math/linear-regression.php

I plugged in my numbers from my test document and it gave me values to use in the script.

Actually it was a very very simple modification to the existing translate layer tool. I think I will just add a checkbox to "scale compensate z index". You could install as a custom tool or it can just be a modification for the existing translate layer tool.

The best part is it keys both translation and scale in the timeline. This means you can change "layer order" by keying translation in the time line.

I want to test it some more before posting. There is a few places to update the changes that I haven't put in code for yet. Basically just added a few lines in the "alt key" modifier section to see if it works. I also need to put in the check box option and update all the variables blah blah blah booring code crud etc etc :).
User avatar
funksmaname
Posts: 3174
Joined: Tue May 29, 2007 11:31 am
Location: New Zealand

Re: script idea - Z distribute while keeping visual size

Post by funksmaname »

two thumbs up! :)
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Re: script idea - Z distribute while keeping visual size

Post by heyvern »

Hah!

this is FUN! This is sooo cool. I am digging it. I put all of my test layers in a group. If I change the z translation with the "regular" translate tool of the group after the sub layers are scaled to compensate, the scaling of the sub layers gets all wonky and it doesn't look right.

BUT if I translate Z with my new tool on the group layer it COMPENSATES THAT LAYER SCALE and the sub layers "stay the same size" but the Z separation goes up or down. It's really cool and makes sense when you see it. Basically you can interactively change the amount of parallax separation really quickly and easily.

This is a coool new tool and I never knew I wanted it! Thanks guys.

-vern
User avatar
funksmaname
Posts: 3174
Joined: Tue May 29, 2007 11:31 am
Location: New Zealand

Re: script idea - Z distribute while keeping visual size

Post by funksmaname »

sharing the tool will be thanks enough ;) :D
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Re: script idea - Z distribute while keeping visual size

Post by heyvern »

Here's a video demo. I will be posting this in it's own topic for download soon as it's ready. I was going to do a modified Anime Studio tool, but I think this needs to be a custom tool.

Watch the video and then read my questions below. I need to know the best way to handle this. A layer script would be "better" but a tool would be more convienant. Both versions would work, but the tool has issues I need to address.



I have some questions though for functionality. Currently it is based on 100% scale as the default and it "permanently" scales the layer. It changes the absolutely scale value to compensate for the z translate value. this might not be a good thing if you use it "accidentally" on a layer but undo will work.

My question is how it should effect overall scale? Should it modify the "existing" scale? Suppose you import a bunch of image layers, or have vector layers set up and have non-uniform scaling. Then you change the z-trans with the "magic z" tool. It would need to compensate without changing the non-uniform scaling right? Also it should account for any scaling done in advance of z trans changes right?

The tricky part is accounting for or enabling additional scaling that might be needed ON TOP of or added to the z translation compensating scaling.

It gets tricky when it's not a "layer script" that can do the offset or compensation without key framing it. For example this could be a layer script applied to a group layer just for a specific purpose, It would compensate the z translation for that group layer as well as ALL the sub layers. this would make it WAY easier and more flexible.

If you try to compensate for any other additional layer scaling other than "100%" you run into cumulative scaling issues. Using a tool to key frame and evaluate scale that's alreay there COMPENSATING for z translation would cause all kinds of problems.

The solution to that would be to always use FRAME 0 as the reference scale. This means you would set up your scaling and translation on frame zero, then ONLY use the tool on other frames (or frame 1 as a starting point) so that frame 0 is your reference scaling point.

So here are the choices:

Layer script
This is the BEST MOST PERFECT solution with the most flexibility and least problems. You embed it on the GROUP layer (you need that anyway for this type of thing) and that group layer is unique from other layers and allows for any type of additional scaling independently from the special z-translation scale offset. You don't have to do ANYTHING else special, no extra tools, nothing it just works. AND it's on the TOP level group layer so you can use other layer scripts on sub layers without issue.

Custom Tool Script
This could have limitations on use but would still work in most general situations. Maintaining a 100% scale value as the default for the layers would be the best situation. Or if you need additional scaling, it would have to be done on frame 0 and then you could use the magic tool to "key" the offset past that frame.

-vern
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Re: script idea - Z distribute while keeping visual size

Post by heyvern »

After playing around with this, the tool works fine but I just can't get past the "cumulative" scaling issues if you want to include additional scaling. I can keep trying. However you could put the group in another group and scale that. Tool works well, but you have to either "double group" or just stick with 100% scale. This would mean that if you are doing image layer stuff you would need to make sure your images are the right size to start with since you can't scale beyond 100% after import. Vector layers not such a problem because you can always scale the POINTS instead. Hmm... you could put EACH image layer inside a group layer and scale that group. pain in the arse though. :) The key is that the magic tool resets the scale to 100%, but If the image is in a group that is scaled, you can change the z trans of the image layer and the outer group layer won't change scale.

Will also do a layer script as well. this may end up having the same problem as the tool but I have high hopes. If it does work it should be much better than the tool version.

This is so cool. Just playing around with it is inspiring. The layer parallax panning and movement WITHOUT the 3D scaling effect is really cool.

-vern
Post Reply