Animation layers in the timeline: child tracks, stepping in, breadcrumb

An animation layer's row shows a folder; opening it lists its child's tracks
underneath, greyed and read only, with each keyframe drawn where the parent
reaches it. Double-clicking the row (or a child row) steps into the child:
its animation in this tab, or its library's tab (opened if need be), at the
time the parent plays it. A breadcrumb above the timeline leads back out, and
the preview draws the parent around the child, dimmed and frozen where it was
stepped in from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-08 18:35:29 -04:00
1 parent 8807096170
commit 0e705e43fa
15 files changed
+402 -20

No files matched your search

+34 -8
View File
@@ -41,6 +41,7 @@ namespace anm2ed::imgui
constexpr auto NULL_RECT_COLOR = vec4(0.0f, 0.0f, 1.0f, 0.90f);
constexpr auto SELECTED_LAYER_BORDER_COLOR = vec4(1.0f, 0.1059f, 0.5882f, 1.0f);
constexpr auto TARGET_SIZE = vec2(32, 32);
constexpr auto PARENT_DIM_ALPHA = 0.65f; // how much a stepped-into child's parent fades
constexpr auto POINT_SIZE = vec2(4, 4);
constexpr auto TRIGGER_TEXT_COLOR_DARK = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
constexpr auto TRIGGER_TEXT_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 0.5f);
@@ -657,23 +658,28 @@ namespace anm2ed::imgui
};
auto isOnlySelected = settings.onionskinIsOnlySelected;
// Draws an animation's draw list; onion-skin samples are tinted and faded, `alphaOffset` fades the overlay.
auto render = [&](Document& sampleDocument, const model::Animation& sampleAnimation, float alphaOffset)
// Draws an animation's draw list; onion-skin samples are tinted and faded, `alphaOffset` fades the overlay. A
// parent around a stepped-into child is drawn in the child's space (`scene`), its layers only, without the
// animation layer playing the child (`skipLayerId`).
auto render = [&](Document& sampleDocument, const model::Animation& sampleAnimation, float alphaOffset,
const model::DrawOptions& options, const mat4& scene = mat4(1.0f), int skipLayerId = -1)
{
auto isActiveDocument = &sampleDocument == &document;
auto isActiveDocument = &sampleDocument == &document && skipLayerId == -1;
auto isParent = skipLayerId != -1;
auto& sampleModel = sampleDocument.model;
auto targetIcon = resources.icon_id_get(isAltIcons && !isIsolated ? icon::TARGET_ALT : icon::TARGET);
auto sampleOptions = drawOptions;
auto sampleOptions = options;
sampleOptions.library_get = sampleDocument.library_resolver_get();
for (const auto& draw : model::animation_draws_get(sampleModel, sampleAnimation, sampleOptions))
{
if (isParent && (draw.type != model::DrawType::LAYER || draw.id == skipLayerId)) continue;
auto isOnion = draw.sample != -1;
if (isOnion && isOnlySelected && !(isActiveDocument && is_draw_selected(draw))) continue;
auto sampleColor = isOnion ? sampleColors[draw.sample] : vec3();
auto sampleAlpha = isOnion ? sampleAlphas[draw.sample] : 0.0f;
auto onionColor = vec4(sampleColor, 1.0f - sampleAlpha);
auto& frame = draw.frame;
auto transform = baseTransform * draw.parent;
auto transform = baseTransform * scene * draw.parent;
auto marker_model_get = [&](vec2 markerSize)
{
return math::quad_model_get(markerSize, frame.position, markerSize * 0.5f,
@@ -708,7 +714,8 @@ namespace anm2ed::imgui
tint.a = std::max(0.0f, tint.a - (alphaOffset + sampleAlpha));
auto customShader = sampleDocument.shader_get(frame.shaderId);
layer_render(customShader ? *customShader : shaderTexture, resource::texture::id_get(*layerTexture),
textureSize, baseTransform, draw, tint, frame.colorOffset + vec4(sampleColor, 0.0f));
textureSize, baseTransform * scene, draw, tint, frame.colorOffset + vec4(sampleColor, 0.0f));
if (isParent) continue;
auto color = isOnion ? onionColor
: isActiveDocument && is_layer_selected(draw.id) ? SELECTED_LAYER_BORDER_COLOR
@@ -740,11 +747,30 @@ namespace anm2ed::imgui
{
if (auto overlayDocument = isIsolated ? nullptr : overlay_animation_document_get(manager, document))
if (auto overlayAnimation = overlayDocument->model.animation_get(overlayIndex))
render(*overlayDocument, *overlayAnimation, 1.0f - math::percent_to_unit(overlayTransparency));
render(*overlayDocument, *overlayAnimation, 1.0f - math::percent_to_unit(overlayTransparency),
drawOptions);
};
// Editing a stepped-into child: its parent, dimmed and frozen where it was stepped in, around it.
if (auto& steps = document.childSteps;
!isIsolated && !steps.empty() && steps.back().childAnimationIndex == reference.animationIndex)
{
auto& step = steps.back();
auto parentIndex = manager.tab_index_get(step.tabId);
auto parentDocument = parentIndex == -1 ? nullptr : manager.get(parentIndex);
auto parentAnimation = parentDocument ? parentDocument->model.animation_get(step.animationIndex) : nullptr;
auto placement = parentAnimation
? model::layer_child_transform_get(parentDocument->model, *parentAnimation,
step.layer.itemID, step.frameTime, isRootTransform)
: std::nullopt;
if (placement && glm::determinant(*placement) != 0.0f)
render(*parentDocument, *parentAnimation, PARENT_DIM_ALPHA,
{.time = step.frameTime, .isRootTransform = isRootTransform}, glm::inverse(*placement),
step.layer.itemID);
}
if (overlayDrawOrder == overlay_draw_order::UNDER) overlay_render();
render(document, *animation, 0.0f);
render(document, *animation, 0.0f, drawOptions);
if (overlayDrawOrder == overlay_draw_order::OVER) overlay_render();
if (settings.onionskinIsEnabled && settings.onionskinIsPivotPath && !isIsolated)
+2 -7
View File
@@ -40,13 +40,8 @@ namespace anm2ed::imgui
{
manager.command_push({.runManager = [path = document.library_path_get(id)](Manager& manager)
{
for (int i = 0; i < (int)manager.documents.size(); ++i)
{
std::error_code ec{};
if (!std::filesystem::equivalent(manager.documents[i].path, path, ec)) continue;
manager.pendingSelected = i;
return manager.set(i);
}
if (auto index = manager.path_index_get(path); index != -1)
return manager.tab_select(index);
manager.open(path);
}});
};
+159
View File
@@ -0,0 +1,159 @@
#include "context.hpp"
// Animation layers in the timeline: their child's tracks under them (read only, timed as the parent plays them),
// stepping into the child, and the breadcrumb back out.
namespace anm2ed::imgui
{
constexpr auto BREADCRUMB_SEPARATOR = ">";
// The child animation's tracks (root, layers top-down, nulls, triggers) when an animation layer row is expanded.
std::vector<PeekRow> TimelineContext::peek_rows_get(const TimelineRow& row)
{
std::vector<PeekRow> rows{};
if (row.isGroup || row.type != LAYER) return rows;
auto track = item_get(LAYER, row.id, row.groupType, row.groupId);
auto layer = model::item_get(model.content.layers, row.id);
if (!track || !layer || !layer->is_animation() || !expandedLayerTracks.contains(track->uid)) return rows;
auto [source, child] = model::child_get(model, *layer, {}, document.library_resolver_get());
if (!child) return rows;
auto row_add = [&](const model::Track& childTrack)
{
if (settings.timelineIsShowUnused || !childTrack.frames.empty()) rows.push_back({source, child, &childTrack});
};
row_add(child->root);
std::vector<const model::Track*> layers{};
model::tracks_each(child->layers, [&](const model::Track& childTrack, auto*) { layers.push_back(&childTrack); });
for (auto it = layers.rbegin(); it != layers.rend(); ++it)
row_add(**it);
model::tracks_each(child->nulls, [&](const model::Track& childTrack, auto*) { row_add(childTrack); });
row_add(child->triggers);
return rows;
}
void TimelineContext::child_step_in(const TimelineRow& row)
{
manager.command_push({.runManager = [index = manager.selected, layer = row_item_reference_get(row)](
Manager& manager) { manager.child_step_in(index, layer); }});
}
void TimelineContext::peek_item_child(const TimelineRow& row, const PeekRow& peek, int index)
{
auto type = (int)peek.track->type;
auto label = std::string(localize.get(TYPE_STRINGS[type]));
if (type == LAYER)
if (auto layer = model::item_get(peek.source->content.layers, peek.track->id)) label = layer_label_get(*layer);
if (type == NULL_)
if (auto null = model::item_get(peek.source->content.nulls, peek.track->id)) label = null->name;
ImGui::PushID(index);
ImGui::PushStyleColor(ImGuiCol_ChildBg, to_imvec4(color_get(COLOR_ITEM_BASE, type) * COLOR_HIDDEN_MULTIPLIER));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding);
if (ImGui::BeginChild("##Peek Item Child", ImVec2(ImGui::GetContentRegionAvail().x, rowFrameChildHeight),
ImGuiChildFlags_Borders, ImGuiWindowFlags_NoScrollWithMouse))
{
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (float)(row.depth + 1) * ImGui::GetTextLineHeightWithSpacing());
ImGui::BeginDisabled();
ImGui::Image(resources.icon_id_get(TYPE_ICONS[type]), icon_size_get());
ImGui::SameLine();
ImGui::TextUnformatted(label.c_str());
ImGui::EndDisabled();
if (ImGui::IsWindowHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) child_step_in(row);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHILD_TRACK));
}
ImGui::EndChild();
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
ImGui::PopID();
}
// The child track's keyframes where the parent reaches them: a run of parent frames showing the same keyframe is one
// cell (a trigger, one cell on the frame it fires).
void TimelineContext::peek_frame_child(const TimelineRow& row, const PeekRow& peek, int& index, float width)
{
ImGui::PushID(index++);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2());
if (ImGui::BeginChild("##Peek Frames Child", ImVec2(width, rowFrameChildHeight), ImGuiChildFlags_Borders) &&
animation)
{
auto drawList = ImGui::GetWindowDrawList();
auto origin = ImGui::GetCursorScreenPos();
auto frameSize = ImVec2(ImGui::GetTextLineHeight(), ImGui::GetContentRegionAvail().y);
auto track = item_get(LAYER, row.id, row.groupType, row.groupId);
auto layer = model::item_get(model.content.layers, row.id);
auto type = (int)peek.track->type;
auto isTrigger = type == TRIGGER;
auto color = ImGui::GetColorU32(to_imvec4(color_get(COLOR_FRAME_BASE, type) * COLOR_HIDDEN_MULTIPLIER));
auto libraryGet = document.library_resolver_get();
auto key_get = [&](int time)
{
auto frame = model::frame_generate(*track, (float)time);
if (!frame.isVisible || model::child_get(model, *layer, frame, libraryGet).second != peek.child) return -1;
auto childTime = model::child_time_get(*track, (float)time, peek.child->frameNum, layer->id);
return isTrigger ? model::frame_index_from_at_frame_get(*peek.track, (int)childTime)
: model::frame_index_from_time_get(*peek.track, childTime);
};
auto cell_draw = [&](int start, int end, int key)
{
auto min = ImVec2(origin.x + frameSize.x * (float)start, origin.y);
auto max = ImVec2(origin.x + frameSize.x * (float)end, origin.y + frameSize.y);
drawList->AddRectFilled(min, max, color, FRAME_ROUNDING);
drawList->AddRect(min, max, ImGui::GetColorU32(frameBorderColor), FRAME_ROUNDING);
auto icon = isTrigger ? icon::TRIGGER : INTERPOLATION_ICONS[(int)peek.track->frames[key].interpolation];
auto iconSize = icon_size_get();
auto iconMin = ImVec2(min.x, origin.y + (frameSize.y - iconSize.y) / 2);
drawList->AddImage((ImTextureID)(intptr_t)resources.icon_id_get(icon), iconMin,
ImVec2(iconMin.x + iconSize.x, iconMin.y + iconSize.y), ImVec2(0, 0), ImVec2(1, 1),
ImGui::GetColorU32(iconTintDefault));
};
int runStart{};
int runKey{-1};
for (int time = 0; time <= animation->frameNum; ++time)
{
auto key = time < animation->frameNum && track && layer ? key_get(time) : -1;
if (key == runKey) continue;
if (runKey != -1 && !isTrigger) cell_draw(runStart, time, runKey);
if (key != -1 && isTrigger) cell_draw(time, time + 1, key);
runStart = time;
runKey = key;
}
if (ImGui::IsWindowHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) child_step_in(row);
}
ImGui::EndChild();
ImGui::PopStyleVar();
ImGui::PopID();
}
// Where the animation being edited was stepped into from: each step leads back.
void TimelineContext::breadcrumb_draw()
{
auto& steps = document.childSteps;
if (!steps.empty() && steps.back().childAnimationIndex != reference.animationIndex) steps.clear();
if (steps.empty()) return;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing);
ImGui::SetCursorPos(ImVec2(style.WindowPadding.x, ImGui::GetCursorPosY() + style.ItemSpacing.y));
auto crumb_draw = [&](const std::string& label, int stepIndex)
{
ImGui::PushID(stepIndex);
if (ImGui::SmallButton(label.c_str()))
manager.command_push({.runManager = [index = manager.selected, stepIndex](Manager& manager)
{ manager.child_step_out(index, stepIndex); }});
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_STEP_OUT));
ImGui::PopID();
ImGui::SameLine();
ImGui::TextUnformatted(BREADCRUMB_SEPARATOR);
ImGui::SameLine();
};
crumb_draw(steps.front().animationName, 0);
for (int i = 0; i + 1 < (int)steps.size(); ++i)
crumb_draw(steps[i].layerName, i + 1);
ImGui::TextUnformatted(steps.back().layerName.c_str());
ImGui::PopStyleVar(2);
}
}
+13
View File
@@ -137,6 +137,14 @@ namespace anm2ed::imgui
resource::icon::EASE_IN, resource::icon::EASE_OUT,
resource::icon::EASE_IN_OUT};
// A read-only row under an expanded animation layer: one track of the child animation it plays.
struct PeekRow
{
const model::Model* source{};
const model::Animation* child{};
const model::Track* track{};
};
Reference row_item_reference_get(const TimelineRow&);
Reference row_selection_reference_get(const TimelineRow&);
@@ -254,6 +262,11 @@ namespace anm2ed::imgui
void group_properties_open(const TimelineRow& row, const model::TrackGroup& group);
void group_properties_update();
void item_context_menu();
std::vector<PeekRow> peek_rows_get(const TimelineRow&);
void peek_item_child(const TimelineRow&, const PeekRow&, int);
void peek_frame_child(const TimelineRow&, const PeekRow&, int&, float);
void child_step_in(const TimelineRow&);
void breadcrumb_draw();
TimelineContext(TimelineState&&, Manager&, Settings&, Resources&, Clipboard&);
void update();
+8
View File
@@ -732,7 +732,15 @@ namespace anm2ed::imgui
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f);
for (const auto& row : timeline_item_rows_get())
{
frames_child_row(row);
for (const auto& peek : peek_rows_get(row))
{
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
peek_frame_child(row, peek, index, childWidth);
}
}
ImGui::PopStyleVar();
}
+1
View File
@@ -47,6 +47,7 @@ namespace anm2ed::imgui
{
isWindowHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows |
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);
breadcrumb_draw();
frames_child();
items_child();
}
+1
View File
@@ -162,6 +162,7 @@ namespace anm2ed::imgui
std::optional<Reference> frameSelectionAnchor{};
int animationLengthEditIndex{-1};
std::vector<TimelineRow> rowDragReferences{};
std::set<std::uint64_t> expandedLayerTracks{}; // animation layer tracks (by uid) showing their child's tracks
glm::vec2 scroll{};
ImGuiStyle style{};
};
+27 -1
View File
@@ -269,10 +269,12 @@ namespace anm2ed::imgui
}
}
auto animationLayer = type == LAYER ? model::item_get(model.content.layers, id) : nullptr;
if (animationLayer && !animationLayer->is_animation()) animationLayer = nullptr;
if (isItemButtonHovered)
{
if (ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
item_base_properties_open(type, id);
animationLayer ? child_step_in(row) : item_base_properties_open(type, id);
else if (ImGui::IsMouseReleased(ImGuiMouseButton_Left) &&
!ImGui::IsMouseDragPastThreshold(ImGuiMouseButton_Left))
row_selection_set(row);
@@ -370,7 +372,23 @@ namespace anm2ed::imgui
contentCursorPos.x += (float)row.depth * ImGui::GetTextLineHeightWithSpacing();
ImGui::SetCursorPos(contentCursorPos);
// An animation layer's icon is a folder that shows (or hides) its child's tracks.
auto isExpanded = item && expandedLayerTracks.contains(item->uid);
if (animationLayer) icon = isExpanded ? icon::FOLDER_OPEN : icon::FOLDER;
ImGui::Image(resources.icon_id_get(icon), icon_size_get());
auto mousePos = ImGui::GetIO().MousePos;
auto iconMin = ImGui::GetItemRectMin();
auto iconMax = ImGui::GetItemRectMax();
auto isIconHovered =
mousePos.x >= iconMin.x && mousePos.x < iconMax.x && mousePos.y >= iconMin.y && mousePos.y < iconMax.y;
if (animationLayer && isItemButtonHovered && isIconHovered && ImGui::IsMouseReleased(ImGuiMouseButton_Left) &&
!ImGui::IsMouseDragPastThreshold(ImGuiMouseButton_Left))
{
if (isExpanded)
expandedLayerTracks.erase(item->uid);
else
expandedLayerTracks.insert(item->uid);
}
overlay_icon(resources.icon_id_get(icon), iconTintCurrent, false);
ImGui::SameLine();
if (isReferenced) ImGui::PushFont(resources.fonts[font::ITALICS].get(), font::SIZE);
@@ -546,7 +564,15 @@ namespace anm2ed::imgui
item_child_row({.type = NONE}, index++);
if (animation)
for (const auto& row : timeline_item_rows_get())
{
item_child_row(row, index++);
for (const auto& peek : peek_rows_get(row))
{
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
peek_item_child(row, peek, index++);
}
}
if (isHorizontalScroll && ImGui::GetCurrentWindow()->ScrollbarY)
{