Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
gltf_mesh_io.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
9
11#include "momentum/common/log.h"
15
16#include <algorithm>
17
18namespace momentum {
19
20namespace {
21
22struct TextureBuffers {
23 std::vector<Vector2f> coords;
24 std::vector<Vector3i> faces;
25};
26
27struct MeshBuffers {
28 std::vector<Vector3i> faces;
29 std::vector<Vector3f> positions;
30 std::vector<Vector3f> normals;
31 std::vector<Vector3b> colors;
32 TextureBuffers texture;
33};
34
35nlohmann::json getMomentumExtension(const nlohmann::json& extensionsAndExtras) {
36 if (extensionsAndExtras.count("extensions") != 0 &&
37 extensionsAndExtras["extensions"].count("FB_momentum") != 0) {
38 return extensionsAndExtras["extensions"]["FB_momentum"];
39 } else {
40 return nlohmann::json::object();
41 }
42}
43
44std::vector<uint32_t> loadIndexBuffer(
45 const fx::gltf::Document& model,
46 const fx::gltf::Primitive& primitive) {
47 auto indices = copyAccessorBuffer<uint32_t>(model, primitive.indices);
48 if (!indices.empty()) {
49 return indices;
50 }
51
52 const auto shortIndices = copyAccessorBuffer<uint16_t>(model, primitive.indices);
53 indices.reserve(shortIndices.size());
54 for (const auto index : shortIndices) {
55 indices.push_back(index);
56 }
57 return indices;
58}
59
60std::vector<Vector3i> makeTriangleFaces(const std::vector<uint32_t>& indices) {
61 MT_CHECK(indices.size() % 3 == 0, "{} % 3 = {}", indices.size(), indices.size() % 3);
62
63 std::vector<Vector3i> faces(indices.size() / 3);
64 if (!faces.empty()) {
65 std::copy_n(indices.data(), indices.size(), &faces[0][0]);
66 }
67 return faces;
68}
69
70std::vector<Vector3i> loadTriangleFaces(
71 const fx::gltf::Document& model,
72 const fx::gltf::Primitive& primitive) {
73 return makeTriangleFaces(loadIndexBuffer(model, primitive));
74}
75
76template <typename T>
77std::vector<T> loadOptionalAttribute(
78 const fx::gltf::Document& model,
79 const fx::gltf::Primitive& primitive,
80 const char* attributeName) {
81 const auto attribute = primitive.attributes.find(attributeName);
82 if (attribute == primitive.attributes.end()) {
83 return {};
84 }
85 return copyAccessorBuffer<T>(model, attribute->second);
86}
87
88std::vector<Vector3f> loadPositions(
89 const fx::gltf::Document& model,
90 const fx::gltf::Primitive& primitive) {
91 auto positions = copyAccessorBuffer<Vector3f>(model, primitive.attributes.at("POSITION"));
92 toMomentumVec3f(positions);
93 return positions;
94}
95
96void offsetFaces(std::vector<Vector3i>& faces, const size_t vertexOffset) {
97 if (vertexOffset == 0) {
98 return;
99 }
100
101 for (auto& face : faces) {
102 face[0] += vertexOffset;
103 face[1] += vertexOffset;
104 face[2] += vertexOffset;
105 }
106}
107
108TextureBuffers loadMomentumTextureBuffers(
109 const fx::gltf::Document& model,
110 const nlohmann::json& extension) {
111 TextureBuffers texture;
112 texture.coords = copyAccessorBuffer<Vector2f>(model, extension.at("texcoords"));
113 texture.faces = makeTriangleFaces(copyAccessorBuffer<uint32_t>(model, extension.at("texfaces")));
114 return texture;
115}
116
117TextureBuffers loadStandardTextureBuffers(
118 const fx::gltf::Document& model,
119 const fx::gltf::Primitive& primitive,
120 const size_t numPositions,
121 const size_t vertexOffset,
122 std::vector<Vector3i>& faces) {
123 TextureBuffers texture;
124 texture.coords = loadOptionalAttribute<Vector2f>(model, primitive, "TEXCOORD_0");
125
126 offsetFaces(faces, vertexOffset);
127 if (texture.coords.size() == numPositions) {
128 texture.faces = faces;
129 }
130
131 MT_CHECK(
132 texture.coords.empty() || texture.coords.size() == numPositions,
133 "texcoord: {}, pos: {}",
134 texture.coords.size(),
135 numPositions);
136
137 return texture;
138}
139
140TextureBuffers loadTextureBuffers(
141 const fx::gltf::Document& model,
142 const fx::gltf::Primitive& primitive,
143 const size_t numPositions,
144 const size_t vertexOffset,
145 std::vector<Vector3i>& faces) {
146 const auto extension = getMomentumExtension(primitive);
147 if (extension.count("texcoords") > 0 && extension.count("texfaces") > 0) {
148 return loadMomentumTextureBuffers(model, extension);
149 }
150
151 return loadStandardTextureBuffers(model, primitive, numPositions, vertexOffset, faces);
152}
153
154MeshBuffers loadMeshBuffers(
155 const fx::gltf::Document& model,
156 const fx::gltf::Primitive& primitive,
157 const size_t vertexOffset) {
158 MeshBuffers buffers;
159 buffers.faces = loadTriangleFaces(model, primitive);
160 buffers.positions = loadPositions(model, primitive);
161
162 if (buffers.faces.empty() || buffers.positions.empty()) {
163 return buffers;
164 }
165
166 buffers.normals = loadOptionalAttribute<Vector3f>(model, primitive, "NORMAL");
167 MT_CHECK(
168 buffers.normals.empty() || buffers.normals.size() == buffers.positions.size(),
169 "nml: {}, pos: {}",
170 buffers.normals.size(),
171 buffers.positions.size());
172 MT_LOGT_IF(buffers.normals.empty(), "no vertex normal found");
173
174 buffers.colors = loadOptionalAttribute<Vector3b>(model, primitive, "COLOR_0");
175 MT_CHECK(
176 buffers.colors.empty() || buffers.colors.size() == buffers.positions.size(),
177 "col: {}, pos: {}",
178 buffers.colors.size(),
179 buffers.positions.size());
180 MT_LOGT_IF(buffers.colors.empty(), "no vertex color found");
181
182 // NOTE: gltf does not support multiple texcoords per vertex, so we only load the GLTF texcoords
183 // if we don't have our own custom extension
184 buffers.texture =
185 loadTextureBuffers(model, primitive, buffers.positions.size(), vertexOffset, buffers.faces);
186 MT_LOGT_IF(buffers.texture.coords.empty(), "no texture coords found");
187
188 return buffers;
189}
190
191void appendColors(Mesh& mesh, const std::vector<Vector3b>& colors, const size_t vertexOffset) {
192 const bool hadColors = !mesh.colors.empty();
193 if (!colors.empty()) {
194 if (!hadColors && vertexOffset > 0) {
195 mesh.colors.resize(vertexOffset, Vector3b::Constant(255));
196 }
197 mesh.colors.insert(mesh.colors.end(), colors.begin(), colors.end());
198 return;
199 }
200
201 if (hadColors) {
202 mesh.colors.resize(mesh.vertices.size(), Vector3b::Constant(255));
203 }
204}
205
206void appendMeshBuffers(Mesh& mesh, const MeshBuffers& buffers, const size_t vertexOffset) {
207 mesh.faces.insert(mesh.faces.end(), buffers.faces.begin(), buffers.faces.end());
208 mesh.vertices.insert(mesh.vertices.end(), buffers.positions.begin(), buffers.positions.end());
209 mesh.normals.insert(mesh.normals.end(), buffers.normals.begin(), buffers.normals.end());
210 appendColors(mesh, buffers.colors, vertexOffset);
211 mesh.texcoords.insert(
212 mesh.texcoords.end(), buffers.texture.coords.begin(), buffers.texture.coords.end());
213 mesh.texcoord_faces.insert(
214 mesh.texcoord_faces.end(), buffers.texture.faces.begin(), buffers.texture.faces.end());
215
216 // make sure we have enough normals
217 mesh.normals.resize(mesh.vertices.size(), Vector3f::Zero());
218 mesh.confidence.resize(mesh.vertices.size(), 1.0f);
219}
220
221} // namespace
222
223size_t
224addMesh(const fx::gltf::Document& model, const fx::gltf::Primitive& primitive, Mesh_u& mesh) {
225 if (primitive.mode != fx::gltf::Primitive::Mode::Triangles) {
226 MT_LOGW("Mesh not loaded because it's not a triangle mesh");
227 return 0;
228 }
229
230 const size_t vertexOffset = mesh->vertices.size();
231 const auto buffers = loadMeshBuffers(model, primitive, vertexOffset);
232
233 // if we have no points or indices, skip loading
234 if (buffers.faces.empty() || buffers.positions.empty()) {
235 return 0;
236 }
237
238 appendMeshBuffers(*mesh, buffers, vertexOffset);
239 return buffers.positions.size();
240}
241
243 const fx::gltf::Document& model,
244 const fx::gltf::Primitive& primitive,
245 BlendShape_u& blendShape) {
246 if (primitive.targets.empty()) {
247 return 0;
248 }
249
250 const size_t numNewTargets = primitive.targets.size();
251
252 // Read the base mesh vertices from the primitive
253 auto baseVertices = copyAccessorBuffer<Vector3f>(model, primitive.attributes.at("POSITION"));
254 toMomentumVec3f(baseVertices);
255 const size_t kNumNewVertices = baseVertices.size();
256
257 // Create the BlendShape if it doesn't exist yet
258 if (blendShape == nullptr) {
259 // Initialize with the base mesh vertices
260 blendShape =
261 std::make_unique<BlendShape>(std::span<const Vector3f>(baseVertices), numNewTargets);
262
263 // load blendshape names from extension
264 const auto& extension = getMomentumExtension(primitive.extensionsAndExtras);
265 std::vector<std::string> blendShapeNames =
266 extension.value("shapeNames", std::vector<std::string>());
267
268 // Load each morph target
269 for (size_t iTarget = 0; iTarget < numNewTargets; ++iTarget) {
270 const auto& target = primitive.targets[iTarget];
271
272 // Look for POSITION attribute in the morph target
273 auto posId = target.find("POSITION");
274 if (posId == target.end()) {
275 MT_LOGW("Morph target {} has no POSITION attribute", iTarget);
276 continue;
277 }
278
279 // Load the position deltas
280 auto deltas = copyAccessorBuffer<Vector3f>(model, posId->second);
281 toMomentumVec3f(deltas);
282
283 MT_CHECK(
284 deltas.size() == kNumNewVertices,
285 "Morph target {} has {} vertices but mesh has {} vertices",
286 iTarget,
287 deltas.size(),
288 kNumNewVertices);
289
290 // Set the shape vector for this target
291 if (iTarget < blendShapeNames.size()) {
292 blendShape->setShapeVector(
293 iTarget, std::span<const Vector3f>(deltas), blendShapeNames[iTarget]);
294 } else {
295 blendShape->setShapeVector(iTarget, std::span<const Vector3f>(deltas));
296 }
297 }
298 } else {
299 // Append to existing BlendShape
300 const size_t kNumExistingVertices = blendShape->modelSize();
301 const size_t kNumExistingTargets = blendShape->shapeSize();
302 const size_t kTotalVertices = kNumExistingVertices + kNumNewVertices;
303 const size_t kMaxTargets = std::max(kNumExistingTargets, numNewTargets);
304
305 // Get the existing data
306 auto existingBaseShape = blendShape->getBaseShape();
307 const auto& existingShapeVectors = blendShape->getShapeVectors();
308
309 // Create new base shape by appending new vertices to existing ones
310 std::vector<Vector3f> newBaseShape;
311 newBaseShape.reserve(kTotalVertices);
312 newBaseShape.insert(newBaseShape.end(), existingBaseShape.begin(), existingBaseShape.end());
313 newBaseShape.insert(newBaseShape.end(), baseVertices.begin(), baseVertices.end());
314
315 // Create new shape vectors matrix
316 MatrixXf newShapeVectors(kTotalVertices * 3, kMaxTargets);
317 newShapeVectors.setZero();
318
319 // Copy existing shape vectors to the top rows
320 newShapeVectors.topRows(kNumExistingVertices * 3).leftCols(kNumExistingTargets) =
321 existingShapeVectors;
322
323 // Load and append new morph target deltas
324 for (size_t iTarget = 0; iTarget < numNewTargets; ++iTarget) {
325 const auto& target = primitive.targets[iTarget];
326
327 // Look for POSITION attribute in the morph target
328 auto posId = target.find("POSITION");
329 if (posId == target.end()) {
330 MT_LOGW("Morph target {} has no POSITION attribute", iTarget);
331 continue;
332 }
333
334 // Load the position deltas
335 auto deltas = copyAccessorBuffer<Vector3f>(model, posId->second);
336 toMomentumVec3f(deltas);
337
338 MT_CHECK(
339 deltas.size() == kNumNewVertices,
340 "Morph target {} has {} vertices but mesh has {} vertices",
341 iTarget,
342 deltas.size(),
343 kNumNewVertices);
344
345 // Copy deltas into the new shape vectors matrix
346 for (size_t iVert = 0; iVert < kNumNewVertices; ++iVert) {
347 const size_t rowOffset = (kNumExistingVertices + iVert) * 3;
348 newShapeVectors(rowOffset + 0, iTarget) = deltas[iVert].x();
349 newShapeVectors(rowOffset + 1, iTarget) = deltas[iVert].y();
350 newShapeVectors(rowOffset + 2, iTarget) = deltas[iVert].z();
351 }
352 }
353
354 // Create a new BlendShape with the combined data
355 blendShape = std::make_unique<BlendShape>(std::span<const Vector3f>(newBaseShape), kMaxTargets);
356 blendShape->setShapeVectors(newShapeVectors);
357 }
358
359 return numNewTargets;
360}
361
362std::vector<Vector4f> loadWeightsFromAccessor(
363 const fx::gltf::Document& model,
364 int32_t accessorIdx) {
365 std::vector<Vector4f> weightsData = copyAlignedAccessorBuffer<Vector4f>(model, accessorIdx);
366 if (weightsData.empty()) {
367 // Try fallback with normalized unsigned short weights (per glTF 2.0 spec, WEIGHTS_n can be
368 // FLOAT, UNSIGNED_BYTE normalized, or UNSIGNED_SHORT normalized).
369 auto weightsShort = copyAccessorBuffer<Vector4s>(model, accessorIdx);
370 if (!weightsShort.empty()) {
371 weightsData.reserve(weightsShort.size());
372 for (const auto& value : weightsShort) {
373 weightsData.emplace_back(value.cast<float>() / 65535.0f);
374 }
375 }
376 }
377 if (weightsData.empty()) {
378 // Try fallback with normalized unsigned byte weights.
379 auto weightsByte = copyAccessorBuffer<Vector4b>(model, accessorIdx);
380 if (!weightsByte.empty()) {
381 weightsData.reserve(weightsByte.size());
382 for (const auto& value : weightsByte) {
383 weightsData.emplace_back(value.cast<float>() / 255.0f);
384 }
385 }
386 }
387 return weightsData;
388}
389
391 const fx::gltf::Document& model,
392 const fx::gltf::Skin& skin,
393 const fx::gltf::Primitive& primitive,
394 const std::vector<size_t>& nodeToObjectMap,
395 const size_t kNumVertices,
396 SkinWeights_u& skinWeights) {
397 const auto kVertexOffset = skinWeights->index.rows();
398 skinWeights->index.conservativeResize(kVertexOffset + kNumVertices, Eigen::NoChange);
399 skinWeights->weight.conservativeResize(kVertexOffset + kNumVertices, Eigen::NoChange);
400 skinWeights->index.bottomRows(kNumVertices).setZero();
401 skinWeights->weight.bottomRows(kNumVertices).setZero();
402
403 // load skinning in batches of 4 indices/weights at a time (up to 8)
404 for (size_t i = 0; i < 2; i++) {
405 // load skinning index buffer
406 auto jointAttribute = primitive.attributes.find(std::string("JOINTS_") + std::to_string(i));
407 std::vector<Vector4s> jointIndices;
408 if (jointAttribute != primitive.attributes.end()) {
409 jointIndices = copyAccessorBuffer<Vector4s>(model, jointAttribute->second);
410 if (jointIndices.empty()) {
411 // Try fallback with short indices.
412 auto jointIndicesShort = copyAccessorBuffer<Vector4b>(model, jointAttribute->second);
413 for (const auto& value : jointIndicesShort) {
414 jointIndices.emplace_back(value.cast<uint16_t>());
415 }
416 }
417 }
418
419 // load skinning weight buffer
420 auto weightsAttribute = primitive.attributes.find(std::string("WEIGHTS_") + std::to_string(i));
421 std::vector<Vector4f> weightsData;
422 if (weightsAttribute != primitive.attributes.end()) {
423 weightsData = loadWeightsFromAccessor(model, weightsAttribute->second);
424 if (weightsData.empty()) {
425 MT_LOGW("No skinning weights read");
426 return;
427 }
428 } else {
429 MT_LOGW_IF(i == 0, "No skinning weights stored on primitive");
430 return;
431 }
432
433 if (jointIndices.empty() || weightsData.empty() || jointIndices.size() != weightsData.size() ||
434 jointIndices.size() != kNumVertices) {
435 MT_LOGW_IF(jointIndices.empty() || weightsData.empty(), "Mesh is not skinned to any joint");
437 !jointIndices.empty() && !weightsData.empty() &&
438 jointIndices.size() != weightsData.size(),
439 "Inconsistent data: {} vertices are skinned but {} weights found",
440 jointIndices.size(),
441 weightsData.size());
443 jointIndices.size() != kNumVertices,
444 "Inconsistent data: {} vertices are skinned but mesh has {} vertices",
445 jointIndices.size(),
446 kNumVertices);
447 return;
448 }
449
450 // copy indices/vertices into our buffer
451 for (Eigen::Index v = 0; v < static_cast<int>(kNumVertices); v++) {
452 for (size_t d = 0; d < 4; d++) {
453 const auto& skinWeight = weightsData[v][d];
454 const auto& jointIdxInSkin = jointIndices[v][d];
455 MT_CHECK(
456 jointIdxInSkin >= 0 && jointIdxInSkin < skin.joints.size(),
457 "{}: {}",
458 jointIdxInSkin,
459 skin.joints.size());
460 const auto& nodeIdx = skin.joints[jointIdxInSkin];
461 MT_CHECK(nodeIdx < nodeToObjectMap.size(), "{}: {}", nodeIdx, nodeToObjectMap.size());
462 const auto& jointIndex = nodeToObjectMap[nodeIdx];
463 if (jointIndex != kInvalidIndex) {
464 skinWeights->index(kVertexOffset + v, i * 4 + d) = (uint32_t)jointIndex;
465 skinWeights->weight(kVertexOffset + v, i * 4 + d) = skinWeight;
466 } else {
467 MT_LOGW("Invalid joint index encountered when reading skinning weights");
468 }
469 }
470 }
471 }
472}
473
474std::tuple<Mesh_u, SkinWeights_u, BlendShape_u> loadSkinnedMesh(
475 const fx::gltf::Document& model,
476 const std::vector<size_t>& meshNodes,
477 const std::vector<size_t>& nodeToObjectMap) {
478 std::vector<size_t> skinnedNodes;
479 skinnedNodes.reserve(meshNodes.size());
480 std::vector<size_t> unskinnedNodes;
481 unskinnedNodes.reserve(meshNodes.size());
482 for (auto nodeId : meshNodes) {
483 MT_CHECK(nodeId >= 0 && nodeId < model.nodes.size(), "{}: {}", nodeId, model.nodes.size());
484 const auto& node = model.nodes[nodeId];
485 if ((node.mesh >= 0) && (node.skin >= 0)) {
486 MT_CHECK(node.mesh < model.meshes.size(), "{}: {}", node.mesh, model.meshes.size());
487 MT_CHECK(node.skin < model.skins.size(), "{}: {}", node.skin, model.skins.size());
488 skinnedNodes.push_back(nodeId);
489 } else if (node.mesh >= 0) {
490 MT_CHECK(node.mesh < model.meshes.size(), "{}: {}", node.mesh, model.meshes.size());
491 unskinnedNodes.push_back(nodeId);
492 }
493 }
494
496 !skinnedNodes.empty() && !unskinnedNodes.empty(),
497 "Found both skinned meshes {} and meshes without skinning {}. Unskinned meshes will be ignored.",
498 skinnedNodes.size(),
499 unskinnedNodes.size());
500 auto resultMesh = std::make_unique<Mesh>();
501 auto skinWeights = std::make_unique<SkinWeights>();
502 BlendShape_u blendShape = nullptr;
503
504 if (!skinnedNodes.empty()) {
505 for (auto nodeId : skinnedNodes) {
506 // NOLINTBEGIN(facebook-hte-ParameterUncheckedArrayBounds)
507 const auto& node = model.nodes[nodeId];
508 const auto& mesh = model.meshes[node.mesh];
509 const auto& skin = model.skins[node.skin];
510 // NOLINTEND(facebook-hte-ParameterUncheckedArrayBounds)
511 for (const auto& primitive : mesh.primitives) {
512 const auto kNumVertices = addMesh(model, primitive, resultMesh);
513 addSkinWeights(model, skin, primitive, nodeToObjectMap, kNumVertices, skinWeights);
514 addBlendShapes(model, primitive, blendShape);
515 MT_CHECK(
516 resultMesh->vertices.size() == skinWeights->index.rows(),
517 "vertices: {}, skinWeights: {}",
518 resultMesh->vertices.size(),
519 skinWeights->index.rows());
520 }
521 }
522 } else if (!unskinnedNodes.empty()) {
523 for (auto nodeId : unskinnedNodes) {
524 // NOLINTBEGIN(facebook-hte-ParameterUncheckedArrayBounds)
525 const auto& node = model.nodes[nodeId];
526 const auto& mesh = model.meshes[node.mesh];
527 // NOLINTEND(facebook-hte-ParameterUncheckedArrayBounds)
528 for (const auto& primitive : mesh.primitives) {
529 addMesh(model, primitive, resultMesh);
530 addBlendShapes(model, primitive, blendShape);
531 }
532 }
533 return {std::move(resultMesh), nullptr, std::move(blendShape)};
534 } else {
535 return {};
536 }
537 return {std::move(resultMesh), std::move(skinWeights), std::move(blendShape)};
538}
539
540SkinWeights_u bindMeshToJoint(const Mesh_u& mesh, size_t jointId) {
541 auto skinWeights = std::make_unique<SkinWeights>();
542 const auto kNumVertices = mesh->vertices.size();
543 skinWeights->index.conservativeResize(kNumVertices, Eigen::NoChange);
544 skinWeights->weight.conservativeResize(kNumVertices, Eigen::NoChange);
545 skinWeights->index.bottomRows(kNumVertices).setZero();
546 skinWeights->weight.bottomRows(kNumVertices).setZero();
547 for (auto vertId = 0; vertId < kNumVertices; vertId++) {
548 skinWeights->index(vertId, 0) = static_cast<uint32_t>(jointId);
549 skinWeights->weight(vertId, 0) = 1.0f;
550 }
551
552 return skinWeights;
553}
554
555} // namespace momentum
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
Definition checks.h:36
#define MT_LOGW(...)
Definition log.h:180
#define MT_LOGW_IF(condition,...)
Definition log.h:186
#define MT_LOGT_IF(condition,...)
Definition log.h:183
::std::unique_ptr< BlendShape > BlendShape_u
Definition fwd.h:21
::std::unique_ptr< Mesh > Mesh_u
Definition fwd.h:24
void addSkinWeights(const fx::gltf::Document &model, const fx::gltf::Skin &skin, const fx::gltf::Primitive &primitive, const std::vector< size_t > &nodeToObjectMap, const size_t kNumVertices, SkinWeights_u &skinWeights)
Add skin weights from a glTF primitive.
SkinWeights_u bindMeshToJoint(const Mesh_u &mesh, size_t jointId)
Bind a mesh to a single joint.
MeshT< float > Mesh
Definition fwd.h:20
std::vector< T > copyAlignedAccessorBuffer(const fx::gltf::Document &model, int32_t id)
size_t addBlendShapes(const fx::gltf::Document &model, const fx::gltf::Primitive &primitive, BlendShape_u &blendShape)
Add blend shapes from a glTF primitive.
Vector3f toMomentumVec3f(const std::array< float, 3 > &vec) noexcept
::std::unique_ptr< SkinWeights > SkinWeights_u
Definition fwd.h:75
std::vector< T > copyAccessorBuffer(const fx::gltf::Document &model, int32_t id)
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
Definition types.h:182
std::vector< Vector4f > loadWeightsFromAccessor(const fx::gltf::Document &model, int32_t accessorIdx)
Load skin weights from a glTF accessor.
std::tuple< Mesh_u, SkinWeights_u, BlendShape_u > loadSkinnedMesh(const fx::gltf::Document &model, const std::vector< size_t > &meshNodes, const std::vector< size_t > &nodeToObjectMap)
Load skinned mesh, skin weights, and blend shapes from the model.
size_t addMesh(const fx::gltf::Document &model, const fx::gltf::Primitive &primitive, Mesh_u &mesh)
Add mesh data from a glTF primitive.
MatrixX< float > MatrixXf
Definition types.h:82