2D Blender animation tests

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact:

Re: 2D Blender animation tests

Post by verilog » Fri Jul 05, 2013 10:37 pm

twobit wrote:
I can't run the love file, there appears to be something faulty in main.lua, line 18.
This should be fixed now.

When importing FBX all skeletal information is discarded. I only care for polygon data and object transformations.

A well-adapted custom blender exporter would be ideal! Has anybody of you experience with this?
That's looking good, twobit. I was thinking about using bone information (both skeletal description and transformations) instead of polygons. Again, I was merely toying with the idea, I never actually implemented anything. I've attached Spine's löve demo that can be downloaded from the official site, it is quite good.

From what I understand, this implementation uses skeletal data described as a JSON file (generated from Spine itself) and a series of images to be attached to the bones, check it out, it is pretty cool and may be useful.
Attachments
spineDemo.love
spine demo
(148.39 KiB) Downloaded 112 times

spectralcanine
Citizen
Posts: 65
Joined: Sat Dec 22, 2012 8:17 am

Re: 2D Blender animation tests

Post by spectralcanine » Fri Jul 05, 2013 11:34 pm

Implementing skeletal animation is very easy.
You form a hierarchy of nodes (which are usually bones, but more things can be used, e.g. particle emitters, light sources, attachment points, etc.), and then you follow it recursively each time you want to update.
For each node you get its local space matrix transformation, and if it has a parent, you multiply the local space matrix with the parent's world space matrix to form this node's world space matrix (if there is no parent, the local and world matrices are equal).

It might sound a little complicated if you never touched matrices, but it's very simple.

The hard part is actually getting the animation data. Since most games tend to have different needs, they also tend to make their own formats. File formats are one of those fields where reinventing the wheel is very common.

For example, do you want only sprite sheet animations, or also skeletal animations. Do you want bounding shapes for collisions, or not. Do you want to be able to change images dynamically while animating, or not. How do you sort the nodes into layers (only relevant to 2D). Can you run multiple animations with blending or not? Do you want to support dynamic animations or not? (and if so, are you going to implement IK, or is FK enough?).
The list can go on endlessly, and it really all depends on the game.

I don't support formats that try to satisfy everyone by allowing "anything and everything" in them, like Collada. It just turns out a big mess.

And after all that, I am not sure what place skeletal animation has in 2D games. I wanted to experiment with it for years, but somehow never got to it.
Using it to generate a sprite sheet, sure, that's very nice. Using it for the animation itself on run-time, that should be experimented with. If one thing is sure, its that it will completely change the "feeling" of the game.

User avatar
verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact:

Re: 2D Blender animation tests

Post by verilog » Sat Jul 06, 2013 12:59 am

Hi, spectralcanine (nice username)

You’re pretty much right. Parsing the skeletal data should be pretty straight forward, as you mentioned, rotation and translation matrices should do the trick. Obtaining the actual animation data is the tricky part, because of that, I thought of using blender for animation data generation and then parsing this info inside löve, pretty much what twobit has shown, except I was planning on using bone information.

I initially thought of this because my current animation system honestly is somewhat of a pain in the ass, it involves rendering multiple sprite sheets off-line and managing each sprite sheet as a unique animation via state machines inside the game engine. Right now it is not as complex as it could be, I was also in search for a real-time blending method, so I figured a skeletal animation system would be more useful for me in the long run, plus, as you also mentioned, I was aiming for that unique “feel”.

As far as inverse/forward kinematics go, I actually never thought it that far, basically because I was examining the option to use an external tool, like blender, to generate all this information.

spectralcanine
Citizen
Posts: 65
Joined: Sat Dec 22, 2012 8:17 am

Re: 2D Blender animation tests

Post by spectralcanine » Sat Jul 06, 2013 8:48 am

Yeah, for any kind of animation blending I'd go with skeletal animation.

I guess 2D games don't really need IK, since their dynamic animations are usually effecting only one bone (e.g., make the head and hands follow the mouse).
In case it is needed, CCD is quite simple to implement, I attached an example with two chains following the mouse, one with angle constraints (and with horrible code that I wrote quite some time ago in a hurry :)).

While I did use Blender also as a 2D level editor and wrote my own exporter, I never tried actually using it for 2D graphics. Didn't touch it in some time, but I remember it being a real pain adding textures and weights.

If you want to write an exporter, always remember you can see all the data in the current Blender scene under the Outliner window when selecting Datablocks in its view mode option.
Attachments
IK.love
(1.62 KiB) Downloaded 95 times

twobit
Prole
Posts: 3
Joined: Thu Jul 04, 2013 10:50 am

Re: 2D Blender animation tests

Post by twobit » Sat Jul 06, 2013 9:59 pm

The Spine example is indeed quite nice. I am too little of an artist though, to draw something beautiful as this. :cry:

For simple animations the skeletal structure of the model is pretty irrelevant. That is, unless you actually want to exploit it, of course. In Intrusion 2, for example, dead bodies of outgunned enemies litter the scene, each limb still being properly connected. Weapon of Choice (I have not yet played it) does something really cool: http://www.gamasutra.com/view/feature/1 ... hp?print=1 (take a look at figure 8). I wouldn't know how to go about creating such a mechanism.

Looking at the FBX export script, animations don't seem to be exported so easily. Nevertheless, I am going to write an export script as soon as I get the time. Thanks for the suggestion.

spectralcanine
Citizen
Posts: 65
Joined: Sat Dec 22, 2012 8:17 am

Re: 2D Blender animation tests

Post by spectralcanine » Sat Jul 06, 2013 11:31 pm

That's what I mean by "dynamic animations". Integrating IK with physics allows you to basically do anything imaginable. The simplest cases are seen in fighting games, where the characters stop their punches/kicks when they hit the enemy, rather than going through them, which would happen if you were to use static animations.
The common way is to indeed make static animations, but in-game blend them with physical IK chains.
This allows you to do otherwise impossible animations. For example: walking correctly on uneven terrain, pushing the wall with your hands when you run into it instead of "walking" while not moving, placing your gun's legs on the floor to improve your aim, etc.
Games can become very realistic with dynamic animations, though implementing them properly isn't trivial.

User avatar
verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact:

Re: 2D Blender animation tests

Post by verilog » Tue Jul 16, 2013 2:06 am

Thanks for the link, twobit, that article is pretty good, there's some very nice stuff in it, definitely inspiring. I might give this whole skeletal system thing a shot one day in the future, for now I think I'll be "stuck" using sprite sheets for my project. I look forward to other people's take on this matter. :ultrahappy:

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests