Rasheed's scripts

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

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Rasheed's scripts

Post by Rasheed »

Here are some scripts I've created. I hope you'll find them useful. If you have any questions, feel free to add a message to this thread. You can modify the scripts to fit your own needs.

TransRotate

Updated: 27 January 2006
Download: TransRotate.zip
Status: working, but still heavily under development

Description: A layer script that attaches a slave bone to a master bone. It uses bone translation to keep the slave bone in the same location as the master bone. The master bone can be translated, and its parent bone rotated or scaled, and still the slave bone will translate to the position of the master bone, without rotating or scaling. This is a way to turn bone rotation and bone scaling of a bone's parent bone into simple bone translation, which then can be used to constrain other bones in their position (via the Bone Constraint position options of the slave bone). Embed this script in a bone layer.

Additional comments: The slave bones should be called after the master bone, with ".tmp" at the end.

At this moment, the slave bones can be root bones (bones without parent bones) or have a parent bone, and the slave bones should be not be constraint (by angle, position or scale) by other bones, or have any other bone constraints on them. Master bones can be either root or child bones, but should not be constraint by other bones. Both slave and master bones can be parent bones.

If you want to offset the slave bone, relative to the master bone, use the Offset Bone tool in frame zero.

This script has some options, which are described in the script text. There is also an utility script available, which lets you add the functionality of this script to your own layer scripts.


FlipByBones

Updated: 18 January 2006
Download: FlipByBones2.zip
Status: working, but still heavily under development

Description: A layer script that reverses the z coordinate of a layer, based on the position of one bone (the control bone), relative to either another bone, or two other bones (the boundary bones). This is a way to influence the order of a layer in a group of layers during animation. Embed this script in a bone layer.

Additional comments: The boundary bone/bones should have the same name as the layer they control, with the extension ".flip" (for one boundary), or ".flip1" and ".flip2" (for two boundaries), and the bone that controls the z coordinate should have the same name as the layer it controls, with the extension ".now".

The document should have the 3D camera and Layer sorting by depth turned on, and the Sorting by true distance turned off. The controlled layer should be a child layer of the bone layer, and should be translated in the z direction in frame zero. The bone layer should have its Sorting by depth turned on, and Sorting by true distance turned off.

The layer translation of the controlled layer is completely taken over by the layer script, any layer translation keys that are already present in all frames, but frame zero will be overwritten. The layer translation keys use step interpolation, so the layer is either in front or in the back.

The bone translation keys of the boundary bone(s) and control bone should have linear interpolation. Another type of key interpolation of these bones can lead to unpredictable results.


Image Copy and Paste Bones

Updated: 23 January 2006
Download: Nothing yet.
Status: Still under heavily development.

Description: A tool to copy and paste existing bones. Here are the options I want to incorporate in the first version:
  • normal clicking -> copy a bone
  • Alt-clicking -> select/deselect a bone
  • Ctrl-clicking -> paste a bone at the current cursor position
  • option to reparent the current bone to the parent of the original bone
Optimize curves

Updated: 23 January 2006
Download: Nothing yet.
Status: Still heavily under development

Description: A tool script that allows you to reduce the number of points within a set of selected points, based on the desired smoothness of your curves. Here are the options I want to incorporate in the first version:
  • option for a lasso mode
  • normal clicking -> select/deselect points
  • Shift-clicking -> modify current point selection
  • option to set the desired smoothness value (0 - 100%)
  • option to select curves only
  • option to do multiple passes
  • option to show totals as a result
Last edited by Rasheed on Sun Jan 28, 2007 1:12 pm, edited 7 times in total.
User avatar
DK
Posts: 2849
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Hi Rasheed,
Thank you for those scripts. They sound like they will be really useful. Would it be possible to describe a scenario where the scripts might be used?

Cheers
D.K
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

The TransRotate and FlipByBones scripts are developed to simplify head (and body) turns in 2D animation. With the TransRotate script you can project the rotation in a 2D layer into a translation along a line. With the FlipByBones script you can move an ear or any other part of the head from the front to the back while the head turns, so it moves in and out of sight.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

FlipByBones can also be used to move other body parts such as arms or legs above other layers.

