Control z depth of a layer with bone translation?
Moderators: Víctor Paredes, Belgarath, slowtiger
Control z depth of a layer with bone translation?
Is this possible?
My dream is this:
Bone layer with multiple vector layers. Put a script in either the bone layer or the vector layer (vector would be better).
The script would change the z depth of the layer when a specific bone passes a certain point in horizontal space.
This would be great for head turns using bones. You could have the ears on these layers that could change z depth depending on the x translation of a bone. As the head turns the ear layers could go behind or in front of the head.
-vern
My dream is this:
Bone layer with multiple vector layers. Put a script in either the bone layer or the vector layer (vector would be better).
The script would change the z depth of the layer when a specific bone passes a certain point in horizontal space.
This would be great for head turns using bones. You could have the ears on these layers that could change z depth depending on the x translation of a bone. As the head turns the ear layers could go behind or in front of the head.
-vern
Not with the bones but yes with the switch.
Let me explain:
THIS IS THE SETUP: (SL =Switch Layer; VL=Vector Layer)
SL: head switch
-VL1: Head front
-VL2: Head right
-VL3: Head left.
In VL2 the right ear shape can be behind the face and the left ear avobe.
In VL3 the left ear shape can be behind the face and the right ear avobe.
In VL1 both ears can be avobe of behind the face (depends on te character)
As well as switch layers can have bones (exacly like bone layers) they affect all layers inside at the same time. So if VL1, VL2 and VL3 have same points (and bones obviously) then you can perform a switch in the moment you want the ear go behind or avobe the face. There is a disadventage: You have to have everything in one layer.
If you want you can automate head turning with actions where one grabbed keyframe is a switch ... I love actions.
I was working on that when discovered the bug of multilpe constraints. Now I'm concentrated in the constest
so no example for you is done
Hope it helps.
-Genete
Let me explain:
THIS IS THE SETUP: (SL =Switch Layer; VL=Vector Layer)
SL: head switch
-VL1: Head front
-VL2: Head right
-VL3: Head left.
In VL2 the right ear shape can be behind the face and the left ear avobe.
In VL3 the left ear shape can be behind the face and the right ear avobe.
In VL1 both ears can be avobe of behind the face (depends on te character)
As well as switch layers can have bones (exacly like bone layers) they affect all layers inside at the same time. So if VL1, VL2 and VL3 have same points (and bones obviously) then you can perform a switch in the moment you want the ear go behind or avobe the face. There is a disadventage: You have to have everything in one layer.

If you want you can automate head turning with actions where one grabbed keyframe is a switch ... I love actions.
I was working on that when discovered the bug of multilpe constraints. Now I'm concentrated in the constest

Hope it helps.

-Genete
Good grief that would work wouldn't it? I like it.
The only drawback is having to change the switch key every time you turn the head (I am referring to my bone controlled head).
If z-depth could be linked to bone translation it would be "automatic" and just the bone key frame to worry about. You would never have to worry about setting any keys except the bones.
For instance on the head I did, there is one main head turn bone. Once it passes the middle of the face horizontally the ears would "switch" depths.
-vern
The only drawback is having to change the switch key every time you turn the head (I am referring to my bone controlled head).
If z-depth could be linked to bone translation it would be "automatic" and just the bone key frame to worry about. You would never have to worry about setting any keys except the bones.
For instance on the head I did, there is one main head turn bone. Once it passes the middle of the face horizontally the ears would "switch" depths.
-vern
Re: Control z depth of a layer with bone translation?
I tried something similar (control the 3D position of a rigged vector layer with the bone angle of a specially named bone in the parent bone layer). I found that when you access the parent bone layer from within a layer script in a child vector layer, it crashes Moho.heyvern wrote:Is this possible?
My dream is this:
Bone layer with multiple vector layers. Put a script in either the bone layer or the vector layer (vector would be better).
The script would change the z depth of the layer when a specific bone passes a certain point in horizontal space.
And since you want this to work dynamically, you must use layer scripts. Unfortunately, because of this apparent bug, it is not yet possible.
I will investigate this further and try to file a bug report ASAP.
Re: Control z depth of a layer with bone translation?
What about the other way around? Put the script in the bone layer that looks for the child layer name. I was thinking you could name the bone the same as the layer.Rasheed wrote:... I found that when you access the parent bone layer from within a layer script in a child vector layer, it crashes Moho.
-vern
I had used three bones, which had the layer name, plus '.x', '.y' and '.z', so you could translate the layer along an elliptical path in the yz, xz and xy planes, respectively, based on the bones' length and current angle, relative to the angle in frame zero. I will try to rewrite my script so, that it can be embedded in the bone layer, and see if that crashes Moho if you select another layer and then go to another frame in the timeline.
I think such a script is more useful than what you suggested, because you can move the layer along a path using bones, instead of just to the front and the back. In essence, those bones would be controlling the layer position on a sphere or ellipsoid. I planned on using the bones' length values for the dimensions of the ellipsoid, and use bones' scale to scale the ellipsoid in x, y and z direction. The layer would always be parallel to the screen, other than you were using rotation along the x or y axis, which changes the orientation of the layer. Of course, you could still rotate the layer with layer rotation.
Needless to say, that when this works, your script will be a piece of cake to create.
I think such a script is more useful than what you suggested, because you can move the layer along a path using bones, instead of just to the front and the back. In essence, those bones would be controlling the layer position on a sphere or ellipsoid. I planned on using the bones' length values for the dimensions of the ellipsoid, and use bones' scale to scale the ellipsoid in x, y and z direction. The layer would always be parallel to the screen, other than you were using rotation along the x or y axis, which changes the orientation of the layer. Of course, you could still rotate the layer with layer rotation.
Needless to say, that when this works, your script will be a piece of cake to create.
Update: I have completely rewritten the old script and it didn't crash. I can collect the polar coordinates of the layer translation in this way:
angle = current_bone_angle - bone_angle_at_frame_zero
length = bone_length * current_bone_scale
I have three angles and three lengths per layer, which I will put in consecutive matrices, so I can calculate the cartesian coordinates of the layer translation. Once I have done that, the layer script should work. It is a lot of math, but that shouldn't be any problem for a computer.
Update2: Well, I have something, I only don't what it exactly is. The transformations are rather comical. 3D space is being distorted...

