From 0b52369ed9e6a3e9c7453292d388c12cdfb7778a Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 6 Oct 2026 21:31:02 +0300 Subject: [PATCH 01/13] cleanup --- res/modules/internal/formats/vca.lua | 98 ++++++++++++++-------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/res/modules/internal/formats/vca.lua b/res/modules/internal/formats/vca.lua index c44d28904..26f4afa8d 100644 --- a/res/modules/internal/formats/vca.lua +++ b/res/modules/internal/formats/vca.lua @@ -62,6 +62,54 @@ local function parse_simple_frames(line, node) end end +local function parse_directive(node, raw_track) + local linesets = raw_track.linesets + local tag = node['#'] + if tag == "configure" then + parse_configure(raw_track, node) + return + elseif tag == "curve" then + raw_track.curves[node.name] = node + return + end + + local target_type = nil + if node.bone then + target_type = "bone" + elseif tag == "texture" then + target_type = "texture" + end + local target_name = node.bone or node.name or "" + local lineset = linesets[target_name] + if not lineset then + lineset = { + lines = {}, + target_type = target_type, + target_name = target_name + } + linesets[target_name] = lineset + end + + local channel = action_to_channel[tag] + if not channel then + error("unknown directive " .. tag:escape()) + end + local line = { + axis = node.by and ("xyz"):find(node.by) or "", + channel = channel, + period = node.period or animation.MAX_FRAMES + } + if node.func then + line.expression = node.func + elseif node.curve then + parse_curve(line, node) + else + parse_simple_frames(line, node) + end + + table.insert(lineset.lines, line) +end + local function parse_track(root) local raw_track = { duration = math.huge, @@ -69,56 +117,10 @@ local function parse_track(root) linesets = {}, curves = {}, } - local linesets = raw_track.linesets for i, node in ipairs(root) do - if type(node) == "string" then - goto continue + if type(node) == 'table' then + parse_directive(node, raw_track) end - local tag = node['#'] - if tag == "configure" then - parse_configure(raw_track, node) - goto continue - elseif tag == "curve" then - raw_track.curves[node.name] = node - goto continue - end - - local target_type = nil - if node.bone then - target_type = "bone" - elseif tag == "texture" then - target_type = "texture" - end - local target_name = node.bone or node.name or "" - local lineset = linesets[target_name] - if not lineset then - lineset = { - lines = {}, - target_type = target_type, - target_name = target_name - } - linesets[target_name] = lineset - end - - local channel = action_to_channel[tag] - if not channel then - error("unknown directive " .. tag:escape()) - end - local line = { - axis = node.by and ("xyz"):find(node.by) or "", - channel = channel, - period = node.period or animation.MAX_FRAMES - } - if node.func then - line.expression = node.func - elseif node.curve then - parse_curve(line, node) - else - parse_simple_frames(line, node) - end - - table.insert(lineset.lines, line) - ::continue:: end return raw_track end From fdd62e2e19b7194aa47c67839073bb3672b8b0ba Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 7 Oct 2026 18:20:51 +0300 Subject: [PATCH 02/13] remove unused feature --- res/modules/internal/animation_codegen.lua | 32 ++++++---------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/res/modules/internal/animation_codegen.lua b/res/modules/internal/animation_codegen.lua index 525240f66..39ba4f20f 100644 --- a/res/modules/internal/animation_codegen.lua +++ b/res/modules/internal/animation_codegen.lua @@ -15,7 +15,7 @@ local exclude_patters = { } -- TODO: replace with actual expression -> lua translator -local function process_expression(src, memoised, mode) +local function process_expression(src, mode) if mode == 'mul' then src = string.format("(%s) * intensity + (1.0 - intensity)", src) elseif mode == "add" then @@ -30,7 +30,6 @@ local function process_expression(src, memoised, mode) for i, pattern in ipairs(patterns) do local pattern_safe = string.pattern_safe(pattern.pattern) if src:find(pattern_safe) then - memoised[pattern.name] = pattern.pattern src = src:gsub(pattern_safe, pattern.name) end end @@ -137,7 +136,7 @@ local is_multiplier = { [animation.CH_ZOOM] = true, } -local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf) +local function codegen_track(raw_track, lineset, keysets, use_tsf) local lines = lineset.lines local code = "" local has_tsf = false @@ -147,7 +146,7 @@ local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf) for i, line in ipairs(lines) do if line.expression then code = code .. "\n local l" .. i .. " = (" .. - process_expression(line.expression, memoised, + process_expression(line.expression, is_multiplier[line.channel] and "mul" or "add") .. ")" elseif line.keys then local target_keysets = keysets[lineset.target_name] @@ -229,8 +228,7 @@ local function codegen_rig_target(raw_track, context) if lineset.target_type ~= "bone" and lineset.target_type ~= "texture" then goto continue end - local lineset_code = codegen_track( - raw_track, lineset, context.memoised, context.keysets, true) + local lineset_code = codegen_track(raw_track, lineset, context.keysets, true) code = code .. string.format("\n local bone_index = target:index(%s)" @@ -252,8 +250,7 @@ local function codegen_object_target(raw_track, context) if not lineset then return "" end - local lineset_code = codegen_track( - raw_track, lineset, context.memoised, context.keysets, true) + local lineset_code = codegen_track(raw_track, lineset, context.keysets, true) code = code .. "\n do" .. lineset_code .. "\n end\n" .. " set_matrix(target, dst)\n" return code .. " end" @@ -266,8 +263,7 @@ local function codegen_camera_target(raw_track, context) if not lineset then return "" end - local lineset_code = codegen_track( - raw_track, lineset, context.memoised, context.keysets, false) + local lineset_code = codegen_track(raw_track, lineset, context.keysets, false) code = code .. "\n do" .. lineset_code .. "\n end\n" .. " target:set_zoom(zoom)\n" return code .. " end" @@ -277,14 +273,13 @@ end function internals.compile_animation_track(raw_track, track_name) local code = "" local context = { - memoised = {}, keysets = {}, curves = {}, } for name, curve in pairs(raw_track.curves) do context.curves[name] = load(string.format( "return function(kl, kr, t) return %s end", - process_expression(curve.func, context.memoised, "curve") + process_expression(curve.func, "curve") ), "", "t", env)() end @@ -292,17 +287,8 @@ function internals.compile_animation_track(raw_track, track_name) code = code .. codegen_object_target(raw_track, context) code = code .. codegen_camera_target(raw_track, context) - local memoised_code = "" - for name, expression in pairs(context.memoised) do - memoised_code = memoised_code .. "\n local " .. name .. " = " - .. expression - end - - if #memoised_code > 0 then - code = memoised_code .. "\n" .. code - end - - local src = "return function(target, t, intensity, m)\n m = m or 1\n intensity = intensity or 1.0\n" + local src = "return function(target, t, intensity, m)\n" + .. "m = m or 1\n intensity = intensity or 1.0\n" .. code .. "\nend" if animation.TRACE_CODEGEN then From b21f4d4439405838a06491a28d8f8070d741a6ac Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 7 Oct 2026 19:55:19 +0300 Subject: [PATCH 03/13] refactor animation_codegen.lua --- res/modules/internal/animation_codegen.lua | 81 +++++++++++++--------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/res/modules/internal/animation_codegen.lua b/res/modules/internal/animation_codegen.lua index 39ba4f20f..272b6c536 100644 --- a/res/modules/internal/animation_codegen.lua +++ b/res/modules/internal/animation_codegen.lua @@ -136,6 +136,32 @@ local is_multiplier = { [animation.CH_ZOOM] = true, } +local function codegen_line(raw_track, lineset, line, index, keysets) + if line.expression then + return "(" .. process_expression(line.expression, + is_multiplier[line.channel] and "mul" or "add") .. ")" + elseif line.keys then + local target_keysets = keysets[lineset.target_name] + if not target_keysets then + target_keysets = {} + keysets[lineset.target_name] = target_keysets + end + target_keysets[index] = line.keys + + if line.curve_func then + local valueat = string.format("curves[%s]", string.escape(line.curve_func)) + return string.format("value_at_custom(keysets['%s'][%d], t * %s %% %s, %s)", + lineset.target_name, index, raw_track.fps, line.period, valueat) + elseif line.channel == animation.CH_TEXTURE then + return string.format("string_at(keysets['%s'][%d], t * %s %% %s)", + lineset.target_name, index, raw_track.fps, line.period) + else + return string.format("value_at(keysets['%s'][%d], t * %s %% %s, %s)", + lineset.target_name, index, raw_track.fps, line.period, line.interp) + end + end +end + local function codegen_track(raw_track, lineset, keysets, use_tsf) local lines = lineset.lines local code = "" @@ -144,34 +170,8 @@ 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 - if line.expression then - code = code .. "\n local l" .. i .. " = (" .. - process_expression(line.expression, - is_multiplier[line.channel] and "mul" or "add") .. ")" - elseif line.keys then - 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 - - if line.curve_func then - local valueat = string.format("curves[%s]", string.escape(line.curve_func)) - - code = code .. string.format( - "\n local l%d = value_at_custom(keysets['%s'][%d], t * %s %% %s, %s)", - i, lineset.target_name, i, raw_track.fps, line.period, valueat) - elseif line.channel == animation.CH_TEXTURE then - code = code .. string.format( - "\n local l%d = string_at(keysets['%s'][%d], t * %s %% %s)", - i, lineset.target_name, i, raw_track.fps, line.period) - else - code = code .. string.format( - "\n local l%d = value_at(keysets['%s'][%d], t * %s %% %s, %s)", - i, lineset.target_name, i, raw_track.fps, line.period, line.interp) - end - end + code = code .. string.format("\n local l%d = ", i) + .. codegen_line(raw_track, lineset, line, i, keysets) if line.channel == animation.CH_TRANSLATE then translation[line.axis] = i @@ -185,7 +185,8 @@ 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, %s)", + lineset.target_name:escape(), "l"..i) end end @@ -270,11 +271,25 @@ local function codegen_camera_target(raw_track, context) end +local function has_transform_directive(raw_track) + for _, lineset in pairs(raw_track.linesets) do + for _, line in ipairs(lineset.lines) do + if line.channel == animation.CH_TRANSLATE or + line.channel == animation.CH_ROTATE or + line.channel == animation.CH_SCALE then + return true + end + end + end + return false +end + function internals.compile_animation_track(raw_track, track_name) local code = "" local context = { keysets = {}, curves = {}, + has_tsf = has_transform_directive(raw_track), } for name, curve in pairs(raw_track.curves) do context.curves[name] = load(string.format( @@ -283,12 +298,14 @@ function internals.compile_animation_track(raw_track, track_name) ), "", "t", env)() end - code = code .. codegen_rig_target(raw_track, context) - code = code .. codegen_object_target(raw_track, context) + 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_camera_target(raw_track, context) local src = "return function(target, t, intensity, m)\n" - .. "m = m or 1\n intensity = intensity or 1.0\n" + .. " m = m or 1\n intensity = intensity or 1.0\n" .. code .. "\nend" if animation.TRACE_CODEGEN then From fed89b64c798ac3e1e121af3247d9ce5c0ea6f89 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 7 Oct 2026 20:51:33 +0300 Subject: [PATCH 04/13] add 'control' VCA directive and 'visible' flag --- res/modules/animation.lua | 13 ++++++----- res/modules/internal/animation_codegen.lua | 26 +++++++++++++--------- res/modules/internal/formats/vca.lua | 17 +++++++++++++- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/res/modules/animation.lua b/res/modules/animation.lua index 0c7bb7741..b2cc56879 100644 --- a/res/modules/animation.lua +++ b/res/modules/animation.lua @@ -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 diff --git a/res/modules/internal/animation_codegen.lua b/res/modules/internal/animation_codegen.lua index 272b6c536..824070a18 100644 --- a/res/modules/internal/animation_codegen.lua +++ b/res/modules/internal/animation_codegen.lua @@ -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) ), "", "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" diff --git a/res/modules/internal/formats/vca.lua b/res/modules/internal/formats/vca.lua index 26f4afa8d..d87f5716c 100644 --- a/res/modules/internal/formats/vca.lua +++ b/res/modules/internal/formats/vca.lua @@ -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 From 1f2e938d83712a69da27aede140038fa64d01e4f Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 7 Oct 2026 22:32:11 +0300 Subject: [PATCH 05/13] feat: control flag visible for whole skeleton support --- res/modules/internal/animation_codegen.lua | 27 +++++++++++++++------- res/modules/internal/formats/vca.lua | 2 ++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/res/modules/internal/animation_codegen.lua b/res/modules/internal/animation_codegen.lua index 824070a18..169b08163 100644 --- a/res/modules/internal/animation_codegen.lua +++ b/res/modules/internal/animation_codegen.lua @@ -162,13 +162,18 @@ local function codegen_line(raw_track, lineset, line, index, keysets) end end -local function codegen_track(raw_track, lineset, keysets, use_tsf) +local function codegen_track(raw_track, lineset, keysets, use_tsf, target_type) + if lineset.target_type ~= target_type then + return "" + end + local lines = lineset.lines local code = "" local has_tsf = false local translation = {false, false, false} 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) .. codegen_line(raw_track, lineset, line, i, keysets) @@ -189,7 +194,11 @@ local function codegen_track(raw_track, lineset, keysets, use_tsf) 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) + if target_type == "bone" then + code = code .. string.format("\n target:set_visible(bone_index, l%d)", i) + else + code = code .. string.format("\n target:set_visible(l%d)", i) + end end end end @@ -233,7 +242,7 @@ local function codegen_rig_target(raw_track, context) if lineset.target_type ~= "bone" and lineset.target_type ~= "texture" then goto continue end - local lineset_code = codegen_track(raw_track, lineset, context.keysets, true) + local lineset_code = codegen_track(raw_track, lineset, context.keysets, true, "bone") code = code .. string.format("\n local bone_index = target:index(%s)", string.escape(bone)) if context.has_tsf then @@ -251,16 +260,18 @@ local function codegen_rig_target(raw_track, context) end local function codegen_object_target(raw_track, context) - local code = "\n if target.set_pos then\n" - code = code .. " local dst = mat4.idt()\n" + local code = " local dst = mat4.idt()\n" local lineset = raw_track.linesets[""] if not lineset then return "" end local lineset_code = codegen_track(raw_track, lineset, context.keysets, true) code = code .. "\n do" .. lineset_code .. "\n end\n" - .. " set_matrix(target, dst)\n" - return code .. " end" + + if context.has_tsf then + code = code .. " set_matrix(target, dst)\n" + end + return code end local function codegen_camera_target(raw_track, context) @@ -270,7 +281,7 @@ local function codegen_camera_target(raw_track, context) if not lineset then return "" end - local lineset_code = codegen_track(raw_track, lineset, context.keysets, false) + local lineset_code = codegen_track(raw_track, lineset, context.keysets, false, "camera") code = code .. "\n do" .. lineset_code .. "\n end\n" .. " target:set_zoom(zoom)\n" return code .. " end" diff --git a/res/modules/internal/formats/vca.lua b/res/modules/internal/formats/vca.lua index d87f5716c..9ce4b6230 100644 --- a/res/modules/internal/formats/vca.lua +++ b/res/modules/internal/formats/vca.lua @@ -88,6 +88,8 @@ local function parse_directive(node, raw_track) local target_type = nil if node.bone then target_type = "bone" + elseif node.zoom then + target_type = "camera" elseif tag == "texture" then target_type = "texture" end From bbe1873bc71d027976ac5920cc2243b5957447fa Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 7 Oct 2026 22:51:57 +0300 Subject: [PATCH 06/13] update doc/*/vca.md --- doc/en/vca.md | 18 ++++++++++++++++++ doc/ru/vca.md | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/doc/en/vca.md b/doc/en/vca.md index 7b2bda0b5..722432e31 100644 --- a/doc/en/vca.md +++ b/doc/en/vca.md @@ -28,6 +28,7 @@ Two kinds of curve definitions are currently available, each producing a value ` - `@scale` - scales an object/bone (multiplier) - `@zoom` - camera zoom (multiplier) - `@texture` - change of a dynamically assigned texture (see [skeleton:set_texture](scripting/ecs.md#skeleton)) +- `@control` - changing flag values, such as visibility ## Metadata @@ -96,6 +97,23 @@ If you do not wish to limit the animation duration via `configure` but want to l } ``` +Example of using the `control` directive: + +```vcd +# Specific bone +@control bone head flag visible period 20 { + @key frame 0 value on + @key frame 10 value off +} + +# Entire skeleton +@control flag visible period 30 { + @key frame 0 value on + @key frame 10 value off +} + +``` + ## Expression curves The attribute describes a function `f(t) = x`, where t is time in seconds. diff --git a/doc/ru/vca.md b/doc/ru/vca.md index 2cba3c3ab..91c252833 100644 --- a/doc/ru/vca.md +++ b/doc/ru/vca.md @@ -28,6 +28,7 @@ VCA файл состоит из набора директив, порядок - `@scale` - масштабирование объекта/кости (множитель) - `@zoom` - масштаб камеры (множитель) - `@texture` - смена динамически-назначаемой текстуры (см. [skeleton:set_texture](scripting/ecs.md#skeleton)) +- `@control` - изменение значений флагов, таких как видимость ## Мета-информация @@ -96,6 +97,23 @@ VCA файл состоит из набора директив, порядок } ``` +Пример использования директивы `control`: + +```vcd +# Конкретная кость +@control bone head flag visible period 20 { + @key frame 0 value on + @key frame 10 value off +} + +# Весь скелет +@control flag visible period 30 { + @key frame 0 value on + @key frame 10 value off +} + +``` + ## Кривые через выражения Через атрибут описывается функция `f(t) = x` где t - время в секундах. From 26d09f750b91c1177ca21c1f27788d77cd392780 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 8 Oct 2026 23:24:09 +0300 Subject: [PATCH 07/13] replace control with show for visibility --- res/modules/animation.lua | 2 +- res/modules/internal/animation_codegen.lua | 12 +++++------- res/modules/internal/formats/vca.lua | 8 ++++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/res/modules/animation.lua b/res/modules/animation.lua index b2cc56879..fd43ac9f9 100644 --- a/res/modules/animation.lua +++ b/res/modules/animation.lua @@ -45,7 +45,7 @@ local M = { CH_SCALE = 3, CH_ZOOM = 4, CH_TEXTURE = 5, - CH_CONTROL = 6, + CH_SHOW = 6, INT_CONST = 1, INT_LINEAR = 2, diff --git a/res/modules/internal/animation_codegen.lua b/res/modules/internal/animation_codegen.lua index 169b08163..eb08c2afb 100644 --- a/res/modules/internal/animation_codegen.lua +++ b/res/modules/internal/animation_codegen.lua @@ -192,13 +192,11 @@ local function codegen_track(raw_track, lineset, keysets, use_tsf, target_type) elseif line.channel == animation.CH_TEXTURE then 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 - if target_type == "bone" then - code = code .. string.format("\n target:set_visible(bone_index, l%d)", i) - else - code = code .. string.format("\n target:set_visible(l%d)", i) - end + elseif line.channel == animation.CH_SHOW then + if target_type == "bone" then + code = code .. string.format("\n target:set_visible(bone_index, l%d)", i) + else + code = code .. string.format("\n target:set_visible(l%d)", i) end end end diff --git a/res/modules/internal/formats/vca.lua b/res/modules/internal/formats/vca.lua index 9ce4b6230..66f1945d7 100644 --- a/res/modules/internal/formats/vca.lua +++ b/res/modules/internal/formats/vca.lua @@ -8,7 +8,7 @@ local action_to_channel = { scale = animation.CH_SCALE, zoom = animation.CH_ZOOM, texture = animation.CH_TEXTURE, - control = animation.CH_CONTROL, + show = animation.CH_SHOW, } local curve_to_interp = { @@ -17,6 +17,10 @@ local curve_to_interp = { bezier = animation.INT_BEZIER, } +local boolean_actions = { + show = true +} + local function parse_configure(raw_track, node) if node.fps then raw_track.fps = tonumber(node.fps) @@ -118,7 +122,7 @@ local function parse_directive(node, raw_track) line.expression = node.func elseif node.curve then parse_curve(line, node) - elseif node.flag then + elseif boolean_actions[tag] then parse_boolean_frames(line, node) else parse_simple_frames(line, node) From a036a590aba69ba5b2dcb5e38c1ac4d67bd670d8 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 8 Oct 2026 23:27:45 +0300 Subject: [PATCH 08/13] add 'model' directive --- res/modules/animation.lua | 1 + res/modules/internal/animation_codegen.lua | 2 ++ res/modules/internal/formats/vca.lua | 1 + 3 files changed, 4 insertions(+) diff --git a/res/modules/animation.lua b/res/modules/animation.lua index fd43ac9f9..89a1ae6e2 100644 --- a/res/modules/animation.lua +++ b/res/modules/animation.lua @@ -46,6 +46,7 @@ local M = { CH_ZOOM = 4, CH_TEXTURE = 5, CH_SHOW = 6, + CH_MODEL = 7, INT_CONST = 1, INT_LINEAR = 2, diff --git a/res/modules/internal/animation_codegen.lua b/res/modules/internal/animation_codegen.lua index eb08c2afb..8230c28dd 100644 --- a/res/modules/internal/animation_codegen.lua +++ b/res/modules/internal/animation_codegen.lua @@ -192,6 +192,8 @@ local function codegen_track(raw_track, lineset, keysets, use_tsf, target_type) elseif line.channel == animation.CH_TEXTURE then code = code .. string.format("\n target:set_texture(%s, l%d)", lineset.target_name:escape(), i) + elseif line.channel == animation.CH_MODEL then + code = code .. string.format("\n target:set_model(bone_index, l%d)", i) elseif line.channel == animation.CH_SHOW then if target_type == "bone" then code = code .. string.format("\n target:set_visible(bone_index, l%d)", i) diff --git a/res/modules/internal/formats/vca.lua b/res/modules/internal/formats/vca.lua index 66f1945d7..0c72203c7 100644 --- a/res/modules/internal/formats/vca.lua +++ b/res/modules/internal/formats/vca.lua @@ -9,6 +9,7 @@ local action_to_channel = { zoom = animation.CH_ZOOM, texture = animation.CH_TEXTURE, show = animation.CH_SHOW, + model = animation.CH_MODEL, } local curve_to_interp = { From ed799233e571f1f13454a9d5750915fa0cd16d56 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 8 Oct 2026 23:32:05 +0300 Subject: [PATCH 09/13] update doc/*/vca.md --- doc/en/vca.md | 8 ++++---- doc/ru/vca.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/en/vca.md b/doc/en/vca.md index 722432e31..16df83cc8 100644 --- a/doc/en/vca.md +++ b/doc/en/vca.md @@ -28,7 +28,7 @@ Two kinds of curve definitions are currently available, each producing a value ` - `@scale` - scales an object/bone (multiplier) - `@zoom` - camera zoom (multiplier) - `@texture` - change of a dynamically assigned texture (see [skeleton:set_texture](scripting/ecs.md#skeleton)) -- `@control` - changing flag values, such as visibility +- `@show` - visibility of a bone or the entire skeleton/object (if no bone is specified) ## Metadata @@ -97,17 +97,17 @@ If you do not wish to limit the animation duration via `configure` but want to l } ``` -Example of using the `control` directive: +Example of using flag directives like `show`: ```vcd # Specific bone -@control bone head flag visible period 20 { +@show bone head period 20 { @key frame 0 value on @key frame 10 value off } # Entire skeleton -@control flag visible period 30 { +@show period 30 { @key frame 0 value on @key frame 10 value off } diff --git a/doc/ru/vca.md b/doc/ru/vca.md index 91c252833..aac88aec8 100644 --- a/doc/ru/vca.md +++ b/doc/ru/vca.md @@ -28,7 +28,7 @@ VCA файл состоит из набора директив, порядок - `@scale` - масштабирование объекта/кости (множитель) - `@zoom` - масштаб камеры (множитель) - `@texture` - смена динамически-назначаемой текстуры (см. [skeleton:set_texture](scripting/ecs.md#skeleton)) -- `@control` - изменение значений флагов, таких как видимость +- `@show` - видимость кости или всего скелета / объекта (если не указана кость) ## Мета-информация @@ -97,17 +97,17 @@ VCA файл состоит из набора директив, порядок } ``` -Пример использования директивы `control`: +Пример использования директив-флагов, таких как `show`: ```vcd # Конкретная кость -@control bone head flag visible period 20 { +@show bone head period 20 { @key frame 0 value on @key frame 10 value off } # Весь скелет -@control flag visible period 30 { +@show period 30 { @key frame 0 value on @key frame 10 value off } From ad56f88e857863b126ee7aff74e54be2d6c49044 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 8 Oct 2026 23:34:04 +0300 Subject: [PATCH 10/13] update doc/*/vca.md --- doc/en/vca.md | 1 + doc/ru/vca.md | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/en/vca.md b/doc/en/vca.md index 16df83cc8..b8be3fe58 100644 --- a/doc/en/vca.md +++ b/doc/en/vca.md @@ -28,6 +28,7 @@ Two kinds of curve definitions are currently available, each producing a value ` - `@scale` - scales an object/bone (multiplier) - `@zoom` - camera zoom (multiplier) - `@texture` - change of a dynamically assigned texture (see [skeleton:set_texture](scripting/ecs.md#skeleton)) +- `@model` - bone model replacement (see [skeleton:set_model](scripting/ecs.md#skeleton)) - `@show` - visibility of a bone or the entire skeleton/object (if no bone is specified) ## Metadata diff --git a/doc/ru/vca.md b/doc/ru/vca.md index aac88aec8..79e9eacb9 100644 --- a/doc/ru/vca.md +++ b/doc/ru/vca.md @@ -28,6 +28,7 @@ VCA файл состоит из набора директив, порядок - `@scale` - масштабирование объекта/кости (множитель) - `@zoom` - масштаб камеры (множитель) - `@texture` - смена динамически-назначаемой текстуры (см. [skeleton:set_texture](scripting/ecs.md#skeleton)) +- `@model` - назначение замены модели кости (см. [skeleton:set_model](scripting/ecs.md#skeleton)) - `@show` - видимость кости или всего скелета / объекта (если не указана кость) ## Мета-информация From 51c8d78b88fdcc241abfd9cc0b16feb6f84c416b Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 9 Oct 2026 00:14:59 +0300 Subject: [PATCH 11/13] add 'color' VCA directive --- res/modules/animation.lua | 1 + res/modules/internal/animation_codegen.lua | 11 +++++++++++ res/modules/internal/formats/vca.lua | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/res/modules/animation.lua b/res/modules/animation.lua index 89a1ae6e2..a4e1f73d9 100644 --- a/res/modules/animation.lua +++ b/res/modules/animation.lua @@ -47,6 +47,7 @@ local M = { CH_TEXTURE = 5, CH_SHOW = 6, CH_MODEL = 7, + CH_COLOR = 8, INT_CONST = 1, INT_LINEAR = 2, diff --git a/res/modules/internal/animation_codegen.lua b/res/modules/internal/animation_codegen.lua index 8230c28dd..5a7c5d8e0 100644 --- a/res/modules/internal/animation_codegen.lua +++ b/res/modules/internal/animation_codegen.lua @@ -173,6 +173,7 @@ local function codegen_track(raw_track, lineset, keysets, use_tsf, target_type) local translation = {false, false, false} local rotation = {false, false, false} local scale = {false, false, false} + local color = {false, false, false, false} for i, line in ipairs(lines) do code = code .. string.format("\n local l%d = ", i) @@ -200,9 +201,19 @@ local function codegen_track(raw_track, lineset, keysets, use_tsf, target_type) else code = code .. string.format("\n target:set_visible(l%d)", i) end + elseif line.channel == animation.CH_COLOR then + color[line.axis] = i end end + if color[1] or color[2] or color[3] or color[4] then + code = code .. "\n target:set_color({" .. + (color[1] and ("l" .. color[1]) or '1').. ", " .. + (color[2] and ("l" .. color[2]) or '1').. ", " .. + (color[3] and ("l" .. color[3]) or '1').. ", " .. + (color[4] and ("l" .. color[4]) or '1').. "})" + end + if not has_tsf or not use_tsf then return code end diff --git a/res/modules/internal/formats/vca.lua b/res/modules/internal/formats/vca.lua index 0c72203c7..1ebac16f8 100644 --- a/res/modules/internal/formats/vca.lua +++ b/res/modules/internal/formats/vca.lua @@ -10,6 +10,7 @@ local action_to_channel = { texture = animation.CH_TEXTURE, show = animation.CH_SHOW, model = animation.CH_MODEL, + color = animation.CH_COLOR, } local curve_to_interp = { @@ -115,7 +116,7 @@ local function parse_directive(node, raw_track) error("unknown directive " .. tag:escape()) end local line = { - axis = node.by and ("xyz"):find(node.by) or "", + axis = node.by and (("xyz"):find(node.by) or ("rgba"):find(node.by)) or "", channel = channel, period = node.period or animation.MAX_FRAMES } From 08abed324c5790c77b5afae82c45ce23c34b77c7 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 9 Oct 2026 00:19:22 +0300 Subject: [PATCH 12/13] fix 'color' target --- res/modules/internal/animation_codegen.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/res/modules/internal/animation_codegen.lua b/res/modules/internal/animation_codegen.lua index 5a7c5d8e0..1b637d866 100644 --- a/res/modules/internal/animation_codegen.lua +++ b/res/modules/internal/animation_codegen.lua @@ -207,11 +207,16 @@ local function codegen_track(raw_track, lineset, keysets, use_tsf, target_type) end if color[1] or color[2] or color[3] or color[4] then - code = code .. "\n target:set_color({" .. + local color_vector = "{" .. (color[1] and ("l" .. color[1]) or '1').. ", " .. (color[2] and ("l" .. color[2]) or '1').. ", " .. (color[3] and ("l" .. color[3]) or '1').. ", " .. - (color[4] and ("l" .. color[4]) or '1').. "})" + (color[4] and ("l" .. color[4]) or '1').. "}" + if target_type == "bone" then + code = code .. "\n target:set_color(" .. color_vector .. ", bone_index)" + else + code = code .. "\n target:set_color(" .. color_vector .. ")" + end end if not has_tsf or not use_tsf then From a382fa2aabc28f0f3b3b8f045d56d3a33fb1fbe8 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Fri, 9 Oct 2026 00:19:36 +0300 Subject: [PATCH 13/13] update doc/*/vca.md --- doc/en/vca.md | 1 + doc/ru/vca.md | 1 + 2 files changed, 2 insertions(+) diff --git a/doc/en/vca.md b/doc/en/vca.md index b8be3fe58..1299662f0 100644 --- a/doc/en/vca.md +++ b/doc/en/vca.md @@ -30,6 +30,7 @@ Two kinds of curve definitions are currently available, each producing a value ` - `@texture` - change of a dynamically assigned texture (see [skeleton:set_texture](scripting/ecs.md#skeleton)) - `@model` - bone model replacement (see [skeleton:set_model](scripting/ecs.md#skeleton)) - `@show` - visibility of a bone or the entire skeleton/object (if no bone is specified) +- `@color` - color of a bone or the entire skeleton/object (if no bone is specified) (RGBA) ## Metadata diff --git a/doc/ru/vca.md b/doc/ru/vca.md index 79e9eacb9..41db479b5 100644 --- a/doc/ru/vca.md +++ b/doc/ru/vca.md @@ -30,6 +30,7 @@ VCA файл состоит из набора директив, порядок - `@texture` - смена динамически-назначаемой текстуры (см. [skeleton:set_texture](scripting/ecs.md#skeleton)) - `@model` - назначение замены модели кости (см. [skeleton:set_model](scripting/ecs.md#skeleton)) - `@show` - видимость кости или всего скелета / объекта (если не указана кость) +- `@color` - цвет кости или всего скелета / объекта (если не указана кость) (RGBA) ## Мета-информация