Libs3D Library Skeletal Animation
From GiderosMobile
I am ready
Next step is to animate our 3D models, skeletal animations ☠️.
Gideros rulez
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!