The rectangle and torus should have remained undistorted, but instead something strange is going on. I'm afraid this will take some time until I know what to do.
The X, Y and Z in the animation stand for the 3 bones that control rotation along the x, y and z axes.
Update3:
Stupid me. I forgot that if you don't use an extra stationary bone to bind a layer, therefore, both child layers were influenced by the "dynamically controlled bones" through normal bone action. Here is the fix:

Next time, I will present a layer script that allows you to move a layer in the z direction by moving a specially named bone. That shouldn't be too difficult at this point...
angle = current_bone_angle - bone_angle_at_frame_zero
length = bone_length * current_bone_scale
I have three angles and three lengths per layer, which I will put in consecutive matrices, so I can calculate the cartesian coordinates of the layer translation. Once I have done that, the layer script should work. It is a lot of math, but that shouldn't be any problem for a computer.
Update2: Well, I have something, I only don't what it exactly is. The transformations are rather comical. 3D space is being distorted...

The rectangle and torus should have remained undistorted, but instead something strange is going on. I'm afraid this will take some time until I know what to do.
The X, Y and Z in the animation stand for the 3 bones that control rotation along the x, y and z axes.
Update3:


Next time, I will present a layer script that allows you to move a layer in the z direction by moving a specially named bone. That shouldn't be too difficult at this point...
Errr, study these screenshots.


Layer ordering only seems to apply at the root level, and not for layers inside group type layers.
So it seems z translation is not going to help you, Vern
I made a script that consisted of two bones. If the bone named "layer.now" was left of the bone named "layer.flip", the layer called "layer" was mirrored in the xy plane, otherwise it was at the position of frame zero. Obviously, when this layer flipped behind the xy plane (at the side of the negative z axis), it didn't disappear behind any objects in the xy plane, because all objects were child layers of the bone layer.
This illustrates once again that Moho nor Anime Studio is a real 3D program.
The only solution I see now, is to use a switch layer and a master slave bone script for multiple bone layers. I don't think that is a very elegant solution to automate.


Layer ordering only seems to apply at the root level, and not for layers inside group type layers.
So it seems z translation is not going to help you, Vern

I made a script that consisted of two bones. If the bone named "layer.now" was left of the bone named "layer.flip", the layer called "layer" was mirrored in the xy plane, otherwise it was at the position of frame zero. Obviously, when this layer flipped behind the xy plane (at the side of the negative z axis), it didn't disappear behind any objects in the xy plane, because all objects were child layers of the bone layer.
This illustrates once again that Moho nor Anime Studio is a real 3D program.
The only solution I see now, is to use a switch layer and a master slave bone script for multiple bone layers. I don't think that is a very elegant solution to automate.
I did have trouble with depth ordering inside groups...
What about looking OUTSIDE the bone layer?
Could this script in the bone layer access layers at the ROOT with a specified name?
I had trouble with that using the switch slave script (Fazek? or 7feet?).
Anyway, I finally modified it so that it would work on multiple switches ANYWHERE in the AS document, inside groups, outside groups. etc etc.
My point is the script was able to identify and modify a layer that was not a child of that layer.
You have no idea how cool this could be... uh... yes I guess you do.
p.s. Any chance I could get a look at the script? I love to poke around in stuff like that but only if you don't mind.
-vern
What about looking OUTSIDE the bone layer?
Could this script in the bone layer access layers at the ROOT with a specified name?
I had trouble with that using the switch slave script (Fazek? or 7feet?).
Anyway, I finally modified it so that it would work on multiple switches ANYWHERE in the AS document, inside groups, outside groups. etc etc.
My point is the script was able to identify and modify a layer that was not a child of that layer.
You have no idea how cool this could be... uh... yes I guess you do.

