mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 14:31:50 +00:00
fix key frames based animation
This commit is contained in:
parent
32876aa9e4
commit
7f15cd897c
2 changed files with 31 additions and 15 deletions
|
|
@ -106,6 +106,9 @@ local env = {
|
||||||
return left.value
|
return left.value
|
||||||
end
|
end
|
||||||
right = keys[right]
|
right = keys[right]
|
||||||
|
if left == nil then
|
||||||
|
return right.value
|
||||||
|
end
|
||||||
local t = (frame - left.frame) / (right.frame - left.frame)
|
local t = (frame - left.frame) / (right.frame - left.frame)
|
||||||
if interp == INT_BEZIER then
|
if interp == INT_BEZIER then
|
||||||
return bezier_interpolation(left, right, t)
|
return bezier_interpolation(left, right, t)
|
||||||
|
|
@ -128,13 +131,15 @@ local env = {
|
||||||
target:set_scale(scale)
|
target:set_scale(scale)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
|
dump = debug.print
|
||||||
}
|
}
|
||||||
table.extend(env, math)
|
table.extend(env, math)
|
||||||
|
|
||||||
local function codegen_track(raw_track, lines, memoised, keysets, transforms)
|
local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf)
|
||||||
|
local lines = lineset.lines
|
||||||
local code = ""
|
local code = ""
|
||||||
local hastsf = false
|
local has_tsf = false
|
||||||
local translation = {false, false, false}
|
local translation = {false, false, false}
|
||||||
local rotation = {false, false, false}
|
local rotation = {false, false, false}
|
||||||
local scale = {false, false, false}
|
local scale = {false, false, false}
|
||||||
|
|
@ -143,27 +148,33 @@ local function codegen_track(raw_track, lines, memoised, keysets, transforms)
|
||||||
code = code .. "\n local l" .. i .. " = (" ..
|
code = code .. "\n local l" .. i .. " = (" ..
|
||||||
process_expression(line.expression, memoised) .. ")"
|
process_expression(line.expression, memoised) .. ")"
|
||||||
elseif line.keys then
|
elseif line.keys then
|
||||||
keysets[i] = line.keys
|
debug.print(raw_track)
|
||||||
|
local target_keysets = keysets[lineset.target_name]
|
||||||
|
if not target_keysets then
|
||||||
|
target_keysets = {}
|
||||||
|
keysets[lineset.target_name] = target_keysets
|
||||||
|
end
|
||||||
|
target_keysets[i] = line.keys
|
||||||
code = code .. string.format(
|
code = code .. string.format(
|
||||||
"\n local l%d = value_at(keysets[%d], t * %s, %s)",
|
"\n local l%d = value_at(keysets['%s'][%d], t * %s, %s)",
|
||||||
i, i, raw_track.fps, line.interp)
|
i, lineset.target_name, i, raw_track.fps, line.interp)
|
||||||
end
|
end
|
||||||
|
|
||||||
if line.channel == this.CH_TRANSLATE then
|
if line.channel == this.CH_TRANSLATE then
|
||||||
translation[line.axis] = i
|
translation[line.axis] = i
|
||||||
hastsf = true
|
has_tsf = true
|
||||||
elseif line.channel == this.CH_ROTATE then
|
elseif line.channel == this.CH_ROTATE then
|
||||||
rotation[line.axis] = i
|
rotation[line.axis] = i
|
||||||
hastsf = true
|
has_tsf = true
|
||||||
elseif line.channel == this.CH_SCALE then
|
elseif line.channel == this.CH_SCALE then
|
||||||
scale[line.axis] = i
|
scale[line.axis] = i
|
||||||
hastsf = true
|
has_tsf = true
|
||||||
elseif line.channel == this.CH_ZOOM then
|
elseif line.channel == this.CH_ZOOM then
|
||||||
code = code .. "\n zoom = l" .. i
|
code = code .. "\n zoom = l" .. i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not hastsf or not transforms then
|
if not has_tsf or not use_tsf then
|
||||||
return code
|
return code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -201,7 +212,7 @@ local function codegen_rig_target(raw_track, memoised, keysets)
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
local lineset_code = codegen_track(
|
local lineset_code = codegen_track(
|
||||||
raw_track, lineset.lines, memoised, keysets, true)
|
raw_track, lineset, memoised, keysets, true)
|
||||||
|
|
||||||
code = code .. "\n do" .. lineset_code .. "\n end\n" ..
|
code = code .. "\n do" .. lineset_code .. "\n end\n" ..
|
||||||
" target:set_matrix(target:index(" .. string.escape(bone) .. "), dst)\n"
|
" target:set_matrix(target:index(" .. string.escape(bone) .. "), dst)\n"
|
||||||
|
|
@ -218,7 +229,7 @@ local function codegen_object_target(raw_track, memoised, keysets)
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
local lineset_code = codegen_track(
|
local lineset_code = codegen_track(
|
||||||
raw_track, lineset.lines, memoised, keysets, true)
|
raw_track, lineset, memoised, keysets, true)
|
||||||
code = code .. "\n do" .. lineset_code .. "\n end\n"
|
code = code .. "\n do" .. lineset_code .. "\n end\n"
|
||||||
.. " set_matrix(target, dst)\n"
|
.. " set_matrix(target, dst)\n"
|
||||||
return code .. " end"
|
return code .. " end"
|
||||||
|
|
@ -232,7 +243,7 @@ local function codegen_camera_target(raw_track, memoised, keysets)
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
local lineset_code = codegen_track(
|
local lineset_code = codegen_track(
|
||||||
raw_track, lineset.lines, memoised, keysets, false)
|
raw_track, lineset, memoised, keysets, false)
|
||||||
code = code .. "\n do" .. lineset_code .. "\n end\n"
|
code = code .. "\n do" .. lineset_code .. "\n end\n"
|
||||||
.. " target:set_zoom(zoom)\n"
|
.. " target:set_zoom(zoom)\n"
|
||||||
return code .. " end"
|
return code .. " end"
|
||||||
|
|
@ -309,6 +320,7 @@ function internals.on_animation_frame()
|
||||||
table.remove(running_actions, i)
|
table.remove(running_actions, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local delta = time.delta()
|
||||||
for i=1,#playing_tracks do
|
for i=1,#playing_tracks do
|
||||||
local track_info = playing_tracks[i]
|
local track_info = playing_tracks[i]
|
||||||
local track = loaded_tracks[track_info.name]
|
local track = loaded_tracks[track_info.name]
|
||||||
|
|
@ -316,7 +328,7 @@ function internals.on_animation_frame()
|
||||||
debug.error("animation track not found: "..track_info.name)
|
debug.error("animation track not found: "..track_info.name)
|
||||||
table.remove(playing_tracks, i)
|
table.remove(playing_tracks, i)
|
||||||
else
|
else
|
||||||
track_info.timer = track_info.timer + time.delta()
|
track_info.timer = track_info.timer + delta
|
||||||
if track_info.timer > track.duration then
|
if track_info.timer > track.duration then
|
||||||
table.remove(playing_tracks, i)
|
table.remove(playing_tracks, i)
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,11 @@ local function parse_track(root)
|
||||||
local target_name = node.bone or ""
|
local target_name = node.bone or ""
|
||||||
local lineset = linesets[target_name]
|
local lineset = linesets[target_name]
|
||||||
if not lineset then
|
if not lineset then
|
||||||
lineset = {lines = {}, target_type = target_type}
|
lineset = {
|
||||||
|
lines = {},
|
||||||
|
target_type = target_type,
|
||||||
|
target_name = target_name
|
||||||
|
}
|
||||||
linesets[target_name] = lineset
|
linesets[target_name] = lineset
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue