heyvern's copy/flip bones script problem

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

Moderators: Víctor Paredes, Belgarath, slowtiger

basshole
Posts: 443
Joined: Tue Feb 12, 2008 1:11 am

heyvern's copy/flip bones script problem

Post by basshole »

I'm having a problem with the copy/flip bones script that heyvern created. It's probably me, but nevertheless, I'll ask.

So, I have a front view of a character (dead on to camera, that is). I wanted each of his hands be viewable from the back side, and from the palm side. After creating a hand with the back facing the camera, with a working skeleton I was happy with, I figured I simply flip the hand skeleton around for the front view, then copy and reverse the vector layer, etc.

I downloaded the copy/flip script, followed the instructions (I think), and attempted to flip that hand skeleton, and got weird results. It worked (sort of. . .I don't think all the bones are being copied?), but I also got three HUGE bones that weren't there before. One on either side of the hand's root bone, pointed directly left and right of the root, and one bone off somewhere in the canvas. No idea where these came from.

Before I tried the flip, I named all the bones in the hand, with the extension lhfab (for example, root_lhfab). I put this extension in the "copied" slot in the dialogue box that pops up on running the script, and put "lhfaf" for the pasted extension. I selected the hand's root bone, and ran the script, and got the results I mentioned above.

I don't know if this matters, but the bones in question are in a switch layer bound to a hand bone in the parent skeleton layer.

Anyway. . . thanks.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I followed your naming convention and was able to flip the bones correctly.

The "bug" you mentioned is known to me. I don't have any error checking in the script so if it you've made a mistake it just sticks in bones in the wrong spot and creates bones it copied but couldn't paste correctly. I really need to do some error checking to prevent that... when I get some time I will.

The key is to do it exactly right. ;) The problem is the result of not doing something right.

For instance DO NOT name the ROOT bone with the extension. This will really mess things up. The script uses the extension to copy the bones so naming the root bone with the extension will be a bad thing.

Also I would use an underscore as part of the extension and also for the search. This prevents "accidental" matches (I did that a few times).

If you still have trouble and want to send me the file BEFORE you did the copy flip so I can check it out let me know.

If you use a bone for the root that is not the last bone in the chain (like a back bone that has arm bones but is the child of a hip bone) then make sure you use a different extension for those bones.

The script will cause an error if it finds matches to bones that aren't children of the root bone selected. For instance the arms are children of the back bone. If the leg bones have the same extension as the arms then an error will occur because the legs are not children of the back bone which was selected as the root for the flip.

p.s. It really does work and it is very easy to use... I use it all the time now.

-vern
basshole
Posts: 443
Joined: Tue Feb 12, 2008 1:11 am

Post by basshole »

I haven't even named most of my bones, only the ones I wanted to flip. Yes, I did use the underscore (so it's really _lhfab), but I DID put that in the root bone of the hand. Maybe that's what nailed me.

By the way, with this bone naming thing, do you need to name every single bone in your entire PROJECT something different, or just within each skeleton/bone layer/switch layer?For instance, can you have a "left arm" bone as many times as you want as long as it's in different characters, or should they be "left arm Jake", "left arm Sarah," etc. You can also apply this question to layer naming.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

You only need unique bone names within EACH bone layer, not the whole document.

If you are using the hand root bone as the base for the flip then don't put the extension on it. I tested it and this causes problems.

-vern
basshole
Posts: 443
Joined: Tue Feb 12, 2008 1:11 am

Post by basshole »

I think that's what went wrong before.
basshole
Posts: 443
Joined: Tue Feb 12, 2008 1:11 am

Post by basshole »

Success!

I created a faux root bone (doesn't do anything) that the real root bone is parented to, just to be able to copy/flip the real root bone along with the rest of the hand.

I had to rebind all the points to the new bones once I copied/flipped the vector layer (I like manual point binding much better than region), and will have to position the mesh correctly over the new bones, but other than that, coolz.

By the way, I thought when you copied the bones, the angle constraints were copied too (as per your notes). My new bones are unrestrained.

Ok, now I have this thing where when I put angle constraints on the new bones and try to manipulate them they. . .go nuts. Don't know how else to phrase it. They don't move in any predictable way that correlates to how I move the mouse, and they "stick" at random angles.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Don't know about the "going nuts". would have to see the file.

The copy flip bones doesn't copy angle limits. It does copy other target type constraints. I think it will copy the constraints to the same bone (if it isn't part of the flip group) and will also copy and create the constraint to a new flipped bone that is part of the flip group (it checks the name and applies the same constraint but to the bone with the flipped name).

