Libs3D Library Skeletal Animation

From GiderosMobile
Revision as of 16:18, 13 August 2026 by MoKaLux (talk | contribs) (wip)

I am ready

Next step is to animate your 3D models, skeletal animations that is ☠️.

If you are using .fbx files, you would need to convert your files to .json using fbx-conv.exe.

If you are using .glb files this is easier.

fbx animation

So you have your animated model exported to an .fbx file. You need to use fbx-conv-win32.exe to convert it to a .json file.

What is fbx-conv-win32.exe?

A command line utility using the FBX SDK to convert FBX/Collada/Obj files to a custom text/binary format for static, keyframed and skinned meshes. https://github.com/libgdx/fbx-conv

You can find fbx-conv-win32.exe in your Gideros installation folder:

  • Gideros\Tools\fbx-conv-win32.exe

Some examples of converting an .fbx file to .json (using Windows PowerShell)

-- from within the fbx-conv.exe folder (with your model.fbx)
.\fbx-conv.exe -v -o G3DJ model.fbx model.json

-- from your model.fbx folder
C:\Program Files\Gideros\Tools\fbx-conv.exe -v -o G3DJ "model.fbx" "model.json"

Then loading your .json animation file in Gideros is as simple as

local anim = buildGdx("path/to/animated_model.json",
	{ modelpath="path/to/model/textures/", } -- textures path (optional)
)
D3Anim.setAnimation(anim, anim.animations[1], "main", true)
D3Anim.tick() -- animation engine tick

Some sample code, pic above (you may have to provide your own assets).

application:setBackgroundColor(0x55007f)

-- we set up a fullscreen 3D viewport (fov: consoles 60, pc 90)
local sw, sh = application:getContentWidth(), application:getContentHeight()
local view = D3.View.new(sw,sh, 90, 0.1,1*1024) -- (screen w,screen h, fov, near plane,far plane)

-- we position the view (camera) and set its target
view:lookAt(0*8,1.5*8,3*8, 0*8,1.5*8,0*8) -- (eyex,eyey,eyez, targetx,targety,targetz[, upx,upy,upz])

-- we add the view (camera) to Gideros stage
stage:addChild(view)

-- we will add 3D shapes and models to a scene
local scene = view:getScene()

-- loading models
local anim001=buildGdx("models/fbxs/character_dev.json")
local anim002=buildGdx("models/fbxs/animeCharacter_truebones.json",
	{ modelpath="models/fbxs/textures/", } -- textures path
)

-- set current animations
D3Anim.setAnimation(anim001,anim001.animations[math.random(#anim001.animations)],"main",true)
D3Anim.setAnimation(anim002,anim002.animations[math.random(#anim002.animations)],"main",true)

-- scale
local scale = 0.1
anim001:setScale(scale,scale,scale)
anim002:setScale(scale,scale,scale)
-- position
anim001:setPosition(1*8, 0*8, 0*8)
anim002:setPosition(-1*8, 0*8, 0*8)
-- rotation
anim001:setRotationY(0*15)
anim002:setRotationY(0*15)
-- order
scene:addChild(anim001)
scene:addChild(anim002)

-- light setup
local lsx, lsy, lsz = 5*8, 5*8, 0*8 -- light source position
local ltx, lty, ltz = 0.0*8, 0.0*8, 0.0*8 -- light target position
Lighting.setLight(lsx,lsy,lsz, 0.4) -- (x,y,z, ambient)
local pd, fov = 6*8, 5*8 -- 5*8, 6*8
Lighting.setLightTarget(ltx,lty,ltz, pd,fov) -- (x,y,z, projection distance,fov)

stage:addEventListener(Event.ENTER_FRAME,function(e)
	-- animation engine tick
	D3Anim.tick()
	-- compute shadows
	Lighting.computeShadows(scene)
end)

.glb animation

So you have your animated model exported to an .glb file. You can animate it this way:

local glbA = Glb.new("model/path", "file.glb")
local glbB = glbA:getScene()
local glb = G3DFormat.buildG3D(glbB)
-- animations
D3Anim.setAnimation(glb, glb.animations[1], "main", true)
D3Anim.tick() -- animation engine tick

Some sample code, pic above (you may have to provide your own assets).

application:setBackgroundColor(0x2e2e2e)

-- we set up a fullscreen 3D viewport (fov: consoles 60, pc 90)
local sw, sh = application:getContentWidth(), application:getContentHeight()
local view = D3.View.new(sw,sh, 90, 0.1,1*1024) -- (screen w,screen h, fov, near plane,far plane)

-- we position the view (camera) and set its target
view:lookAt(0.0*8,0.4*8,0.5*8, 0*8,0.25*8,-0.2*8) -- (eyex,eyey,eyez, targetx,targety,targetz[, upx,upy,upz])

-- we add the view (camera) to Gideros stage
stage:addChild(view)

-- we will add 3D shapes and models to a scene
local scene = view:getScene()

-- loading model
local glbA001 = Glb.new("models/glbs", "_animeCharacters_truebones.glb") -- Glb.new("path", "file")
local glbB001 = glbA001:getScene()
local glb001 = G3DFormat.buildG3D(glbB001)

-- animations
D3Anim.setAnimation(glb001, glb001.animations[4], "main", true)
-- animation engine tick
D3Anim.tick()

-- position
glb001:setPosition(0*8, 0*8, 0*8)
-- rotation
glb001:setRotationY(0*15)
-- scale
local scale = 100
glb001:setScale(scale,scale,scale)
-- order
scene:addChild(glb001)

-- light setup
local lsx, lsy, lsz = 1.0*8, 1.0*8, 1.0*8 -- light source position
local ltx, lty, ltz = 0.0*8, 0.0*8, 0.0*8 -- light target position
Lighting.setLight(lsx,lsy,lsz, 0.5) -- (x,y,z, ambient)
local pd, fov = 6*8, 7*8 -- 5*8, 6*8
Lighting.setLightTarget(ltx,lty,ltz, pd,fov) -- (x,y,z, projection distance,fov)
Lighting.computeShadows(scene)

-- game loop
stage:addEventListener(Event.ENTER_FRAME, function(e)
	D3Anim.tick() -- animation engine tick
	Lighting.computeShadows(scene)
end)

For the nerd in you

  • in theory, all you need is a single file containing your model, your skeleton in its bind pose, and your animations
  • basically buildGdx parse the json file into an intermediate representation (the g3d format), which is then fed into G3DFormat function to generate actual gideros objects
  • the loader code will parse the json file and extract several parts:
    • the skeleton structure and pose (binding pose)
    • the model structure and meshes
    • the animations if any
  • the shader does the animation. In fact OpenGL, since programmable pipeline was introduced, is more like a driver to the GPU. It is the shader code that dictates what to do with vertices, texture coordinates, animation data and so on
  • the lua code in 3DAnimation computes matrices used by the shader, but it is the shader that applies transformations to the mesh
  • having animations separated from the model is actually cool

I am out 4

So here you have your animations playing in Gideros.

You are strongly encouraged to mess with the code.

Bye for now!


Libs3D