For instance a characters arm can go in front of the body, then by moving a bone the arm goes behind the body. With a different bone for each arm or limb lots of options for different effects. This can streamline the animation process by keeping those key frames in "one spot".

My particular use of it will be for ears on head turns. I plan to have it based on a bone passing the center of the face causing the ears to swap levels.

However the layer flipping bone control doesn't have to be limited to any specific motion of the bone. It could just be a "switch" control, like a "toggle" to make any layer pop to the front or behind other layers at the animator's whim. The beauty is that the control is keyed on the BONE LAYER. No need to select another layer and change keys for the translation.

The power of both of these scripts may not seem obvious at first glance. But trust me... this is HUGE! The flip by bones script is amazing!

The trick is to use very small values for the z translation. I use ".01" for my tests. This will prevent the layer from "shrinking" or "enlarging" due to being closer to the "camera". Larger values the change in z-depth is very noticeable. Really small values it is hardly noticeable at all. It doesn't matter how small the value is as long as it isn't "0".

-vern
User avatar
DK
Posts: 2849
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

It would be great to see a sample moho file if possible. It sure does sound handy. How the layers can flipped. Does the script use a switch layer?

D.K
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

Although I suck at drawing and animating, I could piece together this rough animation of a head turn It uses the FlipByBones script, with the utility script of the TransRotate script added to it (both scripts now run simultaneously in the same script).

The TransRotate is used to translate the central root bone (to which other bones are attached), and to rotate the ears. I didn't do the positioning of the ears very well, they are obviously too far to the front of the face. The FlipByBones script was used to bring the ears to the back.

Image

Source: HeadTurn.zip

This is not at all representative of what you can do with the script, but it shows the reordering of the layers pretty well.
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

DK wrote:How the layers can flipped. Does the script use a switch layer?
No, it uses a bone layer, and a layer script embedded in that bone layer.

The bones that control the z depth of the left and the right ear are named after the layer in which the ears are located (called L ear and R ear). These bones are completely separate bones, don't control any points directly, and are merely used to give the layer script some input. You, the animator, control the z depth by dragging one bone left or right from the other bone.

Take the left ear. Its layer is called "L ear". The boundary bone is called "L ear.flip", and the control bone (that controls the z depth of the layer "L ear") is called "L ear.now". In frame zero, the "L ear.now" bone is at one side of the "L ear.flip" bone. If it goes to the other side of the "L ear.flip" bone in frame 2 or higher, the z coordinate value of the "L ear" layer is reversed (minus becomes plus, or plus become minus).

If the 3D camera is on, and layer sorting is both turned on in the document and the bone layer (not sorting by true distance, because that messes things up), this means you can bring the "L ear" layer to the back and front by simply dragging a bone in the bone layer.

However, there is a catch. You can only animate in frames two and higher, and you must use linear key interpolation in the bone translation animation channel. Any other key interpolation will give unpredictable results. Because it is a good thing to reset all bones in frame one, the restriction of only being able to animate in frames 2 and above isn't really a big restriction.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I've found that using "Smooth" interpolation on the bone translation works fine. It puts the key frame for the layer depth in the same spot as linear.

the other interpolation methods don't work at all as far as I can tell. Not a problem for me so far.

I have been using constraints to control the "flipping" so that the actual flip just happens at the right time by tweaking the position or translation constraint of the controlling mesh bones.

For instance if the flip doesn't happen in exactly the right spot, I can tweak the bone positions on frame 0 or the constraint value to adjust it. Sometimes I have characters with wider or thinner heads and the ears need to flip at different spots.

Another trick is to just use the bones as a "toggle". Put them both ("now" and "flip" bones) right next to each other. A simple nudge of the bone on a key frame raises or lowers the layer.

Thanks so much for this... I keep saying it... but it's wonderful! I have been looking through a bunch of old stuff and found a bunch of times I had to use duplicate arm and leg layers, use visibility or keyframe z-depth... Good grief! I have a head turn where I had to scale the dang ear to a thin line so it fit inside the line of the head to make it work. This is SO much easier.

-vern
User avatar
DK
Posts: 2849
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Post by DK »

Heyverne. Could you post a gif of what you've been working on? It would be nice to see as well as Rasheed's.