I know my current version does this... I just can't remember if that is a new thing I added and didn't upload yet.

It also copies bone strength which is very nice.

p.s. You can also copy WITHOUT flipping. Like legs for a spider or something that repeats. It just sticks the new bones in the same spot but with new names.

-vern
basshole
Posts: 443
Joined: Tue Feb 12, 2008 1:11 am

Post by basshole »

could I maybe email you the file instead of uploading it to my site again?
basshole
Posts: 443
Joined: Tue Feb 12, 2008 1:11 am

Post by basshole »

Ok. . .I'm guessing that has something to do with the values I was putting in for the angle constraints. I thought simply reversing them from what worked on the "back hand" would work for the front hand, but looks like that's what made it go crazy. I guess if the constraints "cross each other" it goes nuts?
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Are you talking about angle limits not the angle control bone constraint correct?

Yes they are strange. If you leave the default of -70, 70 and have flipped bones... it looks the same on both sides. But only because both numbers are the same just negative or positive.

Let's say you have a bone with the following limits on the left side and it works just the way you like:

-20, 90

On the right side you need to do this:

-90, 20

Now you have a mirror image of the angle constraints.

I am going to change the code over the weekend to include angle constraints to clear up this confusion. It should be simple enough to do. It bugs me too that it isn't in there.

-vern
basshole
Posts: 443
Joined: Tue Feb 12, 2008 1:11 am

Post by basshole »

Yes, the range of movement contraints. Don't know what weird terminology I used before.
basshole
Posts: 443
Joined: Tue Feb 12, 2008 1:11 am

Post by basshole »

Ok, so, I think I've finally finally got half this character's body designed right. That's legs and arms. So my plan was to copy/flip the bones, and then I'd have his other half.

There's a few things that get me:

In the instructions for using this script, I'm not sure I understand when you say "if you have multiple sets of mirrored bones, you need a different extension for each set". How do you mean multiple sets of mirrored bones?

Also, how does this script handle switch layers? For instance, his arm has a hand switch layer bound to it. His lower leg is switch layer, so that it can both be fully extended, and bent at the knee. Will I be able to copy and flip of all this in one operation?

Thanks.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

The script only copies and flips bones. It does nothing with sub layers.

-----

There is a tiny bug I can't fix yet in this script.

The part about "multiple sets of mirrored bones" is for when you want to copy and flip only a subset of the whole skeleton or when a set of bones has a parent that isn't a single bone at the top of the stack of bones. The script is reading all the names of all the bones and if it finds any anywhere that match the extension it tries to copy them. However this is a problem if the bones don't have the exact same parent bone.

For example the arms and legs.

The arms are children of one of the back bones but the legs are children of the pelvis or hip bone. You don't want to copy and flip the back bone or the pelvis bone, there should only be ONE of those.

You actually want to select the back bone for the arms or the pelvis for the legs. You want to select the bone that is the parent of BOTH sets of arms or legs to do the flip.

So by doing the copy flip in two stages (arms then legs) you avoid that problem with the script, but you need to use a different extension like:

"_upper_lft" for the torso, "lower_lft" for the legs or lower body.

Once you do this select the back bone to flip for the arms and do the "search" just for those named bones. repeat for the legs.

For example I will have a root parent bone that is the top level of the skeleton but I don't use that bone to copy/flip. What I do is use the back bone that is the parent for the shoulders/arms.

I was planning on working on this script over the weekend but I ended up in bed for two days with the most horrible flu I've ever had. When I get back on my feet I will take a look at it and see if it can be simplified.

-vern
basshole
Posts: 443
Joined: Tue Feb 12, 2008 1:11 am

Post by basshole »

So how could I handle those sublayers? I guess I could copy and reverse the layer (if it's a switch layer), and that would take care of that? Or if I dive into the switch layer itself, and then run the script, will that also work?
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

If it is an image layer and you are just binding the layer to a bone you could just flip the layer. That's what I do.

You could also just flip the vectors and realign them. That's what I do with vector layers. In most cases the vectors are all "connected" and I just copy and flip it and connect it to the other one.

-vern
Post Reply