Anime Studio Pro and lua scripted physics?

I am NOT a programmer. I know very little about physics math, I basically have no clue. I am however very skilled with "cut and paste" and "search and replace" 😉. I use a 2D animation program called Anime Studio Pro that has a pretty darn good lua scripting back end. I recently started to add in some physics functionality by "porting" to lua some action script physics code I found on the internet. Here are my "exciting" results (Hey! They thrilled me beyond belief!):

http://www.lowrestv.com/moho_stuff/scripts/gravity_collision_detection.mov
http://www.lowrestv.com/moho_stuff/scripts/physics1.mov
http://www.lowrestv.com/moho_stuff/scripts/angle_bounce1.mov
http://www.lowrestv.com/moho_stuff/scripts/springs1.mov

I want to add more features and make it better... I don't know if Box2D is the solution or if it would even be usable in Anime Studio (scripts are linked as text files, no "compiling" of lua scripts). The program itself already has "bones" which is what I use for the physical "objects". I use the bone length as the "radius" for collision detection. It also has drawn vector "layers" similar in some ways to Flash that can be bound to the bones. This means that joints and bone hierarchies are "built in". I would like to add in the "vector" aspect for irregular shaped object physics. That was what I was working on when I found Box2D. I know also that the BEST solution would be for the developers to add a physics engine to the application, but I don't see this happening anytime soon.

I was actually thinking of "porting" the "Flash port" to Lua but... yikes... that might just be too crazy (Flash is "upside down" and rotates "backwards" unless they "fixed" that recently).

I plan to keep going on my own with what I have but would love... a shortcut. 😉 I did search here for Lua and came up with only one topic that mentions it as it an unrelated issue. Like I said... I'm not a programmer in real life... I pretend to be one... like a kid wearing a towel around his neck pretending to be superman. 😉

Any advice appreciated. You can also make fun of me and poke me with sticks it you like. That's always fun.

-vern
Quote:
I was actually thinking of "porting" the "Flash port" to Lua but... yikes... that might just be too crazy (Flash is "upside down" and rotates "backwards" unless they "fixed" that recently).

I'd warn you against trying, especially if you're not "really" a programmer - if I recall, Lua doesn't even have classes, and it's very syntactically different from Flash. That means that pretty much every line of code needs to be actually rewritten, and a lot of the structure might even have to be reworked. It's tough enough to port from C++ to AS3 or Java, and those languages are all very similar in structure and style.

My suggestion would be to see if you can use SWIG to create bindings for the C++ Box2d code so you can use them from Lua. I'm not sure if this is possible or not, though, and swig.org is down at the moment so I can't check...
Quote:
if I recall, Lua doesn't even have classes, and it's very syntactically different from Flash. That means that pretty much every line of code needs to be actually rewritten, and a lot of the structure might even have to be reworked.


Yes I noticed that but I found the code to be very similar. I use Jedit and I created a bunch of regex snippets that do a pretty darn good job. I can get about 90% there without doing any manual editing. I even have one that "switches" around "for loops". The samples above were done by straight conversion of "one frame" action scripts. The hardest part was flipping the world space (why IS Flash upside down dagnabbit? Someone should be spanked for that decision years ago).

I am very limited with what can be "linked" to the Lua functionality in Anime Studio. No external linkage to libraries or anything like that. Everything has to be in the embedded script based on the version of Lua compiled with the application. There are even some math functions I don't have because of the older version of Lua compiled in the app. I can use what is called a "utility script" that is loaded when the application launches. I can put all kinds of functions in there that are only used as needed by a separate script embedded in a layer to move the objects around. This simplifies it a lot.

Yes, no "classes" in Lua but you can sort of "fake it" using metatables. I haven't played around with it much yet so I don't know how difficult it would be to "convert" the code. If only I were 10 years younger... my brain is just too old and crusty. I have to delete Love Boat and Dukes of Hazard reruns in my head to learn anything new. I deleted Fantasy Island and Lavern and Shirley to learn Lua, but they're out on DVD now I think. 😉

-vern
A Lua version seems ambitious, though it isn't missing anything massive that Box2dAS3 uses, as far as I can tell.

Is it possible to export the animated stuff from Anime Studio to some readable vector format? It seems like it would be easier to to export the physics set up, simulate it in one of the existing versions of Box2d, recording object positions at each time step, and then import that data into Anime Studio. You presumably don't need real time behaviour for your physics.

I would warn against using bones and vector shapes to describe a physics problem anyway, no matter how nice the Anime Studio IDE is. The moment you get it working using that, you'll just feel annoyed that there is no way to control mass, friction and restitution properly, you'll only be able to describe the shape.
My goal is to have physics as a tool in Anime Studio with a simple user interface. Yes, real time playback is needed (it works in examples so far). A character would throw an object, or knock over objects etc. Need the real time feed back to incorporate physics into the animation.

I also plan to have a pop up window that will allow the user to define the physical properties of "bones" in the program. In my previous example I am using bone length to determine the mass or weight of an object. Restitution and gravity would be settable properties.

The reason Box2D is so intriguing is that it is "2D" and it's right along the lines of what I was doing anyway... but... all the work is done. I won't get anything out of this but the joy of it and the congratulatory slaps on the back over at the Anime Studio forum... so whatever can make that easier I am all for it. I guess now I should just bite the bullet, download the source and take a look at it. If my eyes roll into the back of my head and I pass out... I'll know I need to find a simpler solution. 😉

-vern
heyvern wrote:
(Flash is "upside down" and rotates "backwards" unless they "fixed" that recently).

I didn't actually change anything from the c++ version, if you need to use a +y up world, just use a negative y value in the gravity vector.

I've never used Anime Studio Pro, or even Lua, so I don't really know how feasible this is, but best of luck none the less.
Flash, the program itself was designed "wrong" from the very beginning. The 0 point is top left and DOWN goes UP, and it rotates backwards, clockwise is positive. Minor complaints but it is silly.

-vern
Quote:
The 0 point is top left and DOWN goes UP, and it rotates backwards, clockwise is positive.

This is veering off topic, but this behavior is actually quite consistent with most windowing systems - Windows, for one, has always defined the origin of a window to be the upper left. I assume this is because monitors tend to start their scans at the upper left, and as they go along it's best to read all the memory sequentially rather than jumping around or backtracking.

If you just route your drawing calls through a handler, you can deal with zooms, rotations, and translations as well as this upside-down issue, which I think is worthwhile in most cases.
Quote:
this behavior is actually quite consistent with most windowing systems - Windows, for one, has always defined the origin of a window to be the upper left.


Yes quite true... unfortunately no one told the mathematicians. 😉 When I was researching physics math all of the equations and grids were based on 0 at the center, up to the right is positive and counter clockwise rotations are positive. That is how Anime Studio is set up. I did end up putting the "flipping around" stuff in a separate function. All the blood rushing to my head was giving me headaches and it's hard to use the computer in that position. 😉

-vern

Original thread: https://box2d.org/forum/viewtopic.php?t=371