Skip to content

Commit

Permalink
cleanup keyframe animation
Browse files Browse the repository at this point in the history
  • Loading branch information
aimoonchen committed Jan 19, 2024
1 parent 2e3c1bf commit a96ec26
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 61 deletions.
2 changes: 1 addition & 1 deletion tools/editor/pkg/tools.editor/gui_system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function m:handle_event()
if e.slot then
hierarchy:update_slot_list(world)
end
prefab_mgr:on_patch_tag(target, v1, v2)
prefab_mgr:on_patch_tag(target, v1, v2, false, true)
end
elseif what == "parent" then
target = prefab_mgr:set_parent(target, v1)
Expand Down
47 changes: 14 additions & 33 deletions tools/editor/pkg/tools.editor/prefab_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ function m:on_prefab_ready(prefab)
self:on_patch_tag(v[2], nil, tpl.tag, true)
end
end
self:update_tag_list()
anim_view.on_prefab_load(anim_eid)
end

Expand Down Expand Up @@ -1004,45 +1005,23 @@ function m:set_parent(target, parent)
end
end

function m:update_efk_tag(eid)
local e <close> = world:entity(eid, "efk?in")
if e.efk then
local tag = self.current_prefab.tag
if ov and tag[ov] then
tag[ov] = nil
end
tag[nv] = {eid}
end
end

