Origin works oddly?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
bibbinator
Posts: 17
Joined: Wed Mar 10, 2010 1:37 pm

Origin works oddly?

Post by bibbinator »

Hi,
This post is just out of curiosity, not an issue exactly.

When I change the origin of a layer, I sort of expected that it would either leave the layer visually where it is and modify the keyframes to account for the offset, or leave the keyframes and visually move the layer, but this isn't the case.

If I create a new image layer and then put the anchor in the lower left corner, I would expect then that when I click on the move tool I could see the current position of the layer as now being the inverse of the amount I put in the anchor, or that when I placed the origin the layer would snap and reorient to the new origin.

The workaround for my exporter was that I needed to offset all keyframes by the origin coordinates to make it work.

Obviously it looks and works fine in AS, but I was just curious about this. Why does the origin not effect the positions of things (or at least the coordinates for keyframes effected by it)? Was this a usability decision?

Cheers,
Brett
User avatar
lwaxana
Posts: 1295
Joined: Wed Jan 06, 2010 6:50 pm

Post by lwaxana »

If I'm understanding you correctly, you're making an observation that AS uses both an absolute coordinate system (0,0,0 is always in the same place) and relative coordinate systems (the position of 0,0,0 can be changed).

When you compare the move tool coordinate system with the layer coordinate system, you must be talking about the "translate points" tool from the draw menu, right? Basically the draw coordinate system is not following the same coordinate system that the layer is.

Here's how it works (as far as I can tell):
All the layers move around within an absolute coordinate system.
Each layer is positioned within the absolute coordinate system, but it also acts as a portal to a secondary relative coordinate system. The origin of that coordinate system is at the center of the the "layer anchor."

It's kind of confusing to explain without pictures, so I hope that made sense.

Without a second coordinate system, I don't think the "translate layer" tool could actually do anything.
bibbinator
Posts: 17
Joined: Wed Mar 10, 2010 1:37 pm

Post by bibbinator »

Thanks for your post.

Yes, like all systems with coordinates, there is a concept of world space and local space. AS has the same concept whereby each layer is specified in the local space of it's parent. So a root layer's parent is in world space, so local space = world space and so things work as you would expect visually (all units in canvas space).

If I create a sub-layer, it then moves around in local space to the layer above, and also visually works as expected. No surprise here either.

What surprised me was that when you move the origin of a root layer, I expected the layer to visually move to accommodate the change or the position to offset by the inverse amount to visually keep it where it was on the canvas (but reflect the fact that the layer is now offset. The reason why is that it you take all those coordinates and render it in any other tool (or draw it on paper) you won't end up with objects in the same position (I know because I'm writing an exporter and the positional keyframes are all off by the inverse amount of the origin).

Anyways, no worries, it was easy to get the right data out!

Cheers,
Brett
User avatar
lwaxana
Posts: 1295
Joined: Wed Jan 06, 2010 6:50 pm

Post by lwaxana »

Haha, I'm in over my head here, but now I'm curious. When you refer to a sublayer, do you mean a layer within a group layer? Because if I use the layer translate tool on a group layer, the layers within the group layer do visually move. Or does this problem only show when rendered in another tool?
bibbinator
Posts: 17
Joined: Wed Mar 10, 2010 1:37 pm

Post by bibbinator »

You're not in over your head, it's just a little confusing, especially to talk about!

Forgetting AS for a moment, and thinking of say a piece of graph paper.

If I have a box that is 10 x 10 units, and I tell you the origin is at 5,5, then you can envision the box in local space on the graph paper as having the left and bottom edges touching the axis and a dot in the middle at 5,5 at the origin (assuming positive runs right for x and up for y for this example).

Now, if I cut out that box, put a pin through it at 5,5 (the origin) and then ask you to place it on another piece of paper at 10,10 what would you do? You would naturally push the pin in at 10,10, thereby having the left and bottom edges 5 units to the right above the bottom.

Of course coordinate systems vary, and which quadrants are positive, negative, etc., etc. but this way of thinking is how all 3D programs and most 2D programs I have worked with work.

Now in AS let's do the same thing. I create a box 10 x 10 units and it sits in the center of the screen and the origin is at the center. In terms of graph paper, I would say the box is defined by extents -5,-5 to +5,+5 with the origin at 0,0. So far so good. Now though, if I change the origin to say the bottom left corner, then I would expect either:

1. The box doesn't move visually, but the origin moves visually to the bottom left corner. That means that I would expect it's position to now be -5,-5 to reflect the fact that it's origin (the anchor point we're holding onto to move it) is actually 5 units away now.

2. The origin stays put in the center of the screen and the box moves 5 units to the right and up.

In AS it leaves the box where it is, visually moves the origin and all is well (and in fact all transforms such as rotation and so forth will obey this origin as expected).

The only puzzling piece is why the translation/position doesn't reflect this origin.

So when I import the AS file into another program, the box is in the wrong spot and all the keyframes positions are also in the wrong spot, simply because they also expected the positions to be offset to account for the moved origin.

The fix is simply to add the inverse of the origin to all keyframes on import which then yields the expected result.

Again, I'm not faulting AS here at all. Just an oddity among the programs I have used, and since I have found AS to be an excellent animators tool, was curious why they did this. Perhaps it was easier for users to understand?

At any rate, no worries, just can't help being curious!
User avatar
lwaxana
Posts: 1295
Joined: Wed Jan 06, 2010 6:50 pm

Post by lwaxana »

So you're saying that the layer's coordinate extents (and origin?) are not actually moved at the code level, but it appears that they have moved in the anime studio user interface because all visual indications like grids, vectors, images, etc. visually obey the new origin?
bibbinator
Posts: 17
Joined: Wed Mar 10, 2010 1:37 pm

Post by bibbinator »

Basically yes. The code can work of course, but the edit fields in the workspace don't show the coordinate offsets.
Post Reply