Libs3D Library Skeletal Animation: Difference between revisions
wip |
wip |
||
| Line 2: | Line 2: | ||
== I am ready == | == I am ready == | ||
Next step is to animate our 3D models, skeletal animations ☠️. | Next step is to animate our 3D models, skeletal animations that is ☠️. | ||
There are two methods that I know of to animate in Gideros. | |||
== fbx-conv.exe (json) == | |||
The first method using .fbx. | |||
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. | |||
So, in theory, all you need is a single file containing your model, your skeleton in its bind pose, and your animations. | |||
My 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 compute matrices used by the shader, but it is the shader that applies transformations to the mesh. | |||
Having animations separated from the model is actually more annoying then having all in the same file, because you may end up with duplicate things. In my fbx files, the skeleton was in each file, but not in the same pose, which was confusing. | |||
To try to work out the simplest case, I made a rectangle in Blender, linked to an armature, and added a couple key frames, basically making a block that folds. I exported that to FBX, and used fbx-conv-win32.exe to export it to a JSON file. | |||
The steps I did: | |||
- have an fbx model | |||
- copy it in your fbx-conv-win32 folder (optional?) | |||
- open windows powershell in the same directory | |||
- in the command line type: .\fbx-conv-win32.exe -f yourmodel.fbx yourmodel.g3dj | |||
- finally change the extension of yourmodel.g3dj to yourmodel.json | |||
you can grab fbx-conv for your system here: https://github.com/libgdx/fbx-conv | |||
I am not Gideros guru, one way of animating is converting .fbx file into .json file. There is a tool to do this in your Gideros installation folder: | I am not Gideros guru, one way of animating is converting .fbx file into .json file. There is a tool to do this in your Gideros installation folder: | ||
Revision as of 00:57, 13 August 2026
I am ready
Next step is to animate our 3D models, skeletal animations that is ☠️.
There are two methods that I know of to animate in Gideros.
fbx-conv.exe (json)
The first method using .fbx.
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.
So, in theory, all you need is a single file containing your model, your skeleton in its bind pose, and your animations.
My 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 compute matrices used by the shader, but it is the shader that applies transformations to the mesh.
Having animations separated from the model is actually more annoying then having all in the same file, because you may end up with duplicate things. In my fbx files, the skeleton was in each file, but not in the same pose, which was confusing.
To try to work out the simplest case, I made a rectangle in Blender, linked to an armature, and added a couple key frames, basically making a block that folds. I exported that to FBX, and used fbx-conv-win32.exe to export it to a JSON file.
The steps I did: - have an fbx model - copy it in your fbx-conv-win32 folder (optional?) - open windows powershell in the same directory - in the command line type: .\fbx-conv-win32.exe -f yourmodel.fbx yourmodel.g3dj - finally change the extension of yourmodel.g3dj to yourmodel.json
you can grab fbx-conv for your system here: https://github.com/libgdx/fbx-conv
I am not Gideros guru, one way of animating is converting .fbx file into .json file. There is a tool to do this in your Gideros installation folder:
Gideros\Tools\fbx-conv-win32.exe
This is how I use it to convert my .fbx files into .json files Gideros can manipulate:
.glb
D3Anim.updateBones()
.json (fbx) format
Loading .json animation files is as simple as
local anim = buildGdx("path/to/animated_model.json",
{ modelpath="path/to/model/textures/", } -- textures path
)
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)
...TO BE CONTINUED...
I am out 4
You are strongly encouraged to mess with the code.
Bye for now!
