HeyVern's scripts and tools - (focus on bones)

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

Moderators: Víctor Paredes, Belgarath, slowtiger

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

Post by heyvern »

Yes!!!

What a coincidence!
Just today I discovered this issue with my bone groups script.

In creating the copy/flip bones script I completely disregarded switch layers. Actually I made the mistake of assuming a switch layer is also a bone layer... which it is.

In fact the code to determine a layer type will say a switch layer is a bone layer but sometimes it isn't. It is annoying because sometimes I want to check for a bone layer and NOT a switch but it gets both... so I have to check for a switch as well... and yet it sometimes doesn't recognize a switch as a bone layer type.

I will fix this ASAP (it is a piece of cake. I had to fix it today for the bone groups) and post here when it's updated.

p.s. To those who use Fazek's tools, I noticed that his bone selection tool has the same problem, it ALSO doesn't recognize switch layers as bone layers for the same reason, so I fixed my version of Fazek's bone selection tool. It will be included with the bone group tools.

I'm stuck on a new problem with bone groups... if you change the name of a bone layer with groups all the groups "vanish". I have to figure out how to check for groups with that layer and change the group layer identifier so the groups "follow along".

I get this thing working and I can do all kinds of stuff. This is the hard part.

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

Post by heyvern »

I updated the copy/flip bones and rename bones scripts in the first post. If you are to lazy too click the button ;) you can get them here:

http://www.lowrestv.com/moho_stuff/scri ... pbones.lua

http://www.lowrestv.com/moho_stuff/scri ... enamer.lua

-vern
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

One remark:
Using Fazek's replacement tools the Select Point tool, the Translate Point tool and the Rotate points tool ARE ENABLED WHEN SELECT A BONE LAYER AND MAKES THE EXPECTED JOB (they are also enabled when select a switch layer but not the Select bone tool and don't do the expected job then).
That's means that they can interact with bones in bone layers but not in switch layers. I tell you that for if it is a clue to the developing code. For some reason switch layers doesn't allow use the other tools to select/rotate/translate bones. I guess Fazek had its reasons to do that so be ware on it.

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

Post by heyvern »

Yes Genete you are right. This is however a "mistake" which is easily fixed:

Here is the original code from Fazek's select points/bone tool:

Code: Select all

function FA_SelectPoints:IsEnabled(moho)
	local ltype= moho.layer:LayerType()

	if (ltype == MOHO.LT_VECTOR or ltype == MOHO.LT_BONE) then
		return true
	end
	return false
end
Here is the simple modification that makes it work for a switch layer exactly like a bone layer:

Code: Select all

function FA_SelectPoints:IsEnabled(moho)
	local ltype= moho.layer:LayerType()

	if (ltype == MOHO.LT_VECTOR or ltype == MOHO.LT_BONE or ltype == MOHO.LT_SWITCH) then
		return true
	end
	return false
end
All I added was an extra "or" statement to cover the switch layer type.

OOPS!

I also had to make changes to fa_sharedutils.lua in the utility script folder. It is the same thing though. Where it checks for a bone layer type or vector layer type I just added in a switch layer and it works.

-vern
slice11217
Posts: 279
Joined: Thu Mar 30, 2006 6:12 pm
Location: Verona, New Jersey

Post by slice11217 »

Hey thanks for fixing that Vern!

In the interim time between writing my post and reading your response, I found a quick workaround. -Not nearly as elegant as simply using 'copy/flip bones' however, but a workaround nonetheless.

Here's what I did and I was surprised that it worked:

I created a normal bone layer above the switch layer. Then I went to the switch layer and used the old 'copy bones' script (the one that you were developing before the current 'copy/flip bones' script). Then I went to the normal bone layer and pasted the bones in. Then I used the 'copy/flip bones' script because it reliably copies and flips, then I used the old 'copy bones' to copy and paste the result back into the switch layer.

Again, not as elegant as 'copy/flip bones' and I was surprised it worked since the old 'copy bones' script wasn't too reliable, but it worked anyway.

Thanks again, now the future is easier!

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

Post by heyvern »

My "new" copy/paste bones script (when I get back to it) should be much more reliable and simple. The first one was a modification of another forum member's script. Back then I was still learning. The code was so confusing and I was sort of "copying/pasting" it to do what I wanted.

Now... good grief... my knowledge of scripting for AS isn't complete but I know so much more than I did. I can actually understand what I'm doing now pretty clearly. ;)

------

An even quicker way to do what you describe is to just create the bone layer normally and change the layer type to a switch layer in the file externally using a text editor. I use to do that all the time because some of the custom bone tools from Fazek didn't work properly with switch layer bones. Now I fixed those tools so I don't have to.

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

Post by heyvern »

Finally!

The last problem for my bone groups script has finally been solved!!!

I was using layer names to identify the bone groups. This works but has huge problems if you move the layers around in the layer palette or change the name of the layer.

Layers don't have "unique" ID's other than the name. And even with the name you can have two layers with the same name. First I fixed the duplicate layer name problem, you can't have two layers with the same name at the same "level" in the layer palette. It will change the name for you automatically.

