Colorize bones - coming soon! Yeehaaa!

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

Colorize bones - coming soon! Yeehaaa!

Post by heyvern »

Well I think I pulled it off! Bone coloring!

I will post the final scripts and instructions when I get this done. This is a test. It works GREAT. And it is fast. It will have the option for stroke wieght and transparency etc etc.

I still need to work out exactly how this will work in AS. I was thinking of using an extension in the bone names to determine the color. But I may use an external preference file but that is going to take a bit more work.

Each AS file would have to have some way of saving a preference file for bone colors... uh... somehow... probably a menu script. So you would run a menu script and put bones in "groups" with a color. This file gets saved into the same directory as the AS file. A utility script would run when the file is opened and "recolor" the bones.

The other problem is pretty big... you will need new tools or at least all new bone tools in order to see the coloring. There is no way to draw on the screen with anything but a tool. I would just stick the code in copies of Fazek's scripts since those are my favorites anyway. Fazek's tools are great.

Maybe efrontier can include this code in the application down the road... or maybe they will add the bone coloring to the application... who knows.

(click image for larger view)
Image

-vern
User avatar
AngryMonster
Posts: 95
Joined: Sun Apr 22, 2007 1:42 am
Location: Australia
Contact:

Post by AngryMonster »

awesome.
Ovjeh
Posts: 26
Joined: Tue Nov 07, 2006 11:53 pm

Post by Ovjeh »

Great, absolutely great.

Transparency, Line weight - will there be option to specify line color for each bone ?
Nothing urgent, just asking.

The another thing that would be realy useful is bone reshaping, or to redraw default bones with custom-shaped ones created with script.
Is this possible at all?
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

The another thing that would be realy useful is bone reshaping, or to redraw default bones with custom-shaped ones created with script.
Is this possible at all?
Yes! The only problem of course is that the custom bone shape would still have to fit the general area of the bone. My dream is to be able to have construction curves turned off and only a few bones "visible". Cut down on clutter.

Keep in mind one important thing; this script doesn't actually change the bones shapes or appearence. This is a UI change ON TOP of what the application is doing. I am merely drawing a color "shape" on top of the bone. So for custom shapes, the actual bone shape is still there.

A side note on this. Since I have to create "groups" of bones for the coloring I've decided to expand this concept to a bone group "tool" or menu script. If you read my description of colorizing the bones... it sounds exactly like creating bone GROUPS. It's the exact same thing. So if you can group bones for color why not just have the color represent a bone group. This would lead to a "tool" that you use to select some bones, name the group, pick a color. I could also have a check box for VISIBILITY. You could turn bones "on and off". You could select bone groups by pulling down from a menu just like point groups.

I'm really excited about this.

I still plan to do the basic colorizing first though. And I also have to figure out how to deal with deleting bones if I am using some type of preference file.

-vern
Ovjeh
Posts: 26
Joined: Tue Nov 07, 2006 11:53 pm

Post by Ovjeh »

Keep in mind one important thing; this script doesn't actually change the bones shapes or appearence. This is a UI change ON TOP of what the application is doing. I am merely drawing a color "shape" on top of the bone. So for custom shapes, the actual bone shape is still there.
Yes, I expected that, it's ok as long the underlying bone is not visible. My dream is similar, just crucial bones visible, masked with custom shapes for easier picking and manipulation.

A side note on this. Since I have to create "groups" of bones for the coloring I've decided to expand this concept to a bone group "tool" or menu script. If you read my description of colorizing the bones... it sounds exactly like creating bone GROUPS. It's the exact same thing. So if you can group bones for color why not just have the color represent a bone group. This would lead to a "tool" that you use to select some bones, name the group, pick a color. I could also have a check box for VISIBILITY. You could turn bones "on and off". You could select bone groups by pulling down from a menu just like point groups.
All good stuff, especially bone hiding.
Last edited by Ovjeh on Thu Nov 15, 2007 3:10 pm, edited 1 time in total.
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

There is another possible benefit. I am not 100% sure this will work I have to test it but I might be able to disable bone selection for bone groups that are "hidden". Right now this is a pain in the arse. If you have certain bones not visible they can still be selected and moved.

The tool script can check if you click on a custom shape. I could ignore bone selection from AS and only select and move bones based on the bone group tool additions.

I think this IS possible. I'm almost sure of it.

There is one tiny problem and I'm still tweaking the code to fix it. The script has to check through the whole bone list each time you do anything on screen which makes it a tiny bit slower than the "normal" bone tools for manipulation. I am hoping once I get the code set up to create the smaller "group" lists it won't be an issue.

Instead of searching the whole bone list it would target the groups.

I have a "prototype" with a color section box and group naiming box. I added a check box for hiding the group and/or hiding all of the coloring.

It's fun just changing the colors on the bones. So cool. It is also really really really cool to have SOLID filled bone shapes. Makes a HUGE difference.

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

Post by heyvern »

This is great!

I don't have a prototype yet but it's coming along. I can turn off a bone groups ability to be "selected".

For example if you have a bone group set to be "hidden" none of those bones can be selected!! This is fantastic!

This bone group tool is my holy grail of bone tools. I am getting excited. Now I can finally hide all my control bone rigs and never select them by accident.

To speed things up I turned of antialiasing of the bone shapes. That makes some difference.

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

Post by heyvern »

