Layer frame depth: change a layer's draw order for part of an animation

Layer frames get an editor-only Depth (Frame Properties, property
copy/paste): +N draws that layer N layers above its place in the timeline
for that frame, -N below; stepped, not interpolated. The draw list orders
layers by it (preview, renders, CLI). Saved as Depth in the editor's copy
only; the Isaac Compatibility Warning and anm2ed info count frames using it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-06 01:21:50 -04:00
1 parent 94d0bbf206
commit f3fb7d5101
13 files changed
+78 -6

No files matched your search

+1
View File
@@ -92,6 +92,7 @@ namespace anm2ed
inline constexpr int FRAME_NUM_MAX = FRAME_DURATION_MAX;
inline constexpr int FPS_MIN = 1;
inline constexpr int FPS_MAX = 120;
inline constexpr int FRAME_DEPTH_MAX = 100;
enum class SpritesheetMergeOrigin
{
+20
View File
@@ -1,5 +1,7 @@
#include "draw.hpp"
#include <algorithm>
#include "frames.hpp"
#include "math.hpp"
@@ -40,6 +42,10 @@ namespace anm2ed::model
std::vector<Draw> animation_draws_get(const Model& model, const Animation& animation, const DrawOptions& options)
{
std::vector<Draw> draws{};
// Each layer draw's place in the drawing order: its track's position among the layers plus its frame's depth; a
// moved layer lands past the one already at that place (below it when moved down, above it when moved up).
std::vector<std::pair<int, int>> layerOrders{};
int layerOrder{};
auto parent_get = [&](float time, const TrackGroup* group)
{
glm::mat4 parent(1.0f);
@@ -67,6 +73,7 @@ namespace anm2ed::model
frame.colorOffset += rootFrame.colorOffset;
}
}
layerOrders.emplace_back(layerOrder + frame.depth, frame.depth);
draws.push_back({type, id, groupType, sample, time, frame, parent});
}
};
@@ -80,6 +87,7 @@ namespace anm2ed::model
auto isFound = type == LAYER ? item_get(model.content.layers, track.id) != nullptr
: item_get(model.content.nulls, track.id) != nullptr;
if (track.isVisible && isFound) track_draws_add(track, drawType, track.id, NONE, group);
if (type == LAYER) ++layerOrder;
};
for (const auto& entry : *entries)
{
@@ -95,6 +103,18 @@ namespace anm2ed::model
track_add(groupTrack, &group);
}
}
// Layers draw one after another, so reordering them by depth only moves them among each other.
std::vector<std::size_t> layerIndices{};
for (std::size_t i = 0; i < draws.size(); ++i)
if (draws[i].type == DrawType::LAYER) layerIndices.push_back(i);
auto sorted = layerIndices;
std::ranges::stable_sort(sorted, {}, [&](std::size_t i) { return layerOrders[i]; });
std::vector<Draw> layerDraws{};
for (auto i : sorted)
layerDraws.push_back(draws[i]);
for (std::size_t i = 0; i < layerIndices.size(); ++i)
draws[layerIndices[i]] = std::move(layerDraws[i]);
return draws;
}
}
+1
View File
@@ -54,6 +54,7 @@ namespace anm2ed::model
Interpolation interpolation{Interpolation::NONE};
int regionId{-1};
int shaderId{-1};
int depth{}; // a layer frame draws this many layers above (or below) its place in the timeline; editor-only
int atFrame{-1};
int eventId{-1};
std::vector<int> soundIds{};
+5 -1
View File
@@ -35,7 +35,7 @@ namespace anm2ed::model
constexpr std::string_view KNOWN_ATTRIBUTES[] = {
"Name", "CreatedBy", "CreatedOn", "Binding", "Value", "DefaultAnimation", "Path", "Vertex", "Fragment", "Id",
"LayerId", "NullId", "SpritesheetId", "Fps", "Version", "FrameNum", "Delay", "AtFrame", "EventId", "RegionId",
"ShaderId", "SoundId", "GroupId", "Index", "Loop", "StartMarker", "EndMarker", "Visible", "ShowRect", "IsExpanded", "Enabled", "Rotation",
"ShaderId", "Depth", "SoundId", "GroupId", "Index", "Loop", "StartMarker", "EndMarker", "Visible", "ShowRect", "IsExpanded", "Enabled", "Rotation",
"XPivot", "YPivot", "XCrop", "YCrop", "XPosition", "YPosition", "Width", "Height", "XScale", "YScale", "ShearX",
"ShearY", "RedTint", "GreenTint", "BlueTint", "AlphaTint", "RedOffset", "GreenOffset", "BlueOffset",
"Interpolated", "Origin", "BakeInterpolation", "BakeDelay", "BakeCount", "OriginalDelay"};
@@ -216,6 +216,7 @@ namespace anm2ed::model
frame.interpolation = interpolation_read(element, "Interpolated");
frame.regionId = int_get(element, "RegionId");
frame.shaderId = int_get(element, "ShaderId");
frame.depth = int_get(element, "Depth", 0);
frame.atFrame = int_get(element, "AtFrame");
frame.eventId = int_get(element, "EventId");
frame.extras = extras_read(element);
@@ -1142,6 +1143,8 @@ namespace anm2ed::model
sink.attribute("Rotation", frame.rotation);
interpolation_add(sink, "Interpolated", frame.interpolation);
if (writer.is(SERIALIZE_EXTENSIONS) && frame.shaderId != -1) sink.attribute("ShaderId", frame.shaderId);
if (writer.is(SERIALIZE_EXTENSIONS) && type == ItemType::LAYER && frame.depth != 0)
sink.attribute("Depth", frame.depth);
extras_attributes_write(sink, frame.extras);
if (bake.delay > 0)
{
@@ -1333,6 +1336,7 @@ namespace anm2ed::model
track.type != ItemType::TRIGGER && is_special_interpolation(frame.interpolation);
issues.shearFrames += frame.shear != glm::vec2();
issues.shaderFrames += frame.shaderId != -1;
issues.depthFrames += track.type == ItemType::LAYER && frame.depth != 0;
issues.triggerSounds +=
track.type == ItemType::TRIGGER &&
std::ranges::any_of(frame.soundIds, [](int id) { return id != -1; });
+1
View File
@@ -15,6 +15,7 @@ namespace anm2ed::model
int groupTransforms{};
int shearFrames{};
int shaderFrames{};
int depthFrames{};
int triggerSounds{};
bool operator==(const IsaacIssues&) const = default;