The next problem has to do with updating the name in the bone groups list. There is absolutely no way to do it with just the name. Once the name is changed the layer can't be identified because the name in the groups list is all we've got to find it. Can't use the layer "ID" because that could change as well if the order of the layers is changed.

So I'm using the "userdata" value of the layer WHICH NEVER CHANGES. This is a value used internally by AS and stays the same through out a continuous "session" in AS (if you close and open a file all the userdata "values" change). Usually I can't do this because the userdata as string for an object changes. So I "assume" (correctly) that a file is "perfect" when it is opened or first created. I read in the table from the saved group file and put in a "fresh" reference to the userdata for that "session" of AS. I can then use that specific ID for that layer to find out if the name changed and update that in the table!!!!

Sounds very technical and it took me 3 days to figure it out. All the problems are solved now.

You can rename layers, move them around and the groups stay in sync. I almost gave up!

Won't be long now before I put up another test version.

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

Post by heyvern »

Updated the copy flip bones script in the first post. It now copies angle constraints and values.

-vern
slice11217
Posts: 279
Joined: Thu Mar 30, 2006 6:12 pm
Location: Verona, New Jersey

Post by slice11217 »

heyvern wrote:Updated the copy flip bones script in the first post. It now copies angle constraints and values.

-vern
Thanks, Vern! This script is a great asset!
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Save and load bone animation script is done!

Post by heyvern »

The heck with it! I'll sleep when I'm dead!

I just couldn't stop working on it. I did take a short nap. Now I can sleep. ;)


The first post has been updated with the new scripts and some sample files in a zip archive.

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

IMPORTANT UPDATE To Copy/flip bones!

Post by heyvern »

There was a somewhat odd issue with the copy/flip bones script that might cause some weird problems. Also the bone offsets were flipping incorrectly.

I have fixed it completely now. It is the same link you can download here.

Copy Flip Bones Script

The problem has to do with how bone rotations on frame 0 are handled differently than on other frames. On frame 0 no negative rotation values should be typed into the rotation tool input box. On frame 0 all rotations are within 0-360.

-vern
slice11217
Posts: 279
Joined: Thu Mar 30, 2006 6:12 pm
Location: Verona, New Jersey

Post by slice11217 »

Hey Vern,

So I don't know what's going on here.....

This is the second script that doesn't seem to be working for me. The first one was the pose toggle from the boneposes thread. Just a dead button in that case, but at least that one spits out a .lua error window. This one doesn't.

I'm referring to the copy/flip points script. Here's what I did: I drew my model and separated a leg out on its own layer from the rest of the drawing. Then I set up my skeleton, excluding the opposite leg (in this case, I excluded the LEFT leg). Then I named all the bones and afterward used the bone renamer script to append the names with _right, except for, of course, the pelvis bone since it resides in the center of the skeleton. Then I ran the copy/flip bones script, which works beautifully, nice work Vern. Next I duplicated the leg layer, selected all the points, and pushed the copy/flip points script. Voila -nada.

On subsequent tries I went in and made names for bones that aren't even involved in the leg area, still nothing. I also tried assigning a _left or a _right naming structure to the bones along the center axis, such as the chest or the neck, etc. -I figured that I could just as easily remove the suffix later on if needed.

I'm wondering since this is the second script that isn't working, is there a new version of .lua or python or whatever that recently came out?

I'm actually hoping more that it's something that I'm doing wrong. I also tried to reproduce the problem on my computer at work and unfortunately I was able to.

Thanks,
S
slice11217
Posts: 279
Joined: Thu Mar 30, 2006 6:12 pm
Location: Verona, New Jersey

Post by slice11217 »

-Oh, I forgot to mention:
when I ran the copy/flip bones script I changed all the _right names to _left.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

EDIT: The "flip" points script doesn't "copy" it just flips the points and flips the bound bones to match the opposite side.

The flip bound points script must have a set of identically named bones with opposite names _right and _left.

Bone 6_left
Bone 6_right

forearm_left
Forearm_right

The vector layer to duplicate should have the points bound to one or the other side of the opposite bones. (If no bones are bound it just flips like a normal flip.) You can even mix and match. A point bound to a left bone or a right bone as long as there is a MATCHING bone with the EXACT NAME except for the extension.

If the bones do not have the EXACT name + extension it won't work. The extension must be _left and _right.

Other than that... I can't say for sure. I just tested it on a new project and it works. I tried a bunch of times and it works.

Are you actually clicking on a bone in the flipped vector layer to determine if the vectors were bound to the opposite bones? For instance if a point is bound to "thigh_left" and you use my flip points script that point should now be bound to "thigh_right". If there was no "thigh_right" it probably won't do anything.

If you can post the project I can look at it to see what the problem might be.

-vern
slice11217
Posts: 279
Joined: Thu Mar 30, 2006 6:12 pm
Location: Verona, New Jersey

Post by slice11217 »

Yeah... hmm...

I pretty much did exactly what you say... I even tried out the 'moving the bones on the opposite leg' thing like you mention but to no avail.

That's why I'm wondering if there's a new version of the code out there or something. I'll try repairing permissions on my computer, maybe that will help, you never know. I'm using Mac's Tiger OS on an old G4, and I'm using a G5 at work. Any thoughts?
Post Reply