add 'texture' vca directive

This commit is contained in:
MihailRis 2026-09-23 22:26:54 +03:00
parent 5ecbeeda7e
commit c573d01cb7
3 changed files with 41 additions and 8 deletions

View file

@ -42,13 +42,14 @@ local this = {
CH_ROTATE = 2, CH_ROTATE = 2,
CH_SCALE = 3, CH_SCALE = 3,
CH_ZOOM = 4, CH_ZOOM = 4,
CH_TEXTURE = 5,
INT_CONST = 1, INT_CONST = 1,
INT_LINEAR = 2, INT_LINEAR = 2,
INT_BEZIER = 3, INT_BEZIER = 3,
INT_CUSTOM = 4, INT_CUSTOM = 4,
TRACE_CODEGEN = false, TRACE_CODEGEN = true,
maths = { maths = {
bezier_interpolation = bezier_interpolation bezier_interpolation = bezier_interpolation

View file

@ -60,6 +60,11 @@ local env = {
Y = {0, 1, 0}, Y = {0, 1, 0},
Z = {0, 0, 1}, Z = {0, 0, 1},
DST = mat4.idt(), DST = mat4.idt(),
string_at = function(keys, frame)
local left, _ = key_neighbors(keys, frame)
left = keys[left]
return left.value
end,
value_at = function(keys, frame, interp) value_at = function(keys, frame, interp)
local left, right = key_neighbors(keys, frame) local left, right = key_neighbors(keys, frame)
if left == right then if left == right then
@ -147,6 +152,10 @@ local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf)
code = code .. string.format( code = code .. string.format(
"\n local l%d = value_at_custom(keysets['%s'][%d], t * %s, %s)", "\n local l%d = value_at_custom(keysets['%s'][%d], t * %s, %s)",
i, lineset.target_name, i, raw_track.fps, valueat) i, lineset.target_name, i, raw_track.fps, valueat)
elseif line.channel == animation.CH_TEXTURE then
code = code .. string.format(
"\n local l%d = string_at(keysets['%s'][%d], t * %s)",
i, lineset.target_name, i, raw_track.fps)
else else
code = code .. string.format( code = code .. string.format(
"\n local l%d = value_at(keysets['%s'][%d], t * %s, %s)", "\n local l%d = value_at(keysets['%s'][%d], t * %s, %s)",
@ -164,7 +173,9 @@ local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf)
scale[line.axis] = i scale[line.axis] = i
has_tsf = true has_tsf = true
elseif line.channel == animation.CH_ZOOM then elseif line.channel == animation.CH_ZOOM then
code = code .. "\n zoom = l" .. i 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)
end end
end end
@ -206,14 +217,17 @@ local function codegen_rig_target(raw_track, context)
local code = "\n if target.set_matrix and target.index then\n" local code = "\n if target.set_matrix and target.index then\n"
code = code .. " local dst = DST\n" code = code .. " local dst = DST\n"
for bone, lineset in pairs(raw_track.linesets) do for bone, lineset in pairs(raw_track.linesets) do
if lineset.target_type ~= "bone" then if lineset.target_type ~= "bone" and lineset.target_type ~= "texture" then
goto continue goto continue
end end
local lineset_code = codegen_track( local lineset_code = codegen_track(
raw_track, lineset, context.memoised, context.keysets, true) raw_track, lineset, context.memoised, context.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" if lineset.target_type == "bone" then
code = code ..
" target:set_matrix(target:index(" .. string.escape(bone) .. "), dst)\n"
end
::continue:: ::continue::
end end
return code .. " end" return code .. " end"

View file

@ -7,6 +7,7 @@ local action_to_channel = {
rotate = animation.CH_ROTATE, rotate = animation.CH_ROTATE,
scale = animation.CH_SCALE, scale = animation.CH_SCALE,
zoom = animation.CH_ZOOM, zoom = animation.CH_ZOOM,
texture = animation.CH_TEXTURE,
} }
local curve_to_interp = { local curve_to_interp = {
@ -50,6 +51,17 @@ local function parse_curve(line, node)
end end
end end
local function parse_simple_frames(line, node)
line.keys = {}
for j, key_node in ipairs(node) do
local keyframe = {
frame = tonumber(key_node.frame),
value = key_node.value,
}
table.insert(line.keys, keyframe)
end
end
local function parse_track(root) local function parse_track(root)
local raw_track = { local raw_track = {
duration = math.huge, duration = math.huge,
@ -74,8 +86,10 @@ local function parse_track(root)
local target_type = nil local target_type = nil
if node.bone then if node.bone then
target_type = "bone" target_type = "bone"
elseif tag == "texture" then
target_type = "texture"
end end
local target_name = node.bone or "" local target_name = node.bone or node.name or ""
local lineset = linesets[target_name] local lineset = linesets[target_name]
if not lineset then if not lineset then
lineset = { lineset = {
@ -86,16 +100,20 @@ local function parse_track(root)
linesets[target_name] = lineset linesets[target_name] = lineset
end end
local channel = action_to_channel[tag]
if not channel then
error("unknown directive " .. tag:escape())
end
local line = { local line = {
axis = node.by and ("xyz"):find(node.by) or "", axis = node.by and ("xyz"):find(node.by) or "",
channel = action_to_channel[tag] channel = channel
} }
if node.func then if node.func then
line.expression = node.func line.expression = node.func
elseif node.curve then elseif node.curve then
parse_curve(line, node) parse_curve(line, node)
else else
error("not implemented") parse_simple_frames(line, node)
end end
table.insert(lineset.lines, line) table.insert(lineset.lines, line)