2026-01-08 19:23:19 +08:00
|
|
|
|
#pragma once
|
2026-01-09 16:40:30 +08:00
|
|
|
|
#include "math.hpp"
|
2026-01-10 20:02:50 +08:00
|
|
|
|
#include "char_types.hpp"
|
2026-01-09 16:40:30 +08:00
|
|
|
|
#include <map>
|
|
|
|
|
|
#include <functional>
|
2026-01-08 19:23:19 +08:00
|
|
|
|
|
|
|
|
|
|
namespace basalt::shared::anime_loader {
|
|
|
|
|
|
|
2026-01-09 16:40:30 +08:00
|
|
|
|
struct KeyFrame {
|
|
|
|
|
|
math::Vector3 position;
|
|
|
|
|
|
math::Quaternion rotation;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct KeyFrameSpan {
|
|
|
|
|
|
math::FloatPoint prev_time; ///< 归一化的到前一帧的时间,即两者加起来为1。
|
|
|
|
|
|
math::FloatPoint next_time; ///< 归一化的到后一帧的时间,即两者加起来为1。
|
|
|
|
|
|
math::Vector3 prev_position; ///< 前一帧的摄像机坐标。
|
|
|
|
|
|
math::Vector3 next_position; ///< 后一帧的摄像机坐标。
|
|
|
|
|
|
math::Quaternion prev_rotation; ///< 前一帧的摄像机旋转。
|
|
|
|
|
|
math::Quaternion next_rotation; ///< 后一帧的摄像机旋转。
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-01-10 20:29:50 +08:00
|
|
|
|
class Timeline {
|
|
|
|
|
|
public:
|
|
|
|
|
|
Timeline();
|
|
|
|
|
|
~Timeline();
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
void add_key_frame(math::Index frame_index, KeyFrame frame_data);
|
|
|
|
|
|
math::Index max_frame() const;
|
|
|
|
|
|
KeyFrameSpan tick(math::Index frame_index) const;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
math::Index max_frame_cache;
|
|
|
|
|
|
std::map<math::Index, KeyFrame> keyframes;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-01-09 16:49:06 +08:00
|
|
|
|
struct AnimeLoaderConfig {
|
2026-01-10 20:02:50 +08:00
|
|
|
|
char_types::BSString filename; ///< The file to be loaded by loader.
|
2026-01-09 16:49:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-01-09 16:40:30 +08:00
|
|
|
|
enum class AnimeLoaderStatus {
|
|
|
|
|
|
Ready,
|
|
|
|
|
|
Loaded,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief
|
|
|
|
|
|
* @details
|
|
|
|
|
|
* \li 摄像机的transform基于Blender坐标系。
|
|
|
|
|
|
* \li 摄像机的默认状态与Blender摄像机一致,即初始指向-Z,+Y Up。
|
|
|
|
|
|
*/
|
2026-01-08 19:23:19 +08:00
|
|
|
|
class IAnimeLoader {
|
|
|
|
|
|
public:
|
|
|
|
|
|
IAnimeLoader();
|
|
|
|
|
|
virtual ~IAnimeLoader();
|
|
|
|
|
|
|
2026-01-09 16:40:30 +08:00
|
|
|
|
public:
|
2026-01-09 16:49:06 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @brief
|
|
|
|
|
|
* @remarks
|
2026-01-10 20:29:50 +08:00
|
|
|
|
* \li 重写时只允许往timeline里插入数据。
|
|
|
|
|
|
* \li 重写时务必保证timeline里插入的数据大于2个,且初始节点的Key总是0。动画帧个数必须大于4。
|
2026-01-09 16:49:06 +08:00
|
|
|
|
*/
|
|
|
|
|
|
virtual void load(AnimeLoaderConfig&& config);
|
2026-01-09 16:40:30 +08:00
|
|
|
|
KeyFrameSpan tick();
|
|
|
|
|
|
|
2026-01-08 19:23:19 +08:00
|
|
|
|
protected:
|
2026-01-09 16:40:30 +08:00
|
|
|
|
AnimeLoaderStatus status;
|
2026-01-09 16:49:06 +08:00
|
|
|
|
AnimeLoaderConfig config;
|
|
|
|
|
|
math::Index time;
|
2026-01-10 20:29:50 +08:00
|
|
|
|
Timeline timeline;
|
2026-01-08 19:23:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace basalt::shared::anime_loader
|