Skeletal animation
Load a skinned model, create a model from it, and pass its first animation to an animator. The clip starts playing immediately and loops without any input.
local natiny = require("natiny")
natiny.backend.init(arg and arg[1] or natiny.backend.AUTO)
local window = natiny.window.create("Natiny - Skeletal animation", 1280, 720)
natiny.window.set_scale_mode(window, natiny.window.SCALE_MODE_STRETCH)
local MODEL_PATH = "common/models/RobotExpressive.glb"
local BG = natiny.color.from_hex("#151E2C")
local camera
local function build()
local resource = natiny.resource.load(MODEL_PATH)
local mesh = natiny.mesh.load(resource)
natiny.resource.destroy(resource)
local robot = natiny.model.create(mesh)
natiny.entity.set_scale(robot, 0.35, 0.35, 0.35)
local first_animation = natiny.mesh.get_animation(mesh, 0)
natiny.animator.create(robot, first_animation)
camera = natiny.camera.create()
natiny.entity.set_position(camera, natiny.entity.SPACE_WORLD, 0.0, 1.4, 2.6)
natiny.entity.look_at(camera, 0.0, 0.6, 0.0)
end
local function frame()
natiny.window.bind(window, function()
natiny.render.clear(BG)
natiny.camera.bind(camera, function()
natiny.render.tag("model")
end)
end)
end
build()
natiny.backend.loop(function(dt)
frame(dt)
end)
natiny.backend.shutdown()