Skeletal animation in 2D

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
lune
Prole
Posts: 9
Joined: Thu Sep 22, 2016 10:03 am
Location: France

Skeletal animation in 2D

Post by lune »

Hello,

I'm interested with animating 2D mesh.

The mesh would be created and exported from Blender.

Then, i get the vertices and created the object with love.graphics.NewMesh.

I could use a vertex shader for doing the animation.

For doing this, i need a format available in Blender (i don't feel like doing my own exporter), which can export bones transformations, and weight.
It seems not very hard to multiply matrix, and weight them with bones informations.

My problem is that i have tried to export to Collada (.dae) and DirectX old format (.x). Both of them seems to use quaternions for transformations. I don't know quaternions, i don't know how to read matrices, and i haven't found anything about this (it seems "magic" operation everybody does and nobody understands).

As i want animating in 2D only, i don't need the whole magic toolbox, and Euler would be enough for me.

I don't have any idea for getting further, can you help me ?

Thank you!
User avatar
RaycatRakittra
Prole
Posts: 22
Joined: Fri Sep 30, 2016 12:40 am
Location: Chicago, IL
Contact:

Re: Skeletal animation in 2D

Post by RaycatRakittra »

I know Spine from Esoteric actively supports LOVE and they use mesh deformation. Perhaps you can study that client's code and use it in combination with a math library?
Sometimes, I can code things.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Skeletal animation in 2D

Post by pgimeno »

Quaternions are like compact matrices. There are formulas for getting a matrix from a quaternion, see e.g. https://en.wikipedia.org/wiki/Quaternio ... ion_matrix but you can use a ready-made library like CPML (see in particular https://github.com/excessive/cpml/blob/ ... 4.lua#L125).

Edit: Every time you use Eulers to make rotation calculations, God kills a kitten. Please think of the kittens!
User avatar
lune
Prole
Posts: 9
Joined: Thu Sep 22, 2016 10:03 am
Location: France

Re: Skeletal animation in 2D

Post by lune »

Well, at first, thank you for the answers.

Yes, one of my issues is a problem of quaternion calculation with the data provided in the Blender's export.
It's not the only one, maybe i'm struggling with something too big to be swallowed in one chunk (quaternions, matrix composition, world space/local space transformation… and shaders… to say the least).

But i think that using quaternions for a 2D problem is like smashing a fly with a gun.
With start/end angles, bones weight and linear interpolations, i feel that i could have done it with simple trigonometrics calculus (and without killing kittens).

It must be more difficult that i thought at first sight, otherwise i guess somebody would had already done something with Blender and Löve2D.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Skeletal animation in 2D

Post by pgimeno »

Yeah, using 3D maths to solve a 2D problem is overkill. If the quaternions represent rotation over one of the main axes only (quite likely for 2D), they will have the form Q = a + bi + 0j + 0k, Q = a + 0i + bj + 0k, or Q = a + 0i + 0j + bk. From there, the rotation angle is math.atan2(b, a)*2, if that helps.
User avatar
shakesoda
Citizen
Posts: 78
Joined: Thu Sep 25, 2014 11:57 am
Location: Seattle, WA
Contact:

Re: Skeletal animation in 2D

Post by shakesoda »

The math being overkill isn't really a problem if it's not a bottleneck is it? IQM format will give you animation data, anim9 can make use of it.
https://github.com/excessive/anim9 + https://github.com/excessive/iqm

https://github.com/excessive/ludum-dare ... sl#L13-L44 example of a shader for skeletal animation
excessive ❤ moé (LÖVE3D, CPML, ...). holo on IRC.
User avatar
lune
Prole
Posts: 9
Joined: Thu Sep 22, 2016 10:03 am
Location: France

Re: Skeletal animation in 2D

Post by lune »

Yes shakesoda, as long as the time involved in extra computations is negligible, i agree with you: not a problem.

Thank you for providing tools and code.

As Blender does not ship an IQM exporter, i've searched and found this:
https://github.com/excessive/iqm-sdk

I haven't done tests with it for the moment, though.

I try to display some 2D meshes this evening, and i will report success here :)

Thank you again!
User avatar
lune
Prole
Posts: 9
Joined: Thu Sep 22, 2016 10:03 am
Location: France

Re: Skeletal animation in 2D

Post by lune »

Hello again,

Well i've generated an iqm with a simple animated model (two quads with two bones, one quad is rotating on Z axis).

The model is loaded, i display it, but i can only see frame 0.
I've asked for animation, but it stays on its first frame.

Reading the documentation of anim9, it seems that you can display an animation without shader (what is the purpose of the shader in the ludum dare 35 sources, then ?)

Can you help me ? Thank you!

Code: Select all


local anim9 = require "anim9"
local iqmloader = require "iqmloader"

local model
local anims
local delta = 0

function love.load()
  local iqmfile="bones-rotation_plat.iqm"
  model = iqmloader.load(iqmfile)
  anims = iqmloader.load_anims(iqmfile)
  model.anim = anim9(anims)
  model.anim:play("ArmatureAction")
end

function love.draw()
  love.graphics.push()
  love.graphics.translate(100,100)
  love.graphics.scale(8,8)

  --i've tried without anim:update, but it's not animated either.
  delta=delta+0.001
  model.anim:update(delta)
  love.graphics.draw(model.mesh)

  love.graphics.pop()
end

User avatar
lune
Prole
Posts: 9
Joined: Thu Sep 22, 2016 10:03 am
Location: France

Re: Skeletal animation in 2D

Post by lune »

«Well» I thought «may be it's a problem with my iqm file.

So i borrowed the tiger.iqm in Ludum Dare 35 moe's assets.

I've also checked one more time in LD35 how the beast was animated , but as i didn't found anything new, i must have missed something :(

I just found a difference between my sources of the iqm loader, and the implementation in LD35 : a second parameter was set to false when loading a mesh. As i didn't find a second parameter of the sources i got, i discarded it.

The tiger doesn't move. It's a stoned tiger, and i guess that stoned tiger is a sad tiger!

Can you help me ? Thank you :)

Here are the sources:

Code: Select all


local anim9 = require "anim9"
local iqmloader = require "iqmloader" 

local mesh
local animation

function love.load()
  local iqmfile="bones-rotation_plat.iqm"
  -- i've seen «false» as second parameter in LD35, but
  -- the iqmloader function exported does have one parameter
  mesh = iqmloader.load("tiger.iqm") --, false)
  animation = iqmloader.load_anims("tiger.iqm")
  
  mesh.anim = anim9(animation)
  -- found anim names with «strings» on tiger.iqm
  mesh.anim:play("attack")
end

function love.draw()
  love.graphics.translate(200,200)
  love.graphics.scale(100,100)

  -- tiger is stoned :(
  love.graphics.draw(mesh.mesh)
end

rosshadden
Prole
Posts: 3
Joined: Fri Sep 09, 2016 5:05 pm

Re: Skeletal animation in 2D

Post by rosshadden »

Any updates on this? I think there's a great possible future with love2d and coa_tools (https://github.com/ndee85/coa_tools), but I don't think there are currently any libraries that can use its output.

I was going to start on a dragonbones runtime for love2d (https://github.com/acleverpun/dragonbones-love), but animations are not my forte. I really urge someone here to run with that torch, and I can help out a lot. I just don't think I should be the one leading the charge.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 167 guests