vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
pose_buffer.h
1#pragma once
2
3#include <cstdint>
4#include <vector>
5
6#include <glm/glm.hpp>
7
8#include "ecs/entity.h"
9
10namespace Vkm::Engine {
11
19struct PoseSlice {
20 uint32_t first = 0;
21 uint32_t count = 0;
22
23 glm::vec3 originMin{0.0f};
24 glm::vec3 originMax{0.0f};
25
26 float maxBoneScale = 1.0f;
27};
28
34struct PoseWrite {
35 PoseSlice* slice = nullptr;
36 glm::mat4* global = nullptr;
37 glm::mat4* palette = nullptr;
38};
39
47class PoseBuffer {
48 public:
49 PoseBuffer() = default;
50 ~PoseBuffer() = default;
51
52 PoseBuffer(const PoseBuffer& other) = delete;
53 PoseBuffer& operator=(const PoseBuffer& other) = delete;
54
55 PoseBuffer(PoseBuffer && other) = delete;
56 PoseBuffer& operator=(PoseBuffer && other) = delete;
57
58 public:
62 void clear();
63
72 uint32_t addSlice(uint32_t boneCount);
73
80 void mapEntity(EntityId entity, uint32_t slice);
81
90 PoseWrite writeTo(uint32_t slice);
91
101 const PoseSlice* sliceOf(EntityId entity) const;
102
103 const std::vector<PoseSlice>& slices() const { return m_slices; }
104 const std::vector<glm::mat4>& global() const { return m_global; }
105 const std::vector<glm::mat4>& palette() const { return m_palette; }
106
107 private:
111 struct Mapping {
112 EntityId entity{};
113 uint32_t slice = 0;
114 };
115
116 private:
117 std::vector<glm::mat4> m_global;
118 std::vector<glm::mat4> m_palette;
119 std::vector<PoseSlice> m_slices;
120 std::vector<Mapping> m_sliceOfEntity;
121};
122
131void finishSlice(const PoseWrite& out);
132
133} // namespace Vkm::Engine
const PoseSlice * sliceOf(EntityId entity) const
The slice driving entity.
uint32_t addSlice(uint32_t boneCount)
Reserve boneCount consecutive bones for one rig.
PoseWrite writeTo(uint32_t slice)
Writable view of slice, for composing its pose.
void clear()
Drop last frame's slices and mapping, keeping the capacity.
void mapEntity(EntityId entity, uint32_t slice)
Record that entity is driven by slice.
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
One rig's range in the frame's pose arrays, plus what the pose implies about its extent.
Definition pose_buffer.h:19
glm::vec3 originMin
AABB of the posed bone origins, rig model space.
Definition pose_buffer.h:23
float maxBoneScale
Largest scale any bone carries in this pose, never below 1.
Definition pose_buffer.h:26
Writable view of one slice, handed to whatever composes the pose.
Definition pose_buffer.h:34