Stage 9b: animations draw from a model draw list
- model::animation_draws_get returns what an animation draws at a time (root, group roots, layers, nulls; onion-skin samples first), with root and group root transforms as each item's parent and their tint/offset folded into layer frames. - The preview, the About friends and animation_rect all use it; the preview's render lambda shrinks to drawing the list. - Tests for draw order and root folding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
595658581f
commit
39ccfb723a
6 files changed
+306
-374
No files matched your search
+14
-29
@@ -3,6 +3,7 @@
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
#include "draw.hpp"
|
||||
#include "math.hpp"
|
||||
|
||||
using namespace anm2ed::util;
|
||||
@@ -228,35 +229,19 @@ namespace anm2ed::model
|
||||
glm::vec2 max{-std::numeric_limits<float>::infinity()};
|
||||
bool isAny{};
|
||||
|
||||
for (float t = 0.0f; t < (float)animation.frameNum; t += 1.0f)
|
||||
{
|
||||
glm::mat4 transform(1.0f);
|
||||
if (isRootTransform) transform *= frame_parent_model_get(frame_generate(animation.root, t));
|
||||
|
||||
tracks_each(animation.layers,
|
||||
[&](const Track& track, const TrackGroup* group)
|
||||
{
|
||||
if (!track.isVisible || (group && !group->isVisible)) return;
|
||||
auto itemTransform = transform;
|
||||
if (isRootTransform && group)
|
||||
itemTransform *= frame_parent_model_get(frame_generate(group->root, t));
|
||||
|
||||
auto frame = model.frame_effective(track.id, frame_generate(track, t));
|
||||
if (frame.size == glm::vec2() || !frame.isVisible) return;
|
||||
|
||||
auto layerTransform =
|
||||
itemTransform * math::quad_model_get(frame.size, frame.position, frame.pivot,
|
||||
math::percent_to_unit(frame.scale), frame.rotation,
|
||||
math::percent_to_unit(frame.shear));
|
||||
for (auto& corner : CORNERS)
|
||||
{
|
||||
auto world = glm::vec2(layerTransform * glm::vec4(corner, 0.0f, 1.0f));
|
||||
min = glm::min(min, world);
|
||||
max = glm::max(max, world);
|
||||
isAny = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
for (float time = 0.0f; time < (float)animation.frameNum; time += 1.0f)
|
||||
for (const auto& draw : animation_draws_get(model, animation, {.time = time, .isRootTransform = isRootTransform}))
|
||||
{
|
||||
if (draw.type != DrawType::LAYER || draw.frame.size == glm::vec2()) continue;
|
||||
auto transform = draw.parent * draw_quad_model_get(draw);
|
||||
for (auto& corner : CORNERS)
|
||||
{
|
||||
auto world = glm::vec2(transform * glm::vec4(corner, 0.0f, 1.0f));
|
||||
min = glm::min(min, world);
|
||||
max = glm::max(max, world);
|
||||
isAny = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isAny) return glm::vec4(-1.0f);
|
||||
return {min.x, min.y, max.x - min.x, max.y - min.y};
|
||||
|
||||
Reference in new issue
Block a user