WIP - Multiple bone constraints on one bone tool

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

WIP - Multiple bone constraints on one bone tool

Post by heyvern »

So I'm off on a crazy adventure. I am trying to create a sort of... uh... well... a replacement of current bone constraints.
The current constraints work great but there are limitations that have annoyed me. For example, you can only have one bone for each constraint. The position constraint changes direction depending on how each bone is parented or rotated. I am very ambitious and want to make position constraints based on "world" or screen space. So if you move a bone up, it moves the constrained bone up no matter where it is in the rig.

This is a result of a very old super complex rig I created many years ago but still love using but it is very difficult to modify and use. It has on average 300 bones. Since I couldn't have multiple constraints on one bone controlling one point, I used multiple bones in exactly the same spot all with the same strength but constrained by controller bones to move in different ways. Using this new script I could knock the number of bones required to a small fraction it currently has making it much easier to create new rigs for new characters.

I would like to fix this with a new tool script. So far I've got it all set up with all the bits and bobs ready but I really need more info on saving script data to the bone layer. I know this is done quite a bit using the new-ish

Code: Select all

moho.layer:ScriptData()
Any guidance or suggestions on which existing scripts to poke around in to get an idea of how it works would be great.
Maybe some info on how much can be saved and the best way to delimit or organize the data. For example, I will need to save multiple controls for each control property along with their values.


This is just a work in progress.
Image

The really really hard part (for me anyway) will be trying to figure out how to flip "matrices" and find all the movement vectors for the position constraints. I did some testing and the concept works. It will calculate the weighted percentages of each constraint value of each bone and use that to change the position, angle, or scale. I actually did some testing with a spreadsheet and it's not rocket science.

EIDT: One big thing I forgot to mention. This new constraint tool will work with an embedded layer script. The script will access the saved data created by the tool to move the bones around.
User avatar
synthsin75
Posts: 9973
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: WIP - Multiple bone constraints on one bone tool

Post by synthsin75 »

mohoscripting.com has some examples and links to scripts that use it: https://mohoscripting.com/methods/1122
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Re: WIP - Multiple bone constraints on one bone tool

Post by heyvern »

Thanks. I will check it out.

Just did a preliminary test and WOOOHOOO! This is going to be awesome! I had to script it "by hand" to make it work but having multiple position constraints is amazing.
I may just leave out the matrix conversions for now. I found some issues forcing everything to "world" space. When you rotated a head bone, for instance, you DO want the constraints to work within the local transformation.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Re: WIP - Multiple bone constraints on one bone tool

Post by heyvern »

It seems to be working! This is a very rough proof of concept. I don't have it hooked up to a menu yet with scriptdata storage. I am currently using a layer script and putting in constraints in the target bone name. It's a bit clunky because the bone names can get quite long but works fine.



This is so freaking exciting! In the example video which is very very rough and simplistic. The center head bone controls the head turn. The mouth bones are constrained to the head bone. The left and right mouth bones have a 50% constraint so they create a sort of fake 3D turn.

The bones on the right side control the SAME MOUTH BONES. That is the beauty of multiple constraints. Those bones ADD to the movement of the mouth bones on top of the turn bone movement to allow for lip sync or smile etc.

TODO List:
While working on this I realized it's a piece of cake to add in additional features. For example "flipping" the direction of the constraint. Instead of always in one direction the constraint can flip from positive to negative based on bone location or percentage of movement. this would allow for easy to create 2.5D head turns and other things. I can finally have my original head rig back without using 300+ bones!
User avatar
DK
Posts: 2854
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Re: WIP - Multiple bone constraints on one bone tool

Post by DK »

Wow! This is great Verne. Would it be possible to script something so that the ear bones move back inwards on the X axis at a certain point rather than floating off into space? I really love where this is going. Great work!

Cheers
D.K
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Re: WIP - Multiple bone constraints on one bone tool

Post by heyvern »

DK wrote: Wed Jul 19, 2023 6:43 am Wow! This is great Verne. Would it be possible to script something so that the ear bones move back inwards on the X axis at a certain point rather than floating off into space? I really love where this is going. Great work!

Cheers
D.K
Absolutely yes yes yes! As I found I had issues with bone parenting causing the bones to not move correctly so I added code to flip x and y positions based on different parents of the target and the control bones. Then it dawned on me I could do the exact same thing and just have the constraint flip "halfway". add some sort of "flip" or reversal checkbox to the tool to flip the direction of the constraint. Maybe based on location in the workspace or some other part of the rig.

The next step is linking this up to the dang popup tool menu and learning how to store the bone constraint data in the file.
and of course adding in multiple scale and angle controls. I've been focused on position because it's more important to me but the others will be in there as well.
User avatar
DK
Posts: 2854
Joined: Mon Aug 09, 2004 6:06 am
Location: Australia

Re: WIP - Multiple bone constraints on one bone tool

Post by DK »

Also, really like how simple your demo rig is too Verne. Very easy to understand what is going on.
Cheers
D.K
No2Nuclear
Posts: 9
Joined: Mon Sep 18, 2023 10:42 pm

Re: WIP - Multiple bone constraints on one bone tool

Post by No2Nuclear »

Hi this is the sort of thing I am wanting to do. Is it easy? and can it be done on 13.5 if you do not have the pro version? (I do not have smart bones options or actions)

Nuke
Post Reply