p.s. Any chance I could get a look at the script? I love to poke around in stuff like that but only if you don't mind.
-vern
Sure, here's a zip archive with the layer script, description file, and example Moho file. You extract the files and embed the FlipByBone.lua script in the bone layer of FlipByBone.moho, to control the child layer called "hair". I know it's a lame example, but its simple enough for practice purposes.
FlipByBones.zip
It uses layer translation to flip from the front to the back, and vice versa, so the layer to be flipped should be offset by layer translation in the z direction in frame zero. The scripts add keys in the layer translation animation channel of the dynamically controlled layer, so you can move the layer to root level without losing the translations after you've animated inside the bone layer. I think this means there is no real need to write a complicated script that dynamically controls a layer's translation with bones outside a bone layer.
I will not release the MoveByPoint layer script, because it seems to be flawed.
FlipByBones.zip
It uses layer translation to flip from the front to the back, and vice versa, so the layer to be flipped should be offset by layer translation in the z direction in frame zero. The scripts add keys in the layer translation animation channel of the dynamically controlled layer, so you can move the layer to root level without losing the translations after you've animated inside the bone layer. I think this means there is no real need to write a complicated script that dynamically controls a layer's translation with bones outside a bone layer.
I will not release the MoveByPoint layer script, because it seems to be flawed.
Rasheed?
This script works perfectly! I just tried it. It works! YEEEEHAAAAA!
I don't know why exactly... but it works. It is usable as is. I plan to play around with it and see what I can do with it.
Are you sure you turned on depth ordering in the layer properties when you tested it? It wasn't turned on in the sample file.
Also you have to sort of scrub through to see the layering change.
Dang! I can't use this one AND the other one you wrote at the same time... I will have to perform a... TWO HEADED TRANSPLANT! Buaaa haaa haaa!
Good grief man. 3 killer scripts. You rule.
-vern
This script works perfectly! I just tried it. It works! YEEEEHAAAAA!
I don't know why exactly... but it works. It is usable as is. I plan to play around with it and see what I can do with it.
Are you sure you turned on depth ordering in the layer properties when you tested it? It wasn't turned on in the sample file.
Also you have to sort of scrub through to see the layering change.
Dang! I can't use this one AND the other one you wrote at the same time... I will have to perform a... TWO HEADED TRANSPLANT! Buaaa haaa haaa!
Good grief man. 3 killer scripts. You rule.
-vern
You need to embed the script in the bone layer (check Embed script file in the General tab of the bone layer, and select the FlipByBones.lua file in the file dialogue box that appears). Next, you need to turn on Depth Sorting in this bone layer (Depth Sort tab of the layer properties). To be sure, in the Project Setting, check Enable 3D camera and Sort layers by depth.
@heyvern: No man, you rock. If you can create an animation method that is simple to set up and perform, you will surely raise some eyebrows of non-AS and non-Moho animators. If they realize how powerful AS is by example, they will get very excited, and give it a try.
@heyvern: No man, you rock. If you can create an animation method that is simple to set up and perform, you will surely raise some eyebrows of non-AS and non-Moho animators. If they realize how powerful AS is by example, they will get very excited, and give it a try.
This script works fine on simple files.
In my big huge 150+ bones file it works when scrubbing through the timeline and in the preview. But for some odd reason it won't render properly. During the rendering of a movie file the layers don't translate correctly.
If I render a single frame it works.
Could it may be that my bone list is so long that the layering isn't taking place before the frame is rendered? That is a huge list of bones for your script to parse through. I just assumed that AS would process the script before rendering the frame.
I will try doing an image sequence and see if that makes a difference.
-vern
In my big huge 150+ bones file it works when scrubbing through the timeline and in the preview. But for some odd reason it won't render properly. During the rendering of a movie file the layers don't translate correctly.
If I render a single frame it works.
Could it may be that my bone list is so long that the layering isn't taking place before the frame is rendered? That is a huge list of bones for your script to parse through. I just assumed that AS would process the script before rendering the frame.
I will try doing an image sequence and see if that makes a difference.
-vern