mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 14:01:49 +00:00
Merge pull request #992 from MihailRis/remove-explicit-multiplier-from-vca
make VCA animation line intensity multiplier implicit
This commit is contained in:
commit
9ca0b5154d
4 changed files with 26 additions and 9 deletions
|
|
@ -97,6 +97,9 @@ local PlayingTrack = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function this.play(name, target)
|
function this.play(name, target)
|
||||||
|
if target and target.reset_pose then
|
||||||
|
target:reset_pose()
|
||||||
|
end
|
||||||
local track = setmetatable({
|
local track = setmetatable({
|
||||||
name = name,
|
name = name,
|
||||||
target = target,
|
target = target,
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,13 @@ local exclude_patters = {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- TODO: replace with actual expression -> lua translator
|
-- TODO: replace with actual expression -> lua translator
|
||||||
local function process_expression(src, memoised)
|
local function process_expression(src, memoised, ismul)
|
||||||
|
if ismul then
|
||||||
|
src = string.format("(%s) * intensity + (1.0 - intensity)", src)
|
||||||
|
else
|
||||||
|
src = string.format("(%s) * intensity", src)
|
||||||
|
end
|
||||||
|
|
||||||
for i, pattern in ipairs(exclude_patters) do
|
for i, pattern in ipairs(exclude_patters) do
|
||||||
if src:find(pattern) then
|
if src:find(pattern) then
|
||||||
debug.print(exclude_patters)
|
debug.print(exclude_patters)
|
||||||
|
|
@ -127,6 +133,11 @@ for _, name in ipairs(math_funcs) do
|
||||||
env[name] = math[name]
|
env[name] = math[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local is_multiplier = {
|
||||||
|
[animation.CH_SCALE] = true,
|
||||||
|
[animation.CH_ZOOM] = true,
|
||||||
|
}
|
||||||
|
|
||||||
local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf)
|
local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf)
|
||||||
local lines = lineset.lines
|
local lines = lineset.lines
|
||||||
local code = ""
|
local code = ""
|
||||||
|
|
@ -137,7 +148,7 @@ local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf)
|
||||||
for i, line in ipairs(lines) do
|
for i, line in ipairs(lines) do
|
||||||
if line.expression then
|
if line.expression then
|
||||||
code = code .. "\n local l" .. i .. " = (" ..
|
code = code .. "\n local l" .. i .. " = (" ..
|
||||||
process_expression(line.expression, memoised) .. ")"
|
process_expression(line.expression, memoised, is_multiplier[line.channel]) .. ")"
|
||||||
elseif line.keys then
|
elseif line.keys then
|
||||||
local target_keysets = keysets[lineset.target_name]
|
local target_keysets = keysets[lineset.target_name]
|
||||||
if not target_keysets then
|
if not target_keysets then
|
||||||
|
|
@ -183,7 +194,6 @@ local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf)
|
||||||
return code
|
return code
|
||||||
end
|
end
|
||||||
|
|
||||||
code = code .. "\n mat4.idt(dst)"
|
|
||||||
if translation[1] or translation[2] or translation[3] then
|
if translation[1] or translation[2] or translation[3] then
|
||||||
code = code .. "\n mat4.translate(dst, {" ..
|
code = code .. "\n mat4.translate(dst, {" ..
|
||||||
(translation[1] and ("l" .. translation[1]) or '0').. ", " ..
|
(translation[1] and ("l" .. translation[1]) or '0').. ", " ..
|
||||||
|
|
@ -215,7 +225,6 @@ end
|
||||||
|
|
||||||
local function codegen_rig_target(raw_track, context)
|
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"
|
|
||||||
for bone, lineset in pairs(raw_track.linesets) do
|
for bone, lineset in pairs(raw_track.linesets) do
|
||||||
if lineset.target_type ~= "bone" and lineset.target_type ~= "texture" then
|
if lineset.target_type ~= "bone" and lineset.target_type ~= "texture" then
|
||||||
goto continue
|
goto continue
|
||||||
|
|
@ -223,10 +232,13 @@ local function codegen_rig_target(raw_track, context)
|
||||||
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
|
||||||
|
.. 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" then
|
||||||
code = code ..
|
code = code ..
|
||||||
" target:set_matrix(target:index(" .. string.escape(bone) .. "), dst)\n"
|
" target:set_matrix(bone_index, dst)\n"
|
||||||
end
|
end
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
|
|
@ -290,7 +302,7 @@ function internals.compile_animation_track(raw_track, track_name)
|
||||||
code = memoised_code .. "\n" .. code
|
code = memoised_code .. "\n" .. code
|
||||||
end
|
end
|
||||||
|
|
||||||
local src = "return function(target, t, m)\n"
|
local src = "return function(target, t, intensity, m)\n m = m or 1\n"
|
||||||
.. code .. "\nend"
|
.. code .. "\nend"
|
||||||
|
|
||||||
if animation.TRACE_CODEGEN then
|
if animation.TRACE_CODEGEN then
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ function set_state(name, fade_time)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update(delta)
|
local function update(delta)
|
||||||
|
rig:reset_pose()
|
||||||
for _, state in pairs(states) do
|
for _, state in pairs(states) do
|
||||||
state.timer = state.timer + delta
|
state.timer = state.timer + delta
|
||||||
|
|
||||||
|
|
@ -51,7 +52,7 @@ local function update(delta)
|
||||||
end
|
end
|
||||||
|
|
||||||
state.track = state.track or animation.get_track(state.track_id)
|
state.track = state.track or animation.get_track(state.track_id)
|
||||||
if state.track and intensity > 0.0 then
|
if state.track then
|
||||||
state.track.func(
|
state.track.func(
|
||||||
rig,
|
rig,
|
||||||
state.timer % math.min(MAX_DURATION, state.track.duration),
|
state.timer % math.min(MAX_DURATION, state.track.duration),
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@ class Time {
|
||||||
uint64_t frame = 0;
|
uint64_t frame = 0;
|
||||||
double lastTime = 0.0;
|
double lastTime = 0.0;
|
||||||
double delta = 0.0;
|
double delta = 0.0;
|
||||||
|
double timeMultiplier = 1.0;
|
||||||
public:
|
public:
|
||||||
Time() {}
|
Time() {}
|
||||||
|
|
||||||
void update(double currentTime) {
|
void update(double currentTime) {
|
||||||
frame++;
|
frame++;
|
||||||
delta = currentTime - lastTime;
|
delta = (currentTime - lastTime) * timeMultiplier;
|
||||||
lastTime = currentTime;
|
lastTime = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue