1
0
Files
BasaltMeter/BasaltPresenter/Shared/basalt/anime_loader.hpp
2026-01-10 20:02:50 +08:00

70 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include "math.hpp"
#include "char_types.hpp"
#include <map>
#include <functional>
namespace basalt::shared::anime_loader {
//struct KeyFrame {
// math::Index frame_index;
// math::Matrix4x4 transform;
//};
//struct KeyFrameCompare {
// bool operator()(const KeyFrame& lhs, const KeyFrame& rhs) const { return lhs.time < rhs.time; }
//};
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; ///< 后一帧的摄像机旋转。
};
struct AnimeLoaderConfig {
char_types::BSString filename; ///< The file to be loaded by loader.
};
enum class AnimeLoaderStatus {
Ready,
Loaded,
};
/**
* @brief
* @details
* \li 摄像机的transform基于Blender坐标系。
* \li 摄像机的默认状态与Blender摄像机一致即初始指向-Z+Y Up。
*/
class IAnimeLoader {
public:
IAnimeLoader();
virtual ~IAnimeLoader();
public:
/**
* @brief
* @remarks
* \li 重写时只允许往frames里插入数据。
* \li 重写时务必保证frames里插入的数据大于2个且初始节点的Key总是0。动画帧个数必须大于4。
*/
virtual void load(AnimeLoaderConfig&& config);
KeyFrameSpan tick();
protected:
AnimeLoaderStatus status;
AnimeLoaderConfig config;
math::Index time;
std::map<math::Index, KeyFrame> frames;
};
} // namespace basalt::shared::anime_loader