Bitmap drawing tool test

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

Moderators: Víctor Paredes, Belgarath, slowtiger

ponysmasher
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles
Contact:

Bitmap drawing tool test

Post by ponysmasher »

On Animators Forum I recently gained access to the VIP Scripting forum (around 50 posts needed) and in one of the threads Synthsin and Rudiger were talking about how you can use external .dll files to extend the scripting capabilities of Anime Studio.
This sounded very interesting and I've been playing around with two external bindings, Lua GD for creating and manipulating images, and Lua FileSystem for extending the file manipulation.

With these two Lua bindings I've written a tool for making bitmap drawings directly in AS.
Here's an image drawn in Anime Studio:
Image

Now this is just a test and not a finished tool so it's pretty limited.

What it can do:

- Create png image layers of custom size.
Image
A folder named 'images' will be created in the same folder as your .anme file. The PNG will be transparent and named "image" + the number of files in the directory.

- Draw on any image layer containing a png image.
Pencil size is set in Anime Studios style window under stroke width.
Pen pressure is supported when using a tablet.
Image

- Erase by holding SHIFT. Eraser size is the same as pen width.

- Fill color by holding ALT

What it can't do (among other things):

- Antialiasing. This is posible with the GD library though, but filling antialiased shapes might look bad.

- Speedy drawing on high resolution images. Every time you draw something the PNG file will be saved and loaded back into Anime Studio so the bigger the file the more lag there will be after drawing something.

- Undo. The image is saved right away but one idea I had is creating a copy of the image before any changes. That would give you at least one level of undo but it might introduce more lag.


As previously stated, this is basically just a test but if you want to play around with it or look at the code, here it is:
http://animestudioscripts.com/temp/raster/ds_raster.zip
Unzip it in your Anime Studio folder and things should work.
To uninstall all the files installed, double click "uninstall_ds_raster.bat". It will even remove itself after removing the files so you will have no trace of the tool or the .dll files.

EDIT: This will only work on Windows using Anime Studio Pro 8.

EDIT AGAIN: Tried it on Anime Studio 7 and it works there too. Didn't think it would update the image layer but it did.
User avatar
funksmaname
Posts: 3174
Joined: Tue May 29, 2007 11:31 am
Location: New Zealand

Post by funksmaname »

this is interesting :)
I wonder if it could take on some functionality from Ramon's lost pencil tool - the actual drawing tools are clearly superior.

I will grab and play with it when I have time!
User avatar
Víctor Paredes
Site Admin
Posts: 5646
Joined: Wed Jan 26, 2005 12:18 am
Location: Barcelona/Chile
Contact:

Post by Víctor Paredes »

It's an awesome advance! thank you very much, Ponysmasher. Great, really great.

I have a problem when creating new images. It creates at the project resolution (960x540), but it is not centered and have a black space on the right and down sides.
Image

I have three questions:
- This dll thing have been around since what version?
- Can you give us an idea about what could be done now with that?
- Is there any chance yo have this tool working as a frame by frame tool? (maybe it could create automatically a switch and new keys for new images and you could edit each image over the switch layer on its respective keyframe, that would be fantastic)

:D
Image Image Image Image
Moho Product Manager

www.mohoanimation.com
Rigged animation supervisor in My father's dragon - Lead Moho artist in Wolfwalkers - Cartoon Saloon - My personal Youtube Channel
Rudiger
Posts: 786
Joined: Sun Dec 18, 2005 2:25 am

Post by Rudiger »

Wow, great job Ponysmasher! Using the GD library to add bitmap drawing to AS has been on my todo list for a while now, so I'm grateful to be able to cross it off without having to write a single line of code!

I hope you can add anti-aliasing as an option. It would be great when you just want to paint and have no need for the fill tool.

I also like Selgin's idea of making it work with switch layers. Could make it awesome for storyboarding.

To answer Selgin's question, it has been possible to import dlls with AS, since at least AS6, and quite possibly in AS5 or even Moho. I suspect it became possible when Mike first made all Lua functions available to the scripting interface. However, I don't think it is supported for Macs under any version. Not sure if this is a limitation with the OS or what, but I've submitted a request to Smith Micro to add support for this feature to the Mac version.

Actually, Ponysmasher, you might want to mention that this tool will only work under Windows, to save people the trouble with trying to get it to work on a Mac.
User avatar
ulrik
Posts: 1087
Joined: Thu Aug 11, 2005 10:32 pm
Location: Stockholm Sweden
Contact:

Post by ulrik »

Fantastic work Ponysmasher! :D
I know this will not work on mac, do you have any plans for making it work on mac?
ponysmasher
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles
Contact:

Post by ponysmasher »

selgin wrote:I have a problem when creating new images. It creates at the project resolution (960x540), but it is not centered and have a black space on the right and down sides.
Oops. Fixed it and uploaded to the same link.
selgin wrote:- Can you give us an idea about what could be done now with that?
I'm not really sure, I've just started playing around with this. But it seems exciting.
selgin wrote:- Is there any chance yo have this tool working as a frame by frame tool? (maybe it could create automatically a switch and new keys for new images and you could edit each image over the switch layer on its respective keyframe, that would be fantastic)
This is something I would like to do. I'll experiment some more.
Rudiger wrote:Wow, great job Ponysmasher!
Thanks! You're the inspiration.
ulrik wrote:Fantastic work Ponysmasher! :D
I know this will not work on mac, do you have any plans for making it work on mac?
I hardly know how it works on a PC and I don't have a mac so I'm afraid it's beyond my abilities.
Rudiger
Posts: 786
Joined: Sun Dec 18, 2005 2:25 am

