Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
Animation.hpp
1#pragma once
2
3#include <stdint.h>
4#include <string>
5#include <vector>
6#include "../Math.hpp"
7
8namespace Grindstone::Formats::Animation::V1 {
9 const uint32_t version = 1;
10 const char magicCode[5] = "GANI";
11 const uint32_t magicSize = 4;
12
13 enum class KeyframeInterpolation : uint8_t {
14 Step,
15 Linear,
16 Cubic,
17 };
18
19 struct Header {
20 uint64_t totalFileSize = 0;
21 uint32_t version = 1;
22 double animationDuration = 1.f;
23 double ticksPerSecond = 0.25f;
24 uint16_t boneChannelCount = 0;
25 uint16_t propertyChannelCount = 0;
26 uint32_t positionKeyframesCount = 0;
27 uint32_t rotationKeyframesCount = 0;
28 uint32_t scaleKeyframesCount = 0;
29 uint16_t eventCount = 0;
30 uint64_t boneChannelDataOffset = 0;
31 uint64_t propertyChannelDataOffset = 0;
32 uint64_t positionKeyframesOffset = 0;
33 uint64_t rotationKeyframesOffset = 0;
34 uint64_t scaleKeyframesOffset = 0;
35 uint64_t propertyKeyframesOffset = 0;
36 uint64_t eventsArrayOffset = 0;
37 uint64_t eventsPayloadOffset = 0;
38 uint64_t stringBlockOffset = 0;
39 };
40
41 struct BoneChannel {
42 uint32_t boneNameStringOffset = 0;
43 uint16_t positionCount;
44 uint16_t scaleCount;
45 uint16_t rotationCount;
46 uint32_t positionKeyOffset = 0;
47 uint32_t rotationKeyOffset = 0;
48 uint32_t scaleKeyOffset = 0;
49 KeyframeInterpolation interpolation = KeyframeInterpolation::Linear;
50 };
51
52 template<typename T>
53 struct Keyframe {
54 double time;
55 T value;
56
57 Keyframe() = default;
58 Keyframe(const Keyframe& other) = default;
59 Keyframe(Keyframe&& other) noexcept = default;
60 Keyframe& operator=(const Keyframe& other) = default;
61 Keyframe& operator=(Keyframe&& other) noexcept = default;
62 Keyframe(double time, T value) : time(time), value(value) {}
63 };
64
66 std::vector<Keyframe<Grindstone::Math::Float3>> positions;
67 std::vector<Keyframe<Grindstone::Math::Float3>> scales;
68 std::vector<Keyframe<Grindstone::Math::Quaternion>> rotations;
69 };
70}