update animation api

This commit is contained in:
MihailRis 2026-09-10 19:09:49 +03:00
parent aa6ac5f5bd
commit 21bd5ba1b2
3 changed files with 33 additions and 19 deletions

View file

@ -68,26 +68,40 @@ end
local running_actions = {}
local playing_tracks = {}
local next_track_id = 1
function this.action(func)
table.insert(running_actions, coroutine.create(func))
end
function this.play(name, target)
local id = next_track_id
table.insert(playing_tracks, {id=id, name=name, target=target, timer=0.0})
next_track_id = id + 1
return id
end
function this.stop(id)
for i, entry in pairs(playing_tracks) do
if entry.id == id then
table.remove(playing_tracks, i)
return
local PlayingTrack = {
__index = {
stop = function(self)
table.remove_value(playing_tracks, self)
self.__timer = 0.0
self.__playing = false
end,
pause = function(self)
table.remove_value(playing_tracks, self)
self.__playing = false
end,
resume = function(self)
if not self.__playing then
table.insert(playing_tracks, self)
self.__playing = true
end
end
end
}
}
function this.play(name, target)
local track = setmetatable({
name = name,
target = target,
__timer = 0.0,
__playing = true,
}, PlayingTrack)
table.insert(playing_tracks, track)
return track
end
function internals.on_animation_frame()
@ -109,11 +123,11 @@ function internals.on_animation_frame()
debug.error("animation track not found: "..track_info.name)
table.remove(playing_tracks, i)
else
track_info.timer = track_info.timer + delta
if track_info.timer > track.duration then
track_info.__timer = track_info.__timer + delta
if track_info.__timer > track.duration then
table.remove(playing_tracks, i)
else
track.func(track_info.target, track_info.timer)
track.func(track_info.target, track_info.__timer)
end
end
end

View file

@ -182,7 +182,7 @@ local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf)
local axis_names = {"X", "Y", "Z"}
local axis_indices = {X=1, Y=2, Z=3}
local rotation_order = raw_track.rotation_order
local rotation_order = raw_track.rotation_order or "XYZ"
for i=1,3 do
local axis = axis_indices[rotation_order[i]]
local var = rotation[axis]

View file

@ -24,7 +24,7 @@ local function parse_configure(raw_track, node)
elseif node.duration then
raw_track.duration = node.duration
end
raw_track.rotation_order = string.upper(node["rotation-order"]) or "XYZ"
raw_track.rotation_order = string.upper(node["rotation-order"])
end
local function parse_curve(line, node)