Post by Rudiger »

ponysmasher wrote:
selgin wrote:- Can you give us an idea about what could be done now with that?
I'm not really sure, I've just started playing around with this. But it seems exciting.
Hehe, actually I think a more fitting question would be what can't be done! Synthsin has used this technique to create a rather nifty native color picker that can get the color from anywhere on the screen. It's only available in the VIP scripting area of the Animators Forum though.

Basically, it means that any c-library with Lua bindings can be accessed from inside AS. For example, if you could find a boolean operations library, you could integrate that into AS and have it support boolean operations on its shapes.

You could even use it the other way and use it to treat AS as a plugin for another application.

You can also write your own dlls in c. This is useful for accessing OS-level stuff that the AS scripting interface doesn't give you direct access to, which is what Synthsin did with his native color picker tool.
ponysmasher wrote:
ulrik wrote:Fantastic work Ponysmasher! :D
I know this will not work on mac, do you have any plans for making it work on mac?
I hardly know how it works on a PC and I don't have a mac so I'm afraid it's beyond my abilities.
I think the only way you could currently make it work on a Mac is if you wrote a command-line program that uses the GD library and then execute it from AS using the os.execute() function. Not sure how much more laggy this approach would make it though.
Last edited by Rudiger on Fri Aug 12, 2011 5:26 pm, edited 1 time in total.
F.M.
Posts: 497
Joined: Thu Nov 04, 2004 4:29 pm
Location: Between my ears

Post by F.M. »

This sounds very interesting, hope to hear more about your experiments!
"and then Man created god!"
User avatar
GCharb
Posts: 2202
Joined: Mon Oct 10, 2005 2:31 am
Location: Saint-Donat, Quebec, Canada
Contact:

Post by GCharb »

Works well under asp 6.2, fun stuff, thanks!
User avatar
GCharb
Posts: 2202
Joined: Mon Oct 10, 2005 2:31 am
Location: Saint-Donat, Quebec, Canada
Contact:

Post by GCharb »

Takes a little getting used to but it's working.

Image
JaMike
Posts: 357
Joined: Sat Jul 16, 2011 6:36 pm

Post by JaMike »

This extra LUA stuff sounds great - what other LUA plugins are there that could be used? Has anyone got a list of them? I did a search but didn't really understand what I was looking at.
User avatar
neeters_guy
Posts: 1614
Joined: Mon Sep 14, 2009 7:33 pm
Contact:

Post by neeters_guy »

Yes, this is quite remarkable. The pressure sensitivity doesn't seem to work for me, but it's remarkable nonetheless. Looking forward to see what you do with this.

Edit: Pressure sensitivity works now. Plug in tablet BEFORE launching AS. Duh. :oops:
Rudiger
Posts: 786
Joined: Sun Dec 18, 2005 2:25 am

Post by Rudiger »

JaMike wrote:This extra LUA stuff sounds great - what other LUA plugins are there that could be used? Has anyone got a list of them? I did a search but didn't really understand what I was looking at.
There's a pretty comprehensive list of add-ons for Lua here:
http://lua-users.org/wiki/LibrariesAndBindings

One idea that comes to mind is you could possibly combine one of the image manipulation libraries with one of the GUI libraries to create a full node-based compositor for AS.

I'm sure there's some interesting things that could be done with the 3D libraries as well.
Rudiger
Posts: 786
Joined: Sun Dec 18, 2005 2:25 am

Post by Rudiger »

I had a proper play with it, and it works really great. The default settings for the size of a new image seem to be fixed though. I would have thought you would want it to default to the project size and you then have the option to fiddle with it if you want to.

I also noticed an issue with the origin being redrawn with the same brush size that was used to draw the last line. It might be an idea to set the pen width back to 0 on MouseUp.

Another thing is the width of the bitmap stroke seems quite a bit smaller than the preview stroke, especially for large widths.

Also, I had an idea for how you could support onion skinning inside a switch layer. When onion-skinning is enabled you could still write the stroke to the current image but automatically blend the previous image with the current image when you do the update. It might add a bit to the lag, but you could always keep turning onion skinning on and off with a shortcut key to see how your current image looks compared to the previous one.

I also noticed that you are using a specific color to represent transparency in the image. I think the GD library supports using a separate alpha channel if you use the imagesaveslpha function. That way, you could just use the fill and line colors in the style window and support painting with variable transparency.

EDIT: I think I solved the brush size problem. Instead of calculating the width to put in the table as:

Code: Select all

moho:NewShapeLineWidth()*self.newY
I think it should be:

Code: Select all

moho:DocToPixel(moho:NewShapeLineWidth())
ponysmasher
Posts: 370
Joined: Thu Aug 05, 2004 2:23 am
Location: Los Angeles
Contact:

Post by ponysmasher »

Thanks for looking through the code Rudiger!
There is a lot to be done for sure. I was having a bit of trouble with the transparency and the way I do it now, with a color as transparent, is especially not good when you turn on antialiasing since that color will shine through the antialiased pixels.
But I will read up on it more, just have to catch up with work first.
Post Reply