Libraries window, animation layers and child playback
A Libraries window (docked with Spritesheets and Sounds) links other .anm2 files: cards list each one's animations, open it as a tab, and reload when it changes on disk. A layer's Source is a spritesheet or an animation, from this file or a library; the preview, renders and CLI draw the child in the layer's frame. Animation-layer keyframes set the child's animation, mode (loop, once, hold), start frame (or random) and restart; Child is also a copyable frame property. All of it is editor-only and counted by the Isaac warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6edf5f0e5b
commit
d1a6d89d14
44 files changed
+873
-81
No files matched your search
@@ -57,3 +57,42 @@ TEST_CASE("a layer frame's depth moves it among the layers for that frame only")
|
||||
CHECK(model_load(text).frame_get({0, LAYER, 0, 0})->depth == -1);
|
||||
CHECK(model::isaac_issues_get(anm2).depthFrames == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("an animation layer draws its child animation, from this file or a library")
|
||||
{
|
||||
auto anm2 = model_load(file_load(TEST_DIR / "render" / "nested.anm2"));
|
||||
auto spin = model_load(file_load(TEST_DIR / "render" / "spin.anm2"));
|
||||
model::DrawOptions options{.library_get = [&](const model::Model&, int id) { return id == 0 ? &spin : nullptr; }};
|
||||
auto red_position_get = [&](int layerId)
|
||||
{
|
||||
std::optional<glm::vec2> position{};
|
||||
for (const auto& draw : model::animation_draws_get(anm2, *anm2.animation_get(0), options))
|
||||
if (draw.type == model::DrawType::LAYER && draw.id == layerId && draw.frame.crop == glm::vec2())
|
||||
position = glm::vec2(draw.parent * glm::vec4(draw.frame.position, 0.0f, 1.0f));
|
||||
return position;
|
||||
};
|
||||
|
||||
// The library's red square, half size at (40, 0), starts on its fifth frame (at x 16).
|
||||
CHECK(red_position_get(0) == glm::vec2(48.0f, 0.0f));
|
||||
// This file's Inner holds its first frame however far the parent plays.
|
||||
options.time = 1.0f;
|
||||
CHECK(red_position_get(1) == glm::vec2(-40.0f, 0.0f));
|
||||
// An animation never draws inside itself.
|
||||
CHECK_FALSE(red_position_get(3));
|
||||
|
||||
// Once stops on the child's last frame; Loop wraps around it.
|
||||
options.time = 6.0f;
|
||||
anm2.frame_edit({0, LAYER, 1, 0})->childMode = ChildMode::ONCE;
|
||||
CHECK(red_position_get(1) == glm::vec2(-40.0f, 10.0f));
|
||||
anm2.frame_edit({0, LAYER, 1, 0})->childMode = ChildMode::LOOP;
|
||||
CHECK(red_position_get(1) == glm::vec2(-40.0f, 0.0f));
|
||||
|
||||
// Without the library loaded, its layer draws nothing.
|
||||
options.library_get = {};
|
||||
CHECK_FALSE(red_position_get(0));
|
||||
|
||||
auto text = model::model_to_string(anm2, {.isExtendedFormat = true});
|
||||
CHECK(model::model_hash(model_load(text)) == model::model_hash(anm2));
|
||||
CHECK(model::isaac_issues_get(anm2).animationLayers == 3);
|
||||
CHECK(game_document_get(model::model_to_string(anm2)).find(" Animation=\"") == std::string::npos);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 782 B |
@@ -0,0 +1,52 @@
|
||||
<AnimatedActor>
|
||||
<Info CreatedBy="fixture" CreatedOn="01/01/2026 12:00:00 PM" Fps="30" Version="2" ExtendedVersion="1"/>
|
||||
<Content>
|
||||
<Spritesheets>
|
||||
<Spritesheet Id="0" Path="sheet.png"/>
|
||||
</Spritesheets>
|
||||
<Layers>
|
||||
<Layer Id="0" Name="spin" SpritesheetId="0" Library="0" Animation="Spin"/>
|
||||
<Layer Id="1" Name="inner" SpritesheetId="0" Animation="Inner"/>
|
||||
<Layer Id="2" Name="red" SpritesheetId="0"/>
|
||||
<Layer Id="3" Name="cycle" SpritesheetId="0" Animation="Nested"/>
|
||||
</Layers>
|
||||
<Nulls/>
|
||||
<Events/>
|
||||
<Libraries>
|
||||
<Library Id="0" Path="spin.anm2"/>
|
||||
</Libraries>
|
||||
</Content>
|
||||
<Animations DefaultAnimation="Nested">
|
||||
<Animation Name="Nested" FrameNum="8" Loop="true">
|
||||
<RootAnimation>
|
||||
<Frame XPosition="0" YPosition="0" Delay="8" Visible="true" XScale="100" YScale="100" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
</RootAnimation>
|
||||
<LayerAnimations>
|
||||
<LayerAnimation LayerId="1" Visible="true">
|
||||
<Frame XPivot="0" YPivot="0" XCrop="0" YCrop="0" Width="0" Height="0" XPosition="-40" YPosition="0" Delay="8" Visible="true" XScale="100" YScale="100" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false" ChildMode="Hold"/>
|
||||
</LayerAnimation>
|
||||
<LayerAnimation LayerId="0" Visible="true">
|
||||
<Frame XPivot="0" YPivot="0" XCrop="0" YCrop="0" Width="0" Height="0" XPosition="40" YPosition="0" Delay="8" Visible="true" XScale="50" YScale="50" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false" ChildStart="4"/>
|
||||
</LayerAnimation>
|
||||
<LayerAnimation LayerId="3" Visible="true">
|
||||
<Frame XPivot="0" YPivot="0" XCrop="0" YCrop="0" Width="0" Height="0" XPosition="0" YPosition="0" Delay="8" Visible="true" XScale="100" YScale="100" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
</LayerAnimation>
|
||||
</LayerAnimations>
|
||||
<NullAnimations/>
|
||||
<Triggers/>
|
||||
</Animation>
|
||||
<Animation Name="Inner" FrameNum="2" Loop="true">
|
||||
<RootAnimation>
|
||||
<Frame XPosition="0" YPosition="0" Delay="2" Visible="true" XScale="100" YScale="100" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
</RootAnimation>
|
||||
<LayerAnimations>
|
||||
<LayerAnimation LayerId="2" Visible="true">
|
||||
<Frame XPivot="8" YPivot="8" XCrop="0" YCrop="0" Width="16" Height="16" XPosition="0" YPosition="0" Delay="1" Visible="true" XScale="100" YScale="100" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
<Frame XPivot="8" YPivot="8" XCrop="0" YCrop="0" Width="16" Height="16" XPosition="0" YPosition="10" Delay="1" Visible="true" XScale="100" YScale="100" RedTint="255" GreenTint="255" BlueTint="255" AlphaTint="255" RedOffset="0" GreenOffset="0" BlueOffset="0" Rotation="0" Interpolated="false"/>
|
||||
</LayerAnimation>
|
||||
</LayerAnimations>
|
||||
<NullAnimations/>
|
||||
<Triggers/>
|
||||
</Animation>
|
||||
</Animations>
|
||||
</AnimatedActor>
|
||||
@@ -132,3 +132,28 @@ TEST_CASE("a recorded spritesheet holds every frame")
|
||||
CHECK(sheet.size == glm::ivec2(fixture.canvas->size) * glm::ivec2(layout.columns, layout.rows));
|
||||
golden_image_check("spin_sheet.png");
|
||||
}
|
||||
|
||||
TEST_CASE("animation layers draw their child animations")
|
||||
{
|
||||
RenderFixture fixture("nested.anm2");
|
||||
if (!fixture.gl.is_valid())
|
||||
{
|
||||
MESSAGE("skipped: no OpenGL context");
|
||||
return;
|
||||
}
|
||||
REQUIRE(fixture.document->is_valid());
|
||||
|
||||
// The library's red square at half size starts on its fifth frame, centered at (48, 0); this file's Inner holds its
|
||||
// red square at (-40, 0).
|
||||
auto pixels = fixture.frame_get(0.0f);
|
||||
for (auto point : {glm::vec2(48.0f, 0.0f), glm::vec2(-40.0f, 0.0f)})
|
||||
{
|
||||
auto red = fixture.pixel_get(pixels, point);
|
||||
CHECK(red.r > 200);
|
||||
CHECK(red.g < 80);
|
||||
}
|
||||
|
||||
REQUIRE(resource::Image::write_pixels_png(OUTPUT_DIR / "nested_frame_0.png", glm::ivec2(fixture.canvas->size),
|
||||
pixels.data()));
|
||||
golden_image_check("nested_frame_0.png");
|
||||
}
|
||||
Reference in new issue
Block a user