25 std::ifstream data(filename, std::ios::in | std::ios::binary);
26 if (!data.is_open()) {
32 uint64_t numJoints = 0;
33 data.read((
char*)&numRows,
sizeof(numRows));
34 data.read((
char*)&numJoints,
sizeof(numJoints));
37 MT_LOGW(
"{}: Failed to read dimensions from file {}", __func__, filename);
42 constexpr uint64_t kMaxDimension = 10'000'000;
43 constexpr uint64_t kMaxStringLength = 10'000;
44 if (numRows > kMaxDimension || numJoints > kMaxDimension) {
46 "{}: Unreasonable dimensions in file {}: numRows={}, numJoints={}",
55 if (numJoints > std::numeric_limits<uint64_t>::max() / 4) {
56 MT_LOGW(
"{}: Integer overflow in numCols calculation for file {}", __func__, filename);
59 const uint64_t numCols = numJoints * 4;
62 if (numRows != 0 && numCols != 0 && numRows > std::numeric_limits<uint64_t>::max() / numCols) {
63 MT_LOGW(
"{}: Integer overflow in shape matrix size for file {}", __func__, filename);
68 character.
mesh->vertices.size() * 3 == numRows,
70 character.
mesh->vertices.size() * 3,
74 data.read((
char*)&count,
sizeof(uint64_t));
75 if (!data.good() || count > kMaxStringLength) {
76 MT_LOGW(
"{}: Invalid base joint name length in file {}", __func__, filename);
81 data.read((
char*)base.data(), count);
83 MT_LOGW(
"{}: Failed to read base joint name data from file {}", __func__, filename);
90 "Invalid joint index");
95 std::vector<std::string> names(numJoints);
96 for (
size_t i = 0; i < numJoints; i++) {
97 data.read((
char*)&count,
sizeof(uint64_t));
98 if (!data.good() || count > kMaxStringLength) {
99 MT_LOGW(
"{}: Invalid joint name length in file {}", __func__, filename);
102 names[i].resize(count);
103 data.read((
char*)names[i].data(), count);
105 MT_LOGW(
"{}: Failed to read joint name data from file {}", __func__, filename);
112 data.read((
char*)result.
baseShape.data(),
sizeof(
float) * numRows);
114 MT_LOGW(
"{}: Failed to read base shape data from file {}", __func__, filename);
120 &character.
mesh->vertices[0][0], character.
mesh->vertices.size() * 3);
125 data.read((
char*)result.
shapeVectors.data(),
sizeof(
float) * numRows * numCols);
127 MT_LOGW(
"{}: Failed to read shape vectors data from file {}", __func__, filename);
133 for (
size_t i = 0; i < names.size(); i++) {
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
PoseShape loadPoseShape(const std::string &filename, const Character &character)
Loads pose shape data from a binary file.
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
A character model with skeletal structure, mesh, and optional components.
Mesh_u mesh
3D mesh representing the character's surface
Skeleton skeleton
Skeletal structure defining the character's joints and hierarchy.
Computes shape deformations based on joint rotations.
size_t baseJoint
Index of the joint used as reference for computing relative rotations.
MatrixXf shapeVectors
Shape deformation vectors for each quaternion component of each joint.
VectorXf baseShape
Base shape vertices stored as a flat vector [x1,y1,z1,x2,y2,z2,...].
std::vector< size_t > jointMap
Indices of joints whose rotations drive the shape deformation.
Quaternionf baseRot
Base rotation used as reference for computing rotation differences.
size_t getJointIdByName(std::string_view name) const
Returns the index of a joint with the given name, or kInvalidIndex if not found.
JointList joints
The list of joints in this skeleton, ordered such that every joint's parent appears earlier in the li...