5 #include "../../math/quaternion.h"
6 #include "../../math/vec3.h"
7 #include "../../meshes/mesh.h"
9 #define MAX_JOINTS_PER_VERTEX 4
10 #define MAX_JOINTS_PER_MESH 64
21 std::size_t vertex_id = 0;
34 vertices_.reserve(32);
40 std::string name()
const;
41 void set_name(
const std::string& name);
45 Joint* parent()
const;
46 std::size_t id()
const;
47 void set_id(std::size_t
id) {
60 return absolute_rotation_;
63 const smlt::Vec3 absolute_translation()
const {
64 return absolute_translation_;
73 Joint* parent_ =
nullptr;
81 Vec3 absolute_translation_;
83 std::vector<JointVertex> vertices_;
85 void recalc_absolute_transformation();
89 Joint* joints[2] = {
nullptr,
nullptr};
99 joints_.resize(num_joints,
Joint(
this));
102 Joint* joint(std::size_t idx) {
103 return &joints_[idx];
106 const Joint* joint(std::size_t idx)
const {
107 return &joints_[idx];
110 Joint* find_joint(
const std::string& name) {
111 for(
auto& joint: joints_) {
112 if(joint.name_ == name) {
120 std::size_t joint_count()
const {
121 return joints_.size();
124 void attach_vertex_to_joint(std::size_t j, std::size_t vertex_index,
float weight) {
126 v.vertex_id = vertex_index;
128 joint(j)->vertices_.push_back(v);
134 Mesh* mesh_ =
nullptr;
135 std::vector<Joint> joints_;
137 Bone bones_[MAX_JOINTS_PER_MESH];
138 uint8_t bone_count_ = 0;
153 std::vector<JointState> joints;
157 int32_t joints[MAX_JOINTS_PER_VERTEX] = {-1, -1, -1, -1};
158 float weights[MAX_JOINTS_PER_VERTEX] = {0, 0, 0, 0};
168 uint32_t current_frame,
170 float t,
Rig*
const rig,
171 Debug*
const debug=
nullptr
174 virtual void unpack_frame(
175 const uint32_t current_frame,
176 const uint32_t next_frame,
180 Debug*
const debug=
nullptr
183 void set_joint_state_at_frame(std::size_t frame, std::size_t joint,
JointState state) {
184 assert(frame < skeleton_frames_.size());
185 assert(joint < skeleton_frames_[frame].joints.size());
187 skeleton_frames_[frame].joints[joint] = state;
190 const JointState& joint_state_at_frame(std::size_t frame, std::size_t joint)
const {
191 assert(frame < skeleton_frames_.size());
192 assert(joint < skeleton_frames_[frame].joints.size());
194 return skeleton_frames_[frame].joints[joint];
200 void rebuild_key_frame_absolute_transforms();
204 bool link_vertex_to_joint(std::size_t vertex, std::size_t j,
float weight) {
205 auto vert = &vertices_[vertex];
206 for(uint8_t i = 0; i < MAX_JOINTS_PER_VERTEX; ++i) {
207 if(vert->joints[i] < 0) {
209 vert->weights[i] = weight;
217 const std::vector<SkeletonVertex>& vertices()
const {
221 Mesh* mesh_ =
nullptr;
224 std::vector<SkeletonFrame> skeleton_frames_;
225 std::vector<SkeletonVertex> vertices_;