Dagnabbit!!! ARRRRRGGGGGHHHHH!!

I was almost ready with this script set. Now I've hit a wall. It works fine unless you use the undo. If you undo then the script causes AS to crash or the script to act strangely. I have no idea why and I am struggling to track it down.

Any scripters out there who know exactly what the "undo" command does? Would it undo table creation in a script? Why would it cause tables to completely change bone ID's?

I have a table with the list of bone groups and bones. Sometimes undoing will cause all the bone IDs to change to other bones. The weirdest part is that undoing can't be "redrawn". I would expect even if the script was broken by an undo causing a redraw would fix it?

I will keep at it. It is working perfectly... but no undo... for any tool.

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

Post by Genete »

Did you put the "Set dirty" thing on your scripts?

Code: Select all

moho.document:PrepUndo(moho.layer:Parent())
moho.document:SetDirty()
-G
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I tried it with and without setting the "prepundo" with the same results.

The bone group tool creates a global variable table/array that includes the names of the groups and the bones for each group.

If you undo, this table is completely butchered. All the references to the bones are either changed to random bones or no bones at all. The variable still exists but the groups point to the wrong bones.

Sometimes with two groups the groups will actually switch names! Sometimes all the bone names are lost from the table or changed so that the bones remain highlighted in my script display but there are no bones selected. This is really strange because bone color highlighting is based on the fSelected of the bones in the group.

I think this is going to take some time to figure out. The problem is I don't know what happens when the undo command is used. What is going on "behind the scenes" in AS. It seems that undoing does mess up or "revert" global table variables somehow. I could easily fix that if there were some way to "trap" or check for an undo but there isn't.

It also might have to do with too many things trying to happen all at once. When an undo it used the tool functions, updatewidgets and drawme, are run. When the script runs "normally" those things happen in a specific order and everything is fine. If they run out of sequence all kinds of badness could happen especially if AS is selecting and deselecting bones in the process.

I may have to create a simple tiny script just to test the undo on global variables.


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

Post by heyvern »

Well... it appears to be user error... which is very good news! ;)

I have to make sure my table is created and accessed properly. I was using the name of the group as the index but I think this is causing the trouble during the redraw. I think I am iterating the table differently in different places due to a non sequential and non numeric index. I need to keep the table ordered consistently and without gaps and only loop through it based on the exact order.

Also if an undo doesn't crash AS and I redo and undo, it changes back and forth. The correct state is still there in the undo buffer. So there IS an undo issue that is causing the problem. It seems that I have "undo's" in wrong places. For instance moving a bone sets a prepundo. I think I have CONFLICTING undo states in the script. So an undo does a bunch of weird things.

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

Post by heyvern »

Well, I have not solved my "undo" problem for now. So I decided to move on in hopes that the reading and saving of the bone groups preference file will help solve this.

Yeeehaaaa!

I found a very cool snippet of lua code on the internet that perfectly saves and loads tables as text files. It is really fantastic. I finally got past the one thing that I never tried before... reading and writing to external text files using a script in AS.

I am able to grab the path of the open file and save the complete list of bone colors and groups and load it back in.

Now on to fixing that stupid "undo" problem. That is so... dang annoying.

-vern
Samb
Posts: 84
Joined: Thu Dec 29, 2005 5:18 am
Location: Hamburg,Germany
Contact:

Post by Samb »

well, big thanks to you heyvern!
colored bones would be awesome and extreme useful!

oh, and I really know those programming problems.. sometimes it's so frustrating.. especially when it turn out too be a absolut stupid bug,like one wrong number or small logic issue, in the end :D
User avatar
heyvern
Posts: 7035
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

YAAAAAAAAHOOOOOOOOOOO!!!!!

I solved it baby!!!!!! WOOOOHOOOOOOOOO!!!!!!!!!

Most of you won't have a clue why this didn't work... I don't even know why... but just in case someone has this same problem here is what the problem was and the solution.

I was putting "bones", the userdata as references in the table. the problem is that userdata info "changes". This is just a guess really but it makes sense.

I changed the table info to store the actual bone ID number. A number only that NEVER CHANGES. A bone's ID number is always it's number in the list of bones. Once I did that the undo worked again!!!! The undo was obviously changing the bones userdata reference to the bone.

You know how I found this out? In order to write the table to a file on the drive I had to change to bone ID's because you can't write userdata like a bone reference. It has no meaning when read back in. So what the heck big deal I just change the code so it uses the ID number.

All of a sudden the stupid undo started to work!!!! I should have done this a couple of days ago.

I am so happy.... I could cry.

I promise to have this thing ready in a day or two. You guys will love it!!! It works so well.

To save time and get the ball rolling I will create a special tool that rotates and translates bones and also creates groups. This will be a "test" tool so I don't have to rewrite all the tools. You will get an idea on how this could work without having to make a ton of changes to your tools. Later if you like how it works and when I finish updating all the tools you could replace them and use them as usual.

I have a question though. Is bone coloring needed when using the vector or layer tools? this would save a lot of effort. I would have to rewrite those tools as well in order to show bone coloring. My thought would be that bne coloring would only be needed when using bones... but that's just me.

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

Post by heyvern »

Here's a video of the color bones script working:

http://www.lowrestv.com/moho_stuff/scri ... colors.mov

I still have to add a few things like turning of individual groups and excluding non grouped bone selection.

-vern
Post Reply