function m:get_efk_list()
local list = {}
for k, value in pairs(self.current_prefab.tag) do
if k ~= "*" and k ~= "anim_ctrl" then
for _, eid in ipairs(value) do
local ee <close> = world:entity(eid, "efk?in")
if ee.efk then
list[#list + 1] = k
end
end
end
end
return list
end

function m:get_srt_mtl_list()
local list = {}
function m:update_tag_list()
local srt_mtl_list = {""}
local efk_list = {}
for k, value in pairs(self.current_prefab.tag) do
if k ~= "*" and k ~= "anim_ctrl" then
for _, eid in ipairs(value) do
local ee <close> = world:entity(eid, "scene?in material?in")
if ee.scene or ee.material then
list[#list + 1] = k
srt_mtl_list[#srt_mtl_list + 1] = k
elseif ee.efk then
efk_list[#efk_list + 1] = k
end
end
end
end
return list
self.efk_list = efk_list
self.srt_mtl_list = srt_mtl_list
end

function m:do_remove_entity(eid)
Expand Down Expand Up @@ -1170,7 +1149,7 @@ end
function m:pacth_remove(eid)
local name = hierarchy:get_node_info(eid).template.tag[1]
self.current_prefab.tag[name] = nil
anim_view.update_tag_list()
self:update_tag_list()
if not self.glb_filename then
return true
end
Expand Down Expand Up @@ -1380,7 +1359,7 @@ function m:do_patch(eid, path, v, origin_tag)
self:pacth_modify(info.template.index, path, v, origin_tag)
end

function m:on_patch_tag(eid, ov, nv, origin_tag)
function m:on_patch_tag(eid, ov, nv, origin_tag, update_tag)
if not self.current_prefab then
return
end
Expand All @@ -1392,7 +1371,9 @@ function m:on_patch_tag(eid, ov, nv, origin_tag)
if #nv > 0 then
tag[nv[1]] = {eid}
end
anim_view.update_tag_list()
if update_tag then
self:update_tag_list()
end
end

function m:on_patch_tranform(eid, n, v)
Expand Down
12 changes: 2 additions & 10 deletions tools/editor/pkg/tools.editor/widget/animation_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ local fmod = require "fmod"
local edit_timeline
local timeline_eid
local timeline_playing = false
local efk_tag_list = {}
local srt_tag_list = {}
local mtl_tag_list = {}
local srt_mtl_list = {}
local m = {}
local edit_anims
local anim_eid
Expand Down Expand Up @@ -391,7 +389,7 @@ local function show_current_event()
end
action_list = current_event.action_list or {}
end
action_list = (current_event.event_type == "Effect") and efk_tag_list or (#action_list > 0 and action_list or (edit_anims and edit_anims.name_list or {}))
action_list = (current_event.event_type == "Effect") and prefab_mgr.efk_tag_list or (#action_list > 0 and action_list or (edit_anims and edit_anims.name_list or {}))
if #action_list > 0 then
local action = current_event.action or ''
ImGui.PropertyLabel("Action")
Expand All @@ -409,7 +407,7 @@ local function show_current_event()
local target = current_event.target or ''
ImGui.PropertyLabel("Target")
if ImGui.BeginCombo("##Target", {target, flags = ImGui.Flags.Combo {}}) then
for _, name in ipairs(srt_mtl_list) do
for _, name in ipairs(prefab_mgr.srt_mtl_list) do
if ImGui.Selectable(name, target == name) then
current_event.target = name
end
Expand Down Expand Up @@ -887,7 +885,6 @@ function m.show()
end

function m.on_prefab_load(eid)
m.update_tag_list()
if not eid then
return
end
Expand Down Expand Up @@ -974,11 +971,6 @@ function m.on_target(eid)
end
end

function m.update_tag_list()
efk_tag_list = prefab_mgr:get_efk_list()
srt_mtl_list = prefab_mgr:get_srt_mtl_list()
end

function m.update_anim_namelist()
-- efk_tag_list = namelist
end
Expand Down
47 changes: 30 additions & 17 deletions tools/editor/pkg/tools.editor/widget/keyframe_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ local utils = require "common.utils"
local m = {}
local current_mtl
local current_uniform
local current_bind_eid
local file_path
local joints_map
local joints_list
Expand All @@ -40,6 +39,7 @@ local sample_ratio = 30.0
local anim_eid
local current_joint
local current_anim
local anim_bind_map = {}
local allanims = {}
local anim_name_list = {}
local create_context = {}
Expand Down Expand Up @@ -249,10 +249,12 @@ local function update_animation()
imodifier.delete(anim.modifier)
anim.modifier = nil
if #keyframes > 0 then
local bind_eid = prefab_mgr.get_eid_by_name[anim_bind_map[current_anim.name]]
assert(bind_eid)
if anim_type == "mtl" then
anim.modifier = imodifier.create_mtl_modifier(current_bind_eid, anim.target_name, keyframes, false, true)
anim.modifier = imodifier.create_mtl_modifier(bind_eid, anim.target_name, keyframes, false, true)
elseif anim_type == "srt" then
anim.modifier = imodifier.create_srt_modifier(current_bind_eid, 0, keyframes, false, true)
anim.modifier = imodifier.create_srt_modifier(bind_eid, 0, keyframes, false, true)
end
end
::continue::
Expand Down Expand Up @@ -816,9 +818,9 @@ local function create_animation(animtype, name, duration, target_anims)
for _, desc in ipairs(create_context.desc) do
get_or_create_target_anim(desc.target, desc.init_value)
end
current_bind_eid = create_context.bind_eid
create_context = nil
end
anim_bind_map[name] = ""
end
end
local update_camera_mb = world:sub {"UpdateCamera"}
Expand Down Expand Up @@ -902,7 +904,7 @@ function m.clear(keep_skel)
current_anim = nil
current_joint = nil
current_uniform = nil
current_bind_eid = nil
anim_bind_map = {}
current_mtl = nil
if not keep_skel then
anim_eid = nil
Expand Down Expand Up @@ -978,34 +980,28 @@ function m.show()
ImGui.SetNextWindowSize(viewport.WorkSize[1], uiconfig.BottomWidgetHeight, 'F')
if ImGui.Begin("Skeleton", ImGui.Flags.Window { "NoCollapse", "NoScrollbar", "NoClosed" }) then
if current_skeleton and not current_anim then
if ImGui.Button(faicons.ICON_FA_FILE_PEN.." SkeAnim") then
if ImGui.Button(faicons.ICON_FA_FILE_PEN.." ske") then
new_anim_widget = true
end
ImGui.SameLine()
end
local current_eid = gizmo.target_eid
if current_eid then
local e <close> = world:entity(current_eid, "scene?in material?in")
-- current_anim.target_anims
-- local tpl = hierarchy:get_node_info(current_target).template
-- local name = tpl.tag and tpl.tag[1] or ""
-- target_map[name] = current_target
if e.scene then
if ImGui.Button(faicons.ICON_FA_FILE_PEN.." SRTAnim") then
if ImGui.Button(faicons.ICON_FA_FILE_PEN.." srt") then
new_anim_widget = true
create_context = {
bind_eid = current_eid,
type = "srt",
desc = {}
}
end
ImGui.SameLine()
end
if e.material then
if ImGui.Button(faicons.ICON_FA_FILE_PEN.." MTLAnim") then
if ImGui.Button(faicons.ICON_FA_FILE_PEN.." mtl") then
new_anim_widget = true
create_context = {
bind_eid = current_eid,
type = "mtl",
}
local mtlpath = e.material
Expand Down Expand Up @@ -1043,9 +1039,11 @@ function m.show()
if ImGui.Button(faicons.ICON_FA_FLOPPY_DISK.." Save") then
m.save(file_path)
end
ImGui.SameLine()
ImGui.Text("Mode: "..current_anim.type)
-- ImGui.SameLine()
-- ImGui.Text("Mode: "..current_anim.type)
if #anim_name_list > 0 then
ImGui.SameLine()
ImGui.Text("Anim:")
ImGui.SameLine()
ImGui.PushItemWidth(150)
if ImGui.BeginCombo("##AnimList", {current_anim.name, flags = ImGui.Flags.Combo {}}) then
Expand All @@ -1064,6 +1062,22 @@ function m.show()
end
ImGui.PopItemWidth()
end
if current_anim.type ~= "ske" then
ImGui.SameLine()
ImGui.Text("BindTo:")
ImGui.SameLine()
ImGui.PushItemWidth(200)
if ImGui.BeginCombo("##BindTo", {anim_bind_map[current_anim.name], flags = ImGui.Flags.Combo {}}) then
for _, name in ipairs(prefab_mgr.srt_mtl_list) do
if ImGui.Selectable(name, anim_bind_map[current_anim.name] == name) then
anim_bind_map[current_anim.name] = name
update_animation()
end
end
ImGui.EndCombo()
end
ImGui.PopItemWidth()
end
ImGui.SameLine()
if ImGui.Checkbox("all ", ui_playall) then
anim_set_loop(ui_playall[1])
Expand Down Expand Up @@ -1332,7 +1346,6 @@ function m.load(path_str)
end
create_animation(anim.type, anim.name, math.floor(anim.duration * sample_ratio), anim.target_anims)
sample_ratio = anim.sample_ratio
current_bind_eid = gizmo.target_eid
update_animation()
end
file_path = path:string()
Expand Down

0 comments on commit a96ec26

Please sign in to comment.