add 'control' VCA directive and 'visible' flag

This commit is contained in:
MihailRis 2026-10-07 20:51:33 +03:00
parent b21f4d4439
commit fed89b64c7
3 changed files with 38 additions and 18 deletions

View file

@ -39,12 +39,13 @@ local function bezier_interpolation(k0, k1, t)
return bezier(k0.value, k0.ry + k0.value, k1.ly + k1.value, k1.value, u)
end
local this = {
local M = {
CH_TRANSLATE = 1,
CH_ROTATE = 2,
CH_SCALE = 3,
CH_ZOOM = 4,
CH_TEXTURE = 5,
CH_CONTROL = 6,
INT_CONST = 1,
INT_LINEAR = 2,
@ -53,7 +54,7 @@ local this = {
MAX_DURATION = 1e9,
MAX_FRAMES = 1e9,
TRACE_CODEGEN = false,
TRACE_CODEGEN = true,
maths = {
bezier_interpolation = bezier_interpolation
@ -67,14 +68,14 @@ function internals.store_animation(name, track)
loaded_tracks[name] = track
end
function this.get_track(identifier)
function M.get_track(identifier)
return loaded_tracks[identifier]
end
local running_actions = {}
local playing_tracks = {}
function this.action(func)
function M.action(func)
table.insert(running_actions, coroutine.create(func))
end
@ -98,7 +99,7 @@ local PlayingTrack = {
}
}
function this.play(name, target)
function M.play(name, target)
if target and target.reset_pose then
target:reset_pose()
end
@ -156,4 +157,4 @@ function internals.restore_animation_backup()
loaded_tracks, backup_tracks = backup_tracks, {}
end
return this
return M

View file

@ -75,7 +75,7 @@ local env = {
return keys[left].value
end
left = keys[left]
if interp == INT_CONST then
if not interp or interp == INT_CONST then
return left.value
end
right = keys[right]
@ -170,7 +170,7 @@ local function codegen_track(raw_track, lineset, keysets, use_tsf)
local rotation = {false, false, false}
local scale = {false, false, false}
for i, line in ipairs(lines) do
code = code .. string.format("\n local l%d = ", i)
code = code .. string.format("\n local l%d = ", i)
.. codegen_line(raw_track, lineset, line, i, keysets)
if line.channel == animation.CH_TRANSLATE then
@ -185,8 +185,12 @@ local function codegen_track(raw_track, lineset, keysets, use_tsf)
elseif line.channel == animation.CH_ZOOM then
code = code .. "\n zoom = l" .. i
elseif line.channel == animation.CH_TEXTURE then
code = code .. string.format("\n target:set_texture(%s, %s)",
lineset.target_name:escape(), "l"..i)
code = code .. string.format("\n target:set_texture(%s, l%d)",
lineset.target_name:escape(), i)
elseif line.channel == animation.CH_CONTROL then
if lineset.flag == "visible" then
code = code .. string.format("\n target:set_visible(bone_index, l%d)", i)
end
end
end
@ -231,11 +235,13 @@ local function codegen_rig_target(raw_track, context)
end
local lineset_code = codegen_track(raw_track, lineset, context.keysets, true)
code = code .. string.format("\n local bone_index = target:index(%s)", string.escape(bone))
if context.has_tsf then
code = code .. "\n local dst = target:get_matrix(bone_index)"
end
code = code
.. string.format("\n local bone_index = target:index(%s)"
.. "\n local dst = target:get_matrix(bone_index)", string.escape(bone))
.. "\n do" .. lineset_code .. "\n end\n"
if lineset.target_type == "bone" then
if lineset.target_type == "bone" and context.has_tsf then
code = code ..
" target:set_matrix(bone_index, dst)\n"
end
@ -298,10 +304,8 @@ function internals.compile_animation_track(raw_track, track_name)
), "<curve>", "t", env)()
end
if context.has_tsf then
code = code .. codegen_rig_target(raw_track, context)
code = code .. codegen_object_target(raw_track, context)
end
code = code .. codegen_rig_target(raw_track, context)
code = code .. codegen_object_target(raw_track, context)
code = code .. codegen_camera_target(raw_track, context)
local src = "return function(target, t, intensity, m)\n"

View file

@ -8,6 +8,7 @@ local action_to_channel = {
scale = animation.CH_SCALE,
zoom = animation.CH_ZOOM,
texture = animation.CH_TEXTURE,
control = animation.CH_CONTROL,
}
local curve_to_interp = {
@ -62,6 +63,17 @@ local function parse_simple_frames(line, node)
end
end
local function parse_boolean_frames(line, node)
line.keys = {}
for j, key_node in ipairs(node) do
local keyframe = {
frame = tonumber(key_node.frame),
value = key_node.value == "on",
}
table.insert(line.keys, keyframe)
end
end
local function parse_directive(node, raw_track)
local linesets = raw_track.linesets
local tag = node['#']
@ -85,7 +97,8 @@ local function parse_directive(node, raw_track)
lineset = {
lines = {},
target_type = target_type,
target_name = target_name
target_name = target_name,
flag = node.flag,
}
linesets[target_name] = lineset
end
@ -103,6 +116,8 @@ local function parse_directive(node, raw_track)
line.expression = node.func
elseif node.curve then
parse_curve(line, node)
elseif node.flag then
parse_boolean_frames(line, node)
else
parse_simple_frames(line, node)
end