Set layer transforms to zero?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
JimmyMcNulty
Posts: 16
Joined: Tue Mar 20, 2012 3:27 pm

Set layer transforms to zero?

Post by JimmyMcNulty »

Is it possible to set all the transforms of a layer to zero, without changing the position of the layer? So to say, zero out the transformation values. This would be very helpful. For example: If you want to combine two different rigs together under one bone layer and use bone parent master script, the layer transformations should be all on the same position. Otherwise they will behave different, because the bone rigs are not at the same position comparing the position of the layer. I hope you can understand, what I need. :wink: I can't find something like this. Maybe it's not possible.

Thanks for suggestions. :)
User avatar
hayasidist
Posts: 3831
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Set layer transforms to zero?

Post by hayasidist »

not totally clear to me what you want...

you can zeroise a layer translation, scale, rotation etc using the layer tools, so I guess this isn't what you want.

you (probably) could get the layer tansform matrix, set all the transforms of a given layer to zero, then change its parent layer transforms so that the child layer looked the same, but that wouldn't help if you had two child layers, each with different transforms?

you (probably) could get the (vector) layer transform matrix and zeroise, then move the points to make it look the same, but that would necessarily "flatten" any depth as you'll end up with the projection of the points in (x,y,z) space onto an (x,y) plane at constant z .. which might not be problem and may be what you want?

that would need you to do something such as GetLayerTransform() (or maybe GetFullTransform() ) then interpret the transform matrix so you can mesh:TranslatePoints(), ScalePoints(), RotatePoints()

??
JimmyMcNulty
Posts: 16
Joined: Tue Mar 20, 2012 3:27 pm

Re: Set layer transforms to zero?

Post by JimmyMcNulty »

hello hayasidist, thanks for the reply.
hayasidist wrote:not totally clear to me what you want...

you can zeroise a layer translation, scale, rotation etc using the layer tools, so I guess this isn't what you want.
Yes. I could just reset the layer values, so it's zero again. That's not what I want. All child-layers and everything on the layer would move.
hayasidist wrote: you (probably) could get the layer tansform matrix, set all the transforms of a given layer to zero, then change its parent layer transforms so that the child layer looked the same, but that wouldn't help if you had two child layers, each with different transforms?
??
Correct, with two layers and different transforms, this would be also a problem. But for me it's also a problem, if the parent and the child layer have different transforms.

I try to describe it better. There is a body rig and inside the bone layer, there is a switch layer for different heads. Both layers should have no transformation/rotation/scale values (because some scripts need this to work correct). Now the switch layer is not exactly matching the design with the body. So I have to move the switch layer to the right position. But now the switch layer will have transformation values.
I could just reset the values and start moving every part of the bones and the vektor layers back to the right position. But it would be much better and faster, to just "force" the layer to set the transformed position as the new zero position. :)
In 3D programs you can do this with your bones, so you can work with clear values.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Re: Set layer transforms to zero?

Post by heyvern »

This could be scripted and not really be that complicated. Remember that what you want to change is on frame 0 only. On frame 0 you can move points and bones without fear of anything changing. What I mean is, if you move the bones of a parent bone layer the exact same amount as the child layers points they will line up as before and it will work the same.

The trick here would be to get just the transformation x and y of the top layer that needs changing (z doesn't effect points). Find the value needed to set this to 0. For example; parent or sub layer is set to -0.3 x and you need it to be 0, you would need to move the layer +0.3 to be zero again. Once then you would have to move the points of each layer -0.3 to get those layers back to where they were when the layer was translated.

So imagine all of the switch layer vector layers have different shapes and bounding areas. You need to, select all the points, get the position of that point group, then add or subtract the layer translation value to that point group position. Doing this would put the points in the exact position they were in when the layer was "moved" but now is at zero (I do this by hand all the time).

Layer scaling and z translation are going to be a completely different situation. If you have a sub switch layer with scaling that needs to be "reset", and you need to maintain that size, you would have to scale and offset the bones keeping the locations. Then of course scale the point groups. I have a script I use occasionally to scale bone rigs using a percentage, but it actually simply duplicates the rig to another bone layer. I would need to modify this script to scale the existing bone rig.

Scaling the points in a relative matter is another issue because point scaling scales from the center of the bounding box of the points. This could cause some layers to change position or move incorrectly because the bounding box of the points could be quite different on each layer.

When I do this by hand I create an unfilled "box" that is larger than all of the points of each layer. I paste this box on each layer creating a new bounding area for scaling that is identical for all layers so that scaling is simple and keeps the points in the same position since they now have the same bounding box dimensions and will scale the same way. I actually will leave that unfilled box on the layers just in case I need to do this again in the future.

Everything I described above is actually not that complicated from a scripting point of view. It probably doesn't require using any matrices or global transforms at all because the goal is to set the "global transform" to zero anyway, and changing the regular point locations to match the original value. All pretty straight forward "addition and subtraction".

I have several scripts that individually do some of these things already. The tricky part would be hooking them together to do the whole thing with a click or menu script. The hardest part would be scaling. The translation is actually pretty easy.

The other tricky part would be z translation. If the z of a sub layer is not 0 then the "perspective" scaling is different. So to zero that out you would also need to do some scaling. However, I have yet ANOTHER script that does that as well for a completely different purpose. I could add that in to reverse compensate the z translation. Layer rotation zeroing might be quite tricky if needed. This would require the "bounding box" trick as well, for rotating the points in the exact same spot for each layer. The main problem here would be the rotation center point. The layer origin is used for layer rotation. The bounding box of the points is the origin for point rotation. This could get tricky. A workaround would be to create or modify the bounding box for the layers so that the center origin point of the box is on the layer origin point (I have also done this by hand on several occasions).

I have thought about scripting this process... but... in reality I do this "by hand" only occasionally when I have scaled sublayers like switches, and want to "zero" everything as you described. The "by hand" process doesn't take long for me depending on the number of layers to modify... it's just tedious and requires using a calculator (to calculate the sublayer translation of points) :) I weigh the time it would take to script this against the time it takes to "do it by hand" every once in a while.

