Scripted "line font" for use with LM_Graphics Draw

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: 7042
Joined: Fri Sep 02, 2005 4:49 am

Scripted "line font" for use with LM_Graphics Draw

Post by heyvern »

I have been searching for something "already done" for "drawing" text based on connecting points in a grid but just haven't found anything.

I think this will work but I need to test it out and was hoping I could "steal" some code from something else.

I have sort of "hand coded" some vector letters using the LM_Graphics DrawLine function. My thought would be to store a sort of "letter template" in an external utility script that would convert strings to vector text that can be drawn on the screen when a specific tool or layer script is used.

This would allow for labeling "widgets" and bones etc without having to use images or text. Anyone know of any resources that might have very simple vector descriptions of drawing text like this?

In the meantime I am going to try and create my own. I drew a very simple alphabet on a grid. I can divide the grid and create simple point locations to connect lines for each letter. Each letter uses a 6 x 10 grid. The point locations would be within the "undefined" grid size associated with variables so they could be scalable and can be placed anywhere on the screen. Using matrix transforms the text could even rotate to follow a bone for example. Have to see about that one. ;)

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

Post by Genete »

Currently there is an internal code that does that based on ttf fonts: Draw->Text.
I'm sure that the code that convert a string into a set of draw and points set is already done. I think that you could ask directly to LM to open the source code of this feature to the users because finally use the tff fonts file information is the straightforward way to perform that kind of task.

Anyway, if you continue thinking to do it "by hand" you could try to understand how the ttf files are written and extract the information from there. But I guess it is so hard...

http://en.wikipedia.org/wiki/TrueType

Best wishes.
-G
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Well I sort of already have it working pretty well with my own hand drawn font.

Keep in mind I don't need actual "fonts" just simple UI text as labels. If they open this up it would be fantastic though.

It wasn't as hard as I expected. I drew the letters on a grid and then just wrote down the coordinates for each "line" based on this 6 x 10 grid. Each letter or number only has 3 to 5 lines. I am creating a utility script that parses a string file sent to it and then returns the coordinates for each letter in a table which are drawn to the screen using a loop.

It works just like I hoped so far. I can change the "font size" by just changing the value of a variable which is multiplied times the "grid" coordinate values. I am only testing so far with a few letters but it works great! Finally I can "label" the bones for my scripts!

After I get the text writing function working I plan to figure out how to "rotate" the text. This will allow me to align it with a bone.

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

Post by heyvern »

IT WORKS! IT REALLY WORKS!!! YEEEEEHAAAAA!!!!

This is going to be great. I even got the text to "stick" to a bone and follow it around!!!

Finally I can produce text for all my bone widgets and controls!!! I love this! It was so darn easy. Good grief I can even "draw" sliders and controls that might not even have to have bones to work!! You can grab and move "objects" drawn with the LM_Graphics functions that do things as if they were bones or whatever.

Also it is FAST! My big concern was how much resources it would take to draw the text but it works great. Since it works so well I plan to clean up the font and make it look a little better. I may even stick in some custom tracking on some of the letters and add lower and upper case and more punctuation.

Imagine linking this to a script so you could create documented files!!! This is cool. I could even add in "auto arrows" that could point to elements on the screen like bones with out having to draw anything! You could even animate the text, have it change on different frames. I think this will be GREAT for doing "live" tutorials. Just move to different frames like "slides". Or have the file give a response if the user did the right thing.

I will start a new thread for this one when I get it worked out. I have the whole text functions in a separate script.

Here is a sample screen grab from my bone mirroring test file. Forgive my... vanity. I had a really really horrible job interview at an Apple store (they said they absolutely hated me and I talked too much) and this boosts my ego. ;)

Image

-vern
User avatar
jahnocli
Posts: 3471
Joined: Fri Oct 29, 2004 2:13 pm
Location: UK

Post by jahnocli »

Vern - talking too much is only a problem if you have nothing to say...
You can't have everything. Where would you put it?
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Post by Genete »

Congratulations! It looks so well. Please document it when publish! This would be a crack!
:D

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

Post by heyvern »

Thanks guys!

This is great. I can link the point size of the font to the length or scale of the bone so it changes relative to the length of the bone.

I just redid the font so it has a better look. It just came to me that I can do a script now for colorizing bones!

I need to figure out a way to incorporate bone colors into the file... probably have to be an external file though.

I swear this is like getting a new version of ASP with new features!

-vern
User avatar
jahnocli
Posts: 3471
Joined: Fri Oct 29, 2004 2:13 pm
Location: UK

Post by jahnocli »

Colorized bones would be great!
You can't have everything. Where would you put it?
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

Hey this is cool.

I turned on "smoothing" which antialiases the "text" or any drawing you do.

It looks beautiful.

Image

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

Post by heyvern »

Sorry to keep posting on this...

I linked the text to show the frame number really big in the window! This is cool as heck! No more wondering what frame you are on or squinting at the tiny box.

I think I can link this to DAT files so you can see and update text for lip syncing! Imagine if the text of your dialog displayed as you scrubbed through the animation?!

This is really fun.

-vern
User avatar
jahnocli
Posts: 3471
Joined: Fri Oct 29, 2004 2:13 pm
Location: UK

Post by jahnocli »

Don't apologise! You are scorching the earth with this! E-frontier should make you an offer...
You can't have everything. Where would you put it?
Ovjeh
Posts: 26
Joined: Tue Nov 07, 2006 11:53 pm

Post by Ovjeh »

:D
Bone coloring is one of my top priority wishes for Moho/AS.

Possibility to color bones of different body parts and/or
different characters would improve rigging and animation
workflow significantly.
User avatar
heyvern
Posts: 7042
Joined: Fri Sep 02, 2005 4:49 am

Post by heyvern »

I just don't have complete grasp of the whole scripting aspect but it is coming slowly.

Some of my excitement is a bit subdued now. There doesn't seem to be a way to "draw" in this way using a layer script.

If anyone knows otherwise I would like to hear it.

From what I can tell the LM_view is only available to tools. I will keep plugging away just in case.

It's not the end of the world for most things and I suppose I could add code to the tools to enable text feedback but it would be nice if I could draw to the view with any type of script.

-vern
Post Reply