D.K
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

Well, I was hoping Vern would be posting something. Here is an improvement. I used bone scaling instead of bone rotation for the ears. That seems to work much better.

Image

You know, actually, it is a big advantage that I am such a poor animator, because this means my tools have to be really useful to help me animate. If I was an accomplished animator, I probably wouldn't put so much effort into my scripts, because I could do much of the animating "on the feel".

Source: HeadTurn2.zip

Further improvement could be to include a lower jaw, eyebrows, and hair.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I will post something soon I promise.

The real world intrudes

NOT the show on MTV... I mean MY real world requires attention. ;)

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

Post by heyvern »

Now Rasheed, I need you to be honest and not do anything that you don't want to. Feel free to tell me to go jump in a lake. ;)

You mentioned it might be possible to add children bones to the TransRotate script.

Here's is the situation. It works like a charm. However I would like to add children off of the "tmp" bone or the master bone so I can create multiple points of 3D space for rotation easily by adding additional bones. This works so beautifully and uses that 3D... math... stuff that Genete came up with. It is fantastic. I can pin point any spot in a 3D rotation using these child bones just by moving them away from the rotation point.

However this requires two bones instead of just one. If I add a new child to the "master" bone, I still need a "tmp" for constraints. Would there be a way to somehow, follow the chain of child bones only for the tmp bone (if that is easier) to get the translation?

Or even the bone that the tmp bone refers to? I hope this makes sense. The tmp bone doesn't need to belong to a parent, but it would be nice if that set of bones could be extended by using child bones.

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

Post by heyvern »

Rasheed,

The flipbybones acts strangely with constraints controlling the now bones translation.

When the two bones, now and flip, cross on the first pass, it works fine. When they cross "back" so the layer flips to the original z depth it doesn't work then or any subsequent key frames.

It seems there is something weird happening with the keying after the first pass when using constraints.

Also I haven't confirmed this yet, but it seems transrotate and flipbybones might be conflicting when used together (utility script). Sometimes the transrotate bones just stop working right after flipbybones is "activated". Maybe they are deleting each other's key frames or something?

-vern
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

Vern, I will have a look into both issues, being able to make the tmp bone a child, and the possible interaction between the FlipByBones and TransRotate scripts.
User avatar
Rasheed
Posts: 2008
Joined: Tue May 17, 2005 8:30 am
Location: The Netherlands

Post by Rasheed »

I have not yet uploaded the TransRotate script, but I'm developing a new version locally. I still have to check a possible interference with FlipByBones script, and until then, I will not publish the new version of the TransRotate script.

I have modified the TransRotate script and it works like a charm. I have also properly commented the script, so it is much easier to understand, and make modifications to it, so it suits your particular needs.

Slave bones can now have parents. To keep the slave bones in the same location as their master bones, I needed each slave bone to translate in the opposite direction as the slave bone's parent translates its child bone.

This means if you constrain the position of a separate bone to that slave bone, it will move the constraint bone, because of the slave bone is moving in the opposite direction, trying to remain in the same screen position.

This is the reasoning:
  • master bone is stationary
  • slave bone's parent tries to move the slave bone
  • the script translates the slave bone in the opposite direction, in order to keep it stationary (at the same screen location as its master bone)
  • the bone that is position constraint to the slave bone moves, because the slave bone's bone position value changes
heyvern wrote:You mentioned it might be possible to add children bones to the TransRotate script.

Here's is the situation. It works like a charm. However I would like to add children off of the "tmp" bone or the master bone so I can create multiple points of 3D space for rotation easily by adding additional bones. This works so beautifully and uses that 3D... math... stuff that Genete came up with. It is fantastic. I can pin point any spot in a 3D rotation using these child bones just by moving them away from the rotation point.

However this requires two bones instead of just one. If I add a new child to the "master" bone, I still need a "tmp" for constraints. Would there be a way to somehow, follow the chain of child bones only for the tmp bone (if that is easier) to get the translation?

Or even the bone that the tmp bone refers to? I hope this makes sense. The tmp bone doesn't need to belong to a parent, but it would be nice if that set of bones could be extended by using child bones.
Sorry, I don't understand what you mean. Can you please give me an example?
Post Reply