Onionskin: Pivot Path and Only Selected Item

Pivot Path draws, on the preview, the path each item's pivot travels:
a red point per frame joined by a red dashed line (Canvas::line_render,
on the dashed shader). Only Selected Item limits the onionskin samples
and pivot paths to the selected root, group root, layer or null. Paths
are cached until the document, animation or root-transform view changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 20:58:39 -04:00
1 parent 993957decf
commit 24af98a68e
7 files changed
+109 -5

No files matched your search

+22 -5
View File
@@ -243,17 +243,17 @@ namespace anm2ed
glUniform4fv(glGetUniformLocation(shader.id, shader::UNIFORM_COLOR), 1, value_ptr(color));
}
void rect_end(GLuint vao, GLenum mode)
void rect_end(GLuint vao, GLenum mode, int count = 4)
{
glBindVertexArray(vao);
glDrawArrays(mode, 0, 4);
glDrawArrays(mode, 0, count);
glBindVertexArray(0);
glUseProgram(0);
canvas_blend_straight_set();
}
void Canvas::rect_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color, float dashLength,
float dashGap, float dashOffset) const
void Canvas::dashed_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color, float dashLength,
float dashGap, float dashOffset, GLenum mode, int count) const
{
rect_begin(shader, transform, model, color);
@@ -267,7 +267,24 @@ namespace anm2ed
std::pair{shader::UNIFORM_DASH_OFFSET, dashOffset}})
if (auto location = glGetUniformLocation(shader.id, name); location != -1) glUniform1f(location, value);
rect_end(rectVAO, GL_LINE_LOOP);
rect_end(rectVAO, mode, count);
}
void Canvas::rect_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color, float dashLength,
float dashGap, float dashOffset) const
{
dashed_render(shader, transform, model, color, dashLength, dashGap, dashOffset, GL_LINE_LOOP, RECT_VERTEX_COUNT);
}
// A line from start to end: the bottom edge of a rectangle laid along it.
void Canvas::line_render(Shader& shader, const mat4& transform, vec2 start, vec2 end, vec4 color, float dashLength,
float dashGap, float dashOffset) const
{
auto direction = end - start;
auto normal = glm::length(direction) > 0.0f ? glm::normalize(vec2(-direction.y, direction.x)) : vec2(0.0f, 1.0f);
auto model = mat4(vec4(direction, 0.0f, 0.0f), vec4(normal, 0.0f, 0.0f), vec4(0.0f, 0.0f, 1.0f, 0.0f),
vec4(start, 0.0f, 1.0f));
dashed_render(shader, transform, model, color, dashLength, dashGap, dashOffset, GL_LINES, LINE_VERTEX_COUNT);
}
void Canvas::rect_fill_render(Shader& shader, const mat4& transform, const mat4& model, vec4 color) const
+6
View File
@@ -37,6 +37,8 @@ namespace anm2ed
static constexpr float AXIS_VERTICES[] = {-1.0f, 0.0f, 1.0f, 0.0f};
static constexpr float GRID_VERTICES[] = {-1.f, -1.f, 0.f, 0.f, 3.f, -1.f, 2.f, 0.f, -1.f, 3.f, 0.f, 2.f};
static constexpr float RECT_VERTICES[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f};
static constexpr int RECT_VERTEX_COUNT = 4;
static constexpr int LINE_VERTEX_COUNT = 2;
static constexpr GLuint TEXTURE_INDICES[] = {0, 1, 2, 2, 3, 0};
static constexpr auto BORDER_DASH_LENGTH = 1.0f;
static constexpr auto BORDER_DASH_GAP = 0.5f;
@@ -63,8 +65,12 @@ namespace anm2ed
void texture_render(resource::Shader&, GLuint, glm::mat4 = {1.0f}, glm::vec4 = glm::vec4(1.0f), glm::vec3 = {},
float* = (float*)TEXTURE_VERTICES, glm::vec2 = {}, float = 0.0f) const;
void rect_fill_render(resource::Shader&, const glm::mat4&, const glm::mat4&, glm::vec4 = glm::vec4(1.0f)) const;
void dashed_render(resource::Shader&, const glm::mat4&, const glm::mat4&, glm::vec4, float, float, float, GLenum,
int) const;
void rect_render(resource::Shader&, const glm::mat4&, const glm::mat4&, glm::vec4 = glm::vec4(1.0f),
float dashLength = DASH_LENGTH, float dashGap = DASH_GAP, float dashOffset = DASH_OFFSET) const;
void line_render(resource::Shader&, const glm::mat4&, glm::vec2, glm::vec2, glm::vec4 = glm::vec4(1.0f),
float dashLength = DASH_LENGTH, float dashGap = DASH_GAP, float dashOffset = DASH_OFFSET) const;
float zoom_level_get(float, int) const;
void zoom_level_adjust(float&, glm::vec2&, glm::vec2, int) const;
glm::vec2 position_translate(float&, glm::vec2&, glm::vec2) const;
+56
View File
@@ -285,6 +285,7 @@ namespace anm2ed::imgui
auto& shaderAxes = resources.shaders[shader::AXIS];
auto& shaderGrid = resources.shaders[shader::GRID];
auto& shaderTexture = resources.shaders[shader::TEXTURE];
auto& shaderDashed = resources.shaders[shader::DASHED];
auto center_view = [&]() { pan = vec2(); };
auto fit_view = [&]()
@@ -646,6 +647,24 @@ namespace anm2ed::imgui
std::ranges::any_of(document.frame_references_get(Document::FrameReferenceFallback::NONE), is_layer);
};
// The item the reference points at: the root (or a group's root), a layer or a null.
auto is_draw_selected = [&](const model::Draw& draw)
{
switch (draw.type)
{
case model::DrawType::ROOT:
return referenceItemType == ItemType::ROOT && reference.groupId == -1;
case model::DrawType::GROUP_ROOT:
return referenceItemType == ItemType::ROOT && reference.groupType == draw.groupType &&
reference.groupId == draw.id;
case model::DrawType::LAYER:
return referenceItemType == ItemType::LAYER && reference.itemID == draw.id;
default:
return referenceItemType == ItemType::NULL_ && reference.itemID == draw.id;
}
};
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)
{
@@ -655,6 +674,7 @@ namespace anm2ed::imgui
for (const auto& draw : model::animation_draws_get(sampleModel, sampleAnimation, drawOptions))
{
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);
@@ -734,6 +754,42 @@ namespace anm2ed::imgui
if (overlayDrawOrder == overlay_draw_order::UNDER) overlay_render();
render(document, *animation, 0.0f);
if (overlayDrawOrder == overlay_draw_order::OVER) overlay_render();
if (settings.onionskinIsEnabled && settings.onionskinIsPivotPath && !isIsolated)
{
auto key = std::tuple{document.hash, reference.animationIndex, isRootTransform};
if (key != pivotPathsKey || pivotPaths.empty())
{
pivotPathsKey = key;
pivotPaths.clear();
for (int time = 0; time < animation->frameNum; ++time)
for (const auto& draw : model::animation_draws_get(
model, *animation, {.time = (float)time, .isRootTransform = isRootTransform}))
{
auto path = std::ranges::find_if(pivotPaths,
[&](const PivotPath& path)
{
return path.item.type == draw.type && path.item.id == draw.id &&
path.item.groupType == draw.groupType;
});
if (path == pivotPaths.end()) path = pivotPaths.insert(pivotPaths.end(), {.item = draw});
path->points.push_back(vec2(draw.parent * vec4(draw.frame.position, 0.0f, 1.0f)));
}
}
auto pointIcon = resources.icon_id_get(icon::POINT);
for (const auto& path : pivotPaths)
{
if (isOnlySelected && !is_draw_selected(path.item)) continue;
for (std::size_t i = 0; i < path.points.size(); ++i)
{
if (i > 0) line_render(shaderDashed, baseTransform, path.points[i - 1], path.points[i], color::RED);
texture_render(shaderTexture, pointIcon,
baseTransform * math::quad_model_get(POINT_SIZE, path.points[i], POINT_SIZE * 0.5f),
color::RED);
}
}
}
}
if (isRecordingFrame)
+13
View File
@@ -1,8 +1,12 @@
#pragma once
#include <tuple>
#include <vector>
#include "audio_stream.hpp"
#include "canvas_view.hpp"
#include "manager.hpp"
#include "model/draw.hpp"
#include "render.hpp"
#include "resources.hpp"
#include "settings.hpp"
@@ -22,6 +26,15 @@ namespace anm2ed::imgui
glm::vec2 recordPan{};
float recordZoom{};
// Where each item's pivot is at every frame of the animation, kept until the document or view changes.
struct PivotPath
{
model::Draw item{};
std::vector<glm::vec2> points{};
};
std::vector<PivotPath> pivotPaths{};
std::tuple<std::uint64_t, int, bool> pivotPathsKey{};
void recording_start(Manager&, Settings&, Document&, const model::Animation*);
void recording_stop(Manager&, Document&);
+6
View File
@@ -47,6 +47,12 @@ namespace anm2ed::imgui
ImGui::SameLine();
ImGui::RadioButton(localize.get(BASIC_INDEX), &mode, (int)OnionskinMode::INDEX);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ONIONSKIN_INDEX));
ImGui::SeparatorText(localize.get(LABEL_OPTIONS));
ImGui::Checkbox(localize.get(LABEL_PIVOT_PATH), &settings.onionskinIsPivotPath);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_PIVOT_PATH));
ImGui::Checkbox(localize.get(LABEL_ONLY_SELECTED_ITEM), &settings.onionskinIsOnlySelected);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ONLY_SELECTED_ITEM));
}
ImGui::End();
+4
View File
@@ -253,6 +253,8 @@ namespace anm2ed
X(LABEL_ANIMATIONS_CHILD, "Animations", "Animaciones", "", "动画", "애니메이션") \
X(LABEL_ANIMATIONS_MERGE_POPUP, "Merge Animations", "Combinar Animaciones", "Соединить анимации", "合并多个动画", "애니메이션 병합") \
X(LABEL_AUTO_SPRITESHEET_RELOAD, "Auto Spritesheet Reload", "Recarga Automática de Spritesheets", "Автоперезагрузка спрайт-листов", "自动重新加载图集", "스프라이트 시트 자동 새로고침") \
X(LABEL_ONLY_SELECTED_ITEM, "Only Selected Item", "Solo el Elemento Seleccionado", "Только выбранный элемент", "仅选中项目", "선택한 항목만") \
X(LABEL_PIVOT_PATH, "Pivot Path", "Trayectoria del Pivote", "Путь опорной точки", "枢轴路径", "피벗 경로") \
X(LABEL_SPRITESHEETS_PACK_POPUP, "Pack Spritesheet", "Empaquetar spritesheet", "Упаковать спрайт-лист", "打包图集", "스프라이트 시트 패킹") \
X(LABEL_SPRITESHEETS_MERGE_POPUP, "Merge Spritesheets", "Combinar Spritesheets", "Объединить спрайт-листы", "合并图集", "스프라이트 시트 병합") \
X(LABEL_PACK_PADDING, "Padding", "Relleno", "Отступ", "填充", "패딩") \
@@ -616,6 +618,8 @@ namespace anm2ed
X(TOOLTIP_CENTER_VIEW, "Centers the view.", "Centra la vista.", "Центрирует вид.", "居中视角.", "미리보기 화면을 가운데에 맞춥니다.") \
X(TOOLTIP_CLOSE_SETTINGS, "Close without updating settings.", "Cerrar sin actualizar las configuraciones.", "Закрыть без обновления настройки.", "关闭但不保存设置.", "설정을 갱신하지 않고 닫습니다.") \
X(TOOLTIP_COLOR_OFFSET, "Change the color added onto the frame.", "Cambia el color añadido al Frame.", "Изменить цвет, который добавлен на кадр.", "更改覆盖在帧上的颜色.", "프레임에 더해지는 색을 변경합니다.") \
X(TOOLTIP_ONLY_SELECTED_ITEM, "Only the selected item (root, layer or null) is onionskinned and shows its pivot path.", "Solo el elemento seleccionado (raíz, capa o null) usa papel cebolla y muestra la trayectoria de su pivote.", "Оньонскин и путь опорной точки показываются только для выбранного элемента (корень, слой или null).", "仅对选中的项目(根、图层或空节点)显示洋葱皮和枢轴路径。", "선택한 항목(루트, 레이어 또는 널)에만 전후 비교와 피벗 경로를 표시합니다.") \
X(TOOLTIP_PIVOT_PATH, "Show the path each item's pivot travels through the animation, with a dot on every frame.", "Muestra la trayectoria que recorre el pivote de cada elemento durante la animación, con un punto en cada Frame.", "Показать путь опорной точки каждого элемента в анимации, с точкой на каждом кадре.", "显示每个项目的枢轴在动画中移动的路径,每帧一个点。", "애니메이션 동안 각 항목의 피벗이 지나는 경로를 프레임마다 점으로 표시합니다.") \
X(TOOLTIP_REGION, "Set the spritesheet region the frame will use.", "Establece la región del spritesheet que usará el frame.", "Установить регион спрайт-листа, который будет использовать кадр.", "设置帧将使用的图集区域.", "프레임이 사용할 스프라이트 시트 영역을 설정합니다.") \
X(TOOLTIP_FRAME_SHADER, "Set the shader this frame uses. None uses the default shader.", "Set the shader this frame uses. None uses the default shader.", "Set the shader this frame uses. None uses the default shader.", "Set the shader this frame uses. None uses the default shader.", "Set the shader this frame uses. None uses the default shader.") \
X(TOOLTIP_REGION_PROPERTIES_ORIGIN, "Use a preset origin for the region.", "Usa un origen predefinido para la región.", "Использовать предустановленную точку отсчета для региона.", "为区域使用预设原点。", "영역에 사전 설정된 원점을 사용합니다.") \
+2
View File
@@ -198,6 +198,8 @@ namespace anm2ed
X(ONIONSKIN_BEFORE_COLOR, onionskinBeforeColor, STRING_UNDEFINED, VEC3, types::color::RED) \
X(ONIONSKIN_AFTER_COLOR, onionskinAfterColor, STRING_UNDEFINED, VEC3, types::color::BLUE) \
X(ONIONSKIN_MODE, onionskinMode, STRING_UNDEFINED, INT, (int)types::OnionskinMode::TIME) \
X(ONIONSKIN_IS_PIVOT_PATH, onionskinIsPivotPath, STRING_UNDEFINED, BOOL, false) \
X(ONIONSKIN_IS_ONLY_SELECTED, onionskinIsOnlySelected, STRING_UNDEFINED, BOOL, false) \
\
X(TOOL, tool, STRING_UNDEFINED, INT, 0) \
X(TOOL_COLOR, toolColor, STRING_UNDEFINED, VEC4, {1.0, 1.0, 1.0, 1.0}) \