diff --git a/res/modules/animation.lua b/res/modules/animation.lua index 411623364..1e19822a4 100644 --- a/res/modules/animation.lua +++ b/res/modules/animation.lua @@ -97,6 +97,9 @@ local PlayingTrack = { } function this.play(name, target) + if target and target.reset_pose then + target:reset_pose() + end local track = setmetatable({ name = name, target = target, diff --git a/res/modules/internal/animation_codegen.lua b/res/modules/internal/animation_codegen.lua index 50ae8a5a0..a8fabab8e 100644 --- a/res/modules/internal/animation_codegen.lua +++ b/res/modules/internal/animation_codegen.lua @@ -194,7 +194,6 @@ local function codegen_track(raw_track, lineset, memoised, keysets, use_tsf) return code end - code = code .. "\n mat4.idt(dst)" if translation[1] or translation[2] or translation[3] then code = code .. "\n mat4.translate(dst, {" .. (translation[1] and ("l" .. translation[1]) or '0').. ", " .. @@ -226,7 +225,6 @@ end local function codegen_rig_target(raw_track, context) 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 if lineset.target_type ~= "bone" and lineset.target_type ~= "texture" then goto continue @@ -234,10 +232,13 @@ local function codegen_rig_target(raw_track, context) local lineset_code = codegen_track( 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 code = code .. - " target:set_matrix(target:index(" .. string.escape(bone) .. "), dst)\n" + " target:set_matrix(bone_index, dst)\n" end ::continue:: end diff --git a/res/scripts/components/animator.lua b/res/scripts/components/animator.lua index 611ffa6f8..341f7cf11 100644 --- a/res/scripts/components/animator.lua +++ b/res/scripts/components/animator.lua @@ -38,6 +38,7 @@ function set_state(name, fade_time) end local function update(delta) + rig:reset_pose() for _, state in pairs(states) do state.timer = state.timer + delta @@ -51,7 +52,7 @@ local function update(delta) end 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( rig, state.timer % math.min(MAX_DURATION, state.track.duration),