The key to avoiding this situation (which doesn't help you at all in this case) is to try and keep layer transformations to a minimum during character creation and rigging. This is something I learned over the years which is why I don't have to deal with it.

However, in your description this could be a situation with two different complete character rigs that need to be "zeroed" out to work inside another bone rig.

My one question is what sort of scripts on the parent bone rig don't compensate for layer transformations? I don't know exactly what they do but it would seem to me to be a simpler process to modify a layer script to compensate for layer transformations so that all of the other stuff doesn't need to be done anyway.

Sorry for the long post. When I get some free time I could try to work on this or hopefully some of the information is what you need to script this yourself? Wasn't sure what you needed, scripting info or a script. :)
JimmyMcNulty
Posts: 16
Joined: Tue Mar 20, 2012 3:27 pm

Re: Set layer transforms to zero?

Post by JimmyMcNulty »

Hello,

I'm sorry, there was no time to answer over the last couple of days. Great ideas Heyvern. Thanks a lot.
heyvern wrote: You need to, select all the points, get the position of that point group, then add or subtract the layer translation value to that point group position. Doing this would put the points in the exact position they were in when the layer was "moved" but now is at zero (I do this by hand all the time).
I think this is the most important thing for me. Normally you can avoid scaling, but maybe you need to change the position. At the last project, one person was building the head and another person was building the body. Both persons were working with the same design. So scaling was no problem, but the position is not always the same. We could also do it by hand, but we normally have some more layers multiplied the needed head views. So it's a lot of stuff to change. And we have ~500 characters. With this informations it's maybe clear, that an automatic solution would be very useful.
heyvern wrote: Layer scaling and z translation are going to be a completely different situation.
[...]
When I do this by hand I create an unfilled "box" that is larger than all of the points of each layer. I paste this box on each layer creating a new bounding area for scaling that is identical for all layers so that scaling is simple and keeps the points in the same position since they now have the same bounding box dimensions and will scale the same way. I actually will leave that unfilled box on the layers just in case I need to do this again in the future.
Scaling sounds a bit more complicated, but I really like the unfilled box solution. This is also a good "doing it by hand" solution. Thanks a lot for this.
heyvern wrote: The other tricky part would be z translation.
Right now I didn't use this in my rigging solutions. But maybe in the future. But right now, the project is over. *phew*
heyvern wrote: My one question is what sort of scripts on the parent bone rig don't compensate for layer transformations? I don't know exactly what they do but it would seem to me to be a simpler process to modify a layer script to compensate for layer transformations so that all of the other stuff doesn't need to be done anyway.
I know I could modify the layer script. Normally you have to modify the scripts from rig to rig anyways. As example: bone_parent_master script - you can modify the channels and switch them on and off. But sometimes you need a channel, but over two displaced layers it would cause strange results.
heyvern wrote: Sorry for the long post. When I get some free time I could try to work on this or hopefully some of the information is what you need to script this yourself? Wasn't sure what you needed, scripting info or a script. :)
Not sorry, thank you very much for your time. :) Very helpful informations. I'm not good at scripting. It's possible for me to modify scripts, but normally there is not much time to dive into the difficult stuff. But maybe I will have some time soon. So normally I would need some help with scripts. But scripting advice is also very helpful. :)

Right now I'm switching to other stuff, I have to do. But I wanted to discover some solutions for different problems, to avoid the same problems for future projects. I'm originally from 3D and it's normal, that some things are different in ASP. But I think it gives you some very good solutions for many budgets and styles. And I must admit, I'm wondering, why some things are not in the program and nobody is missing it. :D

Ok, also long post. I need to dive more into the scripting stuff and think about some of the ideas. Very helpful. Thanks.
dkwroot
Posts: 680
Joined: Thu May 02, 2013 6:56 am
Location: USA
Contact:

Re: Set layer transforms to zero?

Post by dkwroot »

Jimmy, use my smart bone parent control script instead of the one you're currently using. I know exactly the problem you're facing and it's the reason I created another master bone controller. Unlike the script you're using, my script ignores the transformation matrix of the layers entirely allowing you to put bones where ever the heck you want. My script is in the thread below this one. :D

viewtopic.php?f=12&t=24177&p=133247#p133247
JimmyMcNulty
Posts: 16
Joined: Tue Mar 20, 2012 3:27 pm

Re: Set layer transforms to zero?

Post by JimmyMcNulty »

dkwroot wrote:Jimmy, use my smart bone parent control script instead of the one you're currently using. I know exactly the problem you're facing and it's the reason I created another master bone controller.
Nice. I will give it a try. Thanks a lot. :)
Post Reply