mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 09:36:48 +01:00
c8068d8f3d
Stage 8 of the EU07M model format. A model can carry animation clips; each track of a clip sets the translation, the rotation or the scale of a node at a time of the clip, and the parts of a node without a track keep its TRS. - Format, five optional sections: ACLP (clips: name, duration, flags 0x1 loop and 0x2 autoplay, range of tracks), ATRK (tracks: node, part, interpolation step / linear / cubic, ranges of keys), ATIM (key times), AVEC (vectors; with cubic the in-tangent, value and out-tangent of glTF) and AROT (rotations in 8 bytes, "smallest three": the three smaller components as snorm16 scaled by sqrt(2) and the index of the largest; eu07m::encode_rotation / decode_rotation). The validator refuses a node out of range, keys out of their arrays, times which aren't numbers from 0 up, a cubic rotation and tracks out of the range of the clip. -eu07m dump lists the clips and their tracks. The current release doesn't read these sections; a file without them loads as before. - Sampling (model/clip.cpp): step, lerp / slerp the shorter way, the Hermite spline of glTF with tangents per second; the first and the last key held outside of them; a looped clip goes around its duration, another stops at its end. - In the game: the clips play by the simulation time, from TAnimModel::play_clip(name, speed) or, flagged autoplay, from the first time the instance is drawn. RaPrepare() samples them for the instance drawn and sets the transforms of the nodes (TSubModel::SetClipTransform(), the new animation type at_Clip, gated by the instance like the others), so a clip moving the joints of a skin bends the skinned parts. The nodes a clip moves are flagged animated at load, which keeps the model out of the instancing. stop_clips() stops them. - The editor self-test gets "clip <node> <name> [speed]". Not yet: a scenery event starting a clip, and the CHNL channels bound to the time of a clip. Checked: a skinned tube with an autoplay clip (the tip to 60 degrees and back in 2 s, looped) beside a still one, six screenshots in Vulkan and in GL 4.6 go from straight to fully bent while the other stays (time let run in the editor for the test only). Unit tests 1200/1200, 6 new ones for the packing, the interpolations, the time and the file. Not built with GCC here.
81 lines
2.2 KiB
C++
81 lines
2.2 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <span>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <glm/glm.hpp>
|
|
#include <glm/gtc/quaternion.hpp>
|
|
|
|
// the animation clips of an EU07M model (ACLP, ATRK and their keys), as the game samples them: each track sets the translation, the
|
|
// rotation or the scale of a node at a time of the clip, and the parts of a node without a track keep its own TRS
|
|
namespace animation
|
|
{
|
|
|
|
enum class part : std::uint8_t
|
|
{
|
|
translation,
|
|
rotation,
|
|
scale
|
|
};
|
|
|
|
enum class curve : std::uint8_t
|
|
{
|
|
step,
|
|
linear, // lerp of vectors, slerp of rotations
|
|
cubic // the Hermite spline of glTF: in-tangent, value and out-tangent for each key, vectors only
|
|
};
|
|
|
|
struct track
|
|
{
|
|
part target{part::translation};
|
|
curve interpolation{curve::linear};
|
|
std::vector<float> times; // seconds, not decreasing
|
|
std::vector<glm::vec3> vectors; // translation, scale; three for each key with cubic
|
|
std::vector<glm::quat> rotations;
|
|
};
|
|
|
|
// the tracks of one node and the TRS the node has of its own
|
|
struct node_tracks
|
|
{
|
|
int node{-1};
|
|
int translation{-1}; // into the tracks of the clip, -1 without one
|
|
int rotation{-1};
|
|
int scale{-1};
|
|
glm::vec3 rest_translation{0.f};
|
|
glm::quat rest_rotation{1.f, 0.f, 0.f, 0.f};
|
|
glm::vec3 rest_scale{1.f};
|
|
};
|
|
|
|
struct clip
|
|
{
|
|
std::string name;
|
|
float duration{0.f};
|
|
bool loop{false};
|
|
bool autoplay{false};
|
|
std::vector<track> tracks;
|
|
std::vector<node_tracks> nodes; // the nodes the clip moves, each once
|
|
};
|
|
|
|
// the time of the clip after Elapsed seconds of playing: around the duration for a looped clip, else held at its end
|
|
float clip_time(clip const &Clip, double Elapsed);
|
|
|
|
// the value of the track at Time, held at the first and the last key outside of them
|
|
glm::vec3 sample_vector(track const &Track, float Time);
|
|
glm::quat sample_rotation(track const &Track, float Time);
|
|
|
|
// the transform of the node within its parent at Time: T * R * S, each part from its track or the rest of the node
|
|
glm::mat4 local_transform(clip const &Clip, node_tracks const &Node, float Time);
|
|
|
|
} // namespace animation
|