Transform Bones Script

General Moho topics.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 9:29 am
Location: Sunny Florida
Contact:

Transform Bones Script

Post by mkelley »

I was complaining about AS 6 not having the ability to resize bones during a copy/paste (one of the things Vern's script did) and I suddenly realized this wouldn't be a big deal to program so here's a 5.6 version of that:

http://www.kelleytown.com/freeware/mk_i ... sforms.zip

I haven't tested this yet in 6.0 but I will shortly. However, along with most folks 5.6 will be my production tool for a while to come so I wanted to get this up in case anyone else needed it. It works by taking the layer transforms and applying them to the bones and then resetting the layer. A couple of notes for those brave or foolish enough to try it:

1) It works on any frame other than zero. This was by design but right now it doesn't matter much since the transforms of the bones are the same no matter what frame you do them on. Later it may be a bigger deal (see below).

2) Position and scale work more accurately if you do them one at a time. You can do them together but due to the way the cumulative effects are the position will be a little off (scale will be correct, though). I will work on fixing this but position is mostly for eyeing how the scale should be (IOW, the idea is you copy your bones in and then align and scale as needed).

3) Rotation works but since the axis of the layer is central and rotation is more complicated (needs to be the parent) your position will move more or less depending on how far you are away from the layer center. Once again, mostly for eyeballing purposes of getting the bone scale right, but I'll work on trying to get it better.

4) Eventually the idea is to apply this not only to bones but to vector layers and then to groups (with all children in that group inheriting the transforms). I suspect it will be far easier to apply this to vectors but given how very little I know about the AS API and how little it's documented it's kind of slow going (with better documentation I would have had this done in a heartbeat, as the programming is REAL straightforward. Right now the only way to actually program ANYTHING in AS is trial and error and standing on the shoulders of those who came before. In that regard I thank Vern for his bone copying script or I wouldn't even have a clue as to where to begin).

If I can get this working the way I want then it will create keys for animation purposes (right now there isn't any need or functionality to having keys for the bones, since you can't undo or use them in any way -- bones are sized and positioned the way they are at frame 0).

(The best part about releasing this now is that it's sure to get lost amid all the 6 talk so that only the hardcore folks will criticize :>)
User avatar
heyvern
Posts: 7045
Joined: Thu Sep 01, 2005 8:49 pm

Post by heyvern »

Brilliant job! I love it!

I don't have any details but the new "walking the scene" in 6 should make changing sub layers in groups easier. 6 has more direct access to ALL the layers. Much more so than 5.6 does. 5.6 you really were only able to work directly on a layer that was selected... without jumping through hoops or selecting the layer with the script.

-----

I have some routines for modifying sub layers in 5.6 and will track them down and paste the code in this thread. I had a huge project with custom scripts that did EXTENSIVE modifications with ALL the layers in a document including group sub layer access. It should help you out.

-vern
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 9:29 am
Location: Sunny Florida
Contact:

Post by mkelley »

Thanks, Vern. If you do come across that code it would be appreciated.

One more thing I forgot to add about this version -- when scaling the bones it only takes into account the x scale. You can scale uniformly (dragging the corner) and it just takes the x scale to process and that's the way I use it, but if you only scale in the y direction nothing will happen to the bones.

If I had my druthers I'd somehow lock the scaling so it could only scale uniformly on a bone layer -- now, I could certainly write the tool that way (and may :>) but that won't do everyone any good unless they substituted that tool. But as it stands now (and I suspect in version 6 as well) there isn't much point in scaling a bone layer in only one direction unless you are going for some very weird looking effect.

When I start adding vector to this then I will take into account both scaling directions. I need to pause for a moment and write some more shows before I can get too heavily involved in programming right now (but I will test this in 6 just to get my feet wet there).
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 9:29 am
Location: Sunny Florida
Contact:

Post by mkelley »

For those of you playing with AS 6, here's that version of the script:

http://www.kelleytown.com/freeware/mk_i ... orms_6.zip

The nice thing, of course, is that in 6 you can copy/paste bones, and with this script you can then resize and align easily. My basic workflow would be to create a new bone layer, then go to the previous bone layer and select the bones I want (say an arm portion), go back to my new bone layer and copy them in, and then use the layer transforms to size, rotation and position the bones the basic way I want. Finally I'll use my inherit script to "bake" those transforms into the bones (and then the process can be iterated so you can construct your rigs exactly as you need them).

If this works as I suspect I'm finally going to be able to have a library of bone rigs and parts that makes sense (including having some very standard bone names for all). Vern's script that did much of this was nice, but rather cumberson in terms of sizing (you had to guess at it). Being able to visually get the bones I like exactly the way I like them has me real excited (well, the LITTLE things excite me :>)

I will say that in AS 6 the combo of position with scale or rotation is even further off than it is in 5.6 -- obviously due to my ignorance of how scripting actually works and it should get better, but anyone who knows more than I do about this (which would be, basically, almost anyone) is welcomed to look at the script and set me straight (but I promise I'll figure it out eventually). It isn't a deal breaker, as it just means you need to nudge the position back to where it should be once you're finished (or you can do position separately, which works just fine).
User avatar
synthsin75
Posts: 10397
Joined: Mon Jan 14, 2008 2:20 pm
Location: Oklahoma
Contact:

Post by synthsin75 »

Wow, amazing script, Mike! Using this even maintains the skeleton's animation, which the other didn't. For building new characters that would work great and make for very uniform skeleton bone names and construction. That will be very helpful once Vern finishes his script that transfers animation across rigs.

Really very good work. :D
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 9:29 am
Location: Sunny Florida
Contact:

Post by mkelley »

I'm even more stoked now that Mike has released scripting docs (as I'm sure you are as well). As good as AS 6 is, it will only get much better when we can get our teeth into things.

I'm really torn, though -- it's soooo much fun to play with scripting that I have to force myself to work on the actual series. I never thought I'd get back into programming once I retired, but this really is very cool stuff.
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 9:29 am
Location: Sunny Florida
Contact:

Post by mkelley »

Okay, the new version now correctly handles position and scale at the same time (same download location -- new version for AS 6 only at this point until I get all the bugs worked out. Can't work on two versions at once).

Rotation is still a problem: I know what the problem is, and I even know the solution. I just don't have the math in my head right now (once upon a time... but there we go again). The bones WILL rotate correctly, but because they are rotating around the layer's origin they are repositioned incorrectly. I need to calculate the offset from the origin and use Pythag and other stuff in order to reset it. I *will* get this but if anyone is more math capable than I they are welcome to help here.
User avatar
mkelley
Posts: 1647
Joined: Fri Nov 02, 2007 9:29 am
Location: Sunny Florida
Contact:

Post by mkelley »

Okay, the new version now handles rotation, position and scaling properly (even all at once :>). Still only works on bone layers, but that's pretty useful in combination with the bones copy/paste (this is for Version 6 only).

My next step is to do vector layers but I have to pause right now -- sounds weird, but I do have a whole other sort of job that doesn't require programming anymore. Plus if I DO get some time to program I want to work on a batch renderer to offset the only other real problem I have with AS right now. But I promise I'll be doing some very cool things, particularly if Mike can address the syntax checking problems in AS 6 (I'd have had this thing done a couple of hours ago if I hadn't run into that major issue).
Post Reply