Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
gltf_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
20#include "momentum/common/log.h"
34#include "momentum/math/mesh.h"
35#include "momentum/math/mppca.h"
37
38#include <algorithm>
39#include <iterator>
40#include <limits>
41#include <set>
42#include <variant>
43
44namespace {
45
46using namespace momentum;
47
48nlohmann::json getMomentumExtension(const nlohmann::json& extensionsAndExtras) {
49 if (extensionsAndExtras.count("extensions") != 0 &&
50 extensionsAndExtras["extensions"].count("FB_momentum") != 0) {
51 return extensionsAndExtras["extensions"]["FB_momentum"];
52 } else {
53 return nlohmann::json::object();
54 }
55}
56
57void loadGlobalExtensions(const fx::gltf::Document& model, Character& character) {
58 try {
59 // load additional momentum data if present
60 const auto& def = getMomentumExtension(model.extensionsAndExtras);
61
62 if (def.count("transform") > 0) {
63 character.parameterTransform = parameterTransformFromJson(character, def["transform"]);
64 } else {
65 character.parameterTransform =
67 }
68 if (def.count("parameterSet") > 0) {
70 parameterSetsFromJson(character, def["parameterSet"]);
71 }
72 if (def.count("poseConstraints") > 0) {
74 poseConstraintsFromJson(character, def["poseConstraints"]);
75 }
76 if (def.count("parameterLimits") > 0) {
77 character.parameterLimits = parameterLimitsFromJson(character, def["parameterLimits"]);
78 }
79 if (def.count("metadata") > 0) {
80 character.metadata = def.value<std::string>("metadata", {});
81 // ensure metadata is valid JSON
82 try {
83 auto json = nlohmann::json::parse(character.metadata);
84 } catch (const nlohmann::json::parse_error& e) {
85 MT_LOGW("Failed to parse metadata: {}", e.what());
86 }
87 }
88 } catch (std::runtime_error& err) {
89 MT_THROW("Unable to load gltf : {}", err.what());
90 }
91}
92
93Character populateCharacterFromModel(
94 const fx::gltf::Document& model,
95 std::vector<size_t>& nodeToObjectMap) {
96 // #TODO: set character name
97 Character result;
98
99 // ---------------------------------------------
100 // load the joints, collision geometry and locators
101 // ---------------------------------------------
102 std::tie(
103 result.name,
104 result.skeleton.joints,
105 result.collision,
106 result.locators,
107 result.physicalProperties,
108 nodeToObjectMap) = loadHierarchy(model);
109 MT_CHECK(
110 nodeToObjectMap.size() == model.nodes.size(),
111 "nodeMap: {}, nodes: {}",
112 nodeToObjectMap.size(),
113 model.nodes.size());
114
115 // ---------------------------------------------
116 // load the mesh -- load from the nodes not in the hierarchy, and combine all meshes into one
117 // ---------------------------------------------
118 std::vector<size_t> remainingNodes;
119 remainingNodes.reserve(model.nodes.size());
120 for (auto nodeId = 0; nodeId < nodeToObjectMap.size(); nodeId++) {
121 if (nodeToObjectMap[nodeId] == kInvalidIndex) {
122 remainingNodes.push_back(nodeId);
123 }
124 }
125
126 BlendShape_u loadedBlendShape;
127 std::tie(result.mesh, result.skinWeights, loadedBlendShape) =
128 loadSkinnedMesh(model, remainingNodes, nodeToObjectMap);
129
130 // Set the blendShape if we loaded any
131 if (loadedBlendShape != nullptr) {
132 result.blendShape = std::move(loadedBlendShape);
133 }
134
135 // Check if there's no skeleton and no skinning nodes found
136 // but there are meshes in the scene. We will create a joint to parent
137 // them.
138 if (result.skeleton.joints.empty() && result.mesh != nullptr && result.skinWeights == nullptr) {
140 for (auto& locator : result.locators) {
141 locator.parent = 0;
142 }
143 result.skinWeights = bindMeshToJoint(result.mesh, 0);
144 }
145
146 loadGlobalExtensions(model, result);
147
148 // Finalize jointMap and inverseBind pose
149 result.resetJointMap();
150 result.initInverseBindPose();
151
152 return result;
153}
154
155fx::gltf::Document loadModel(
156 const std::variant<filesystem::path, std::span<const std::byte>>& input) {
157 fx::gltf::Document model;
158 constexpr uint32_t kMax = std::numeric_limits<uint32_t>::max();
159 constexpr fx::gltf::ReadQuotas kQuotas = {8, kMax, kMax};
160
161 std::visit(
162 [&](auto&& arg) {
163 using T = std::decay_t<decltype(arg)>;
164 if constexpr (std::is_same_v<T, filesystem::path>) {
165 // Read first 4 chars for file sensing (https://docs.fileformat.com/3d/glb/)
166 // It is ASCII string "glTF", and can be used to identify data as Binary glTF
167 std::string magic;
168 std::ifstream infile(arg);
169 MT_THROW_IF(!infile.is_open(), "Unable to open: {}", arg.string());
170 std::copy_n(std::istreambuf_iterator<char>(infile.rdbuf()), 4, std::back_inserter(magic));
171 if (magic == "glTF") {
172 model = fx::gltf::LoadFromBinary(arg.string(), kQuotas);
173 } else {
174 model = fx::gltf::LoadFromText(arg.string(), kQuotas);
175 }
176 } else if constexpr (std::is_same_v<T, std::span<const std::byte>>) {
177 ispanstream inputStream(arg);
178 model = fx::gltf::LoadFromBinary(inputStream, "", kQuotas);
179 }
180 },
181 input);
182
183 return model;
184}
185
186Character loadModelAndCharacter(
187 const std::variant<filesystem::path, std::span<const std::byte>>& input) {
188 Character result;
189 try {
190 // Set maximum filesize to 4 gigabyte (glb hard limit due to uint32).
191 // Need to fork gltf load to support dynamic loading at some point if files get too big
192 fx::gltf::Document model = loadModel(input);
193 result = loadGltfCharacter(model);
194 } catch (std::runtime_error& err) {
195 MT_THROW("Unable to load gltf : {}", err.what());
196 }
197
198 return result;
199}
200
201fx::gltf::Document makeCharacterDocument(
202 const Character& character,
203 const float fps,
204 std::span<const SkeletonState> skeletonStates,
205 std::span<const std::vector<Marker>> markerSequence,
206 bool embedResource,
207 const FileSaveOptions& options) {
208 GltfBuilder fileBuilder;
210
211 const auto kCharacterIsEmpty = character.skeleton.joints.empty() && character.mesh == nullptr;
212 if (!kCharacterIsEmpty) {
213 fileBuilder.addCharacter(character, Vector3f::Zero(), Quaternionf::Identity(), options);
214 }
215 // Add potential motion or offsets, even if the character is empty
216 // (it could be a motion database for example)
217 if (!skeletonStates.empty()) {
218 fileBuilder.addSkeletonStates(character, fps, skeletonStates);
219 }
220 if (!markerSequence.empty()) {
222 !skeletonStates.empty() && (skeletonStates.size() != markerSequence.size()),
223 "Size of skeleton states vector {} does not correspond to size of marker sequence vector {}",
224 skeletonStates.size(),
225 markerSequence.size());
226
227 fileBuilder.addMarkerSequence(fps, markerSequence);
228 }
229 if (embedResource) {
230 fileBuilder.forceEmbedResources();
231 }
232
233 return fileBuilder.getDocument();
234}
235
236} // namespace
237
238namespace momentum {
239
241 const fx::gltf::Document& model,
242 std::vector<size_t>& nodeToObjectMap) {
243 // ---------------------------------------------
244 // load Skeleton and Mesh
245 // ---------------------------------------------
246 Character result;
247 try {
248 result = populateCharacterFromModel(model, nodeToObjectMap);
249 } catch (std::runtime_error& err) {
250 MT_THROW("Unable to load gltf : {}", err.what());
251 }
252
253 return result;
254}
255
256Character loadGltfCharacter(const fx::gltf::Document& model) {
257 std::vector<size_t> nodeToObjectMap;
258 return loadGltfCharacterInternal(model, nodeToObjectMap);
259}
260
261Character loadGltfCharacter(const filesystem::path& gltfFilename) {
262 return loadModelAndCharacter(gltfFilename);
263}
264
265Character loadGltfCharacter(std::span<const std::byte> byteSpan) {
266 return loadModelAndCharacter(byteSpan);
267}
268
269std::tuple<MotionParameters, IdentityParameters, float> loadMotion(
270 const filesystem::path& gltfFilename) {
271 // ---------------------------------------------
272 // load model, parse motion data
273 // ---------------------------------------------
274 try {
275 fx::gltf::Document model = loadModel(gltfFilename);
276 return loadMotionFromModel(model);
277 } catch (std::runtime_error& err) {
278 MT_THROW("Unable to load gltf from file '{}'. Error: {}", gltfFilename.string(), err.what());
279 }
280}
281
282std::vector<int64_t> loadMotionTimestamps(const filesystem::path& gltfFilename) {
283 try {
284 fx::gltf::Document model = loadModel(gltfFilename);
285 const auto& def = getMomentumExtension(model.extensionsAndExtras);
286
287 // Check if motion section exists and has timestamps
288 if (def.count("motion") == 0) {
289 MT_LOGW("No motion data found in gltf file when loading timestamps");
290 return {};
291 }
292
293 const auto& motion = def["motion"];
294 if (!motion.contains("timestamps")) {
295 MT_LOGW("No timestamps found in gltf file");
296 return {};
297 }
298
299 // Extract timestamps from the JSON array
300 return motion["timestamps"].get<std::vector<int64_t>>();
301 } catch (const std::exception& err) {
302 MT_THROW(
303 "Unable to load timestamps from gltf file '{}'. Error: {}",
304 gltfFilename.string(),
305 err.what());
306 }
307}
308
309std::tuple<Character, MatrixXf, JointParameters, float> loadCharacterWithMotion(
310 const filesystem::path& gltfFilename) {
311 return loadCharacterWithMotionCommon(gltfFilename);
312}
313
314std::tuple<Character, MatrixXf, JointParameters, float> loadCharacterWithMotion(
315 std::span<const std::byte> byteSpan) {
316 return loadCharacterWithMotionCommon(byteSpan);
317}
318
319std::tuple<Character, MatrixXf, ModelParameters, float> loadCharacterWithMotionModelParameterScales(
320 const filesystem::path& gltfFilename) {
321 // Read the file into a buffer
322 std::ifstream file(gltfFilename, std::ios::binary | std::ios::ate);
323 MT_THROW_IF(!file.is_open(), "Unable to open file: {}", gltfFilename.string());
324
325 const std::streamsize size = file.tellg();
326 file.seekg(0, std::ios::beg);
327
328 std::vector<std::byte> buffer(size);
329 if (!file.read(reinterpret_cast<char*>(buffer.data()), size)) {
330 MT_THROW("Unable to read file: {}", gltfFilename.string());
331 }
332
333 // Delegate to the byteSpan overload to avoid code duplication
334 return loadCharacterWithMotionModelParameterScales(std::span<const std::byte>(buffer));
335}
336
337std::tuple<Character, MatrixXf, ModelParameters, float> loadCharacterWithMotionModelParameterScales(
338 std::span<const std::byte> byteSpan) {
339 auto [character, motion, jointIdentity, fps] = loadCharacterWithMotionCommon(byteSpan, true);
341 motion.rows() != character.parameterTransform.numAllModelParameters(),
342 "Mismatch between character and motion; character has {} model parameters while motion has {}.",
344 motion.rows());
345
346 auto modelIdentity =
347 applyModelParameterScales(character.parameterTransform, motion, jointIdentity);
348 return {character, motion, modelIdentity, fps};
349}
350
351std::tuple<Character, std::vector<SkeletonState>, std::vector<float>>
352loadCharacterWithSkeletonStates(std::span<const std::byte> byteSpan) {
354}
355
356std::tuple<Character, std::vector<SkeletonState>, std::vector<float>>
357loadCharacterWithSkeletonStates(const filesystem::path& gltfFilename) {
358 return loadCharacterWithSkeletonStatesCommon(gltfFilename);
359}
360
361std::tuple<MatrixXf, JointParameters, float> loadMotionOnCharacter(
362 const filesystem::path& gltfFilename,
363 const Character& character) {
364 return loadMotionOnCharacterCommon(gltfFilename, character);
365}
366
367std::tuple<MatrixXf, JointParameters, float> loadMotionOnCharacter(
368 const std::span<const std::byte> byteSpan,
369 const Character& character) {
370 return loadMotionOnCharacterCommon(byteSpan, character);
371}
372
373fx::gltf::Document makeCharacterDocument(
374 const Character& character,
375 const float fps,
376 const MotionParameters& motion,
377 const IdentityParameters& offsets,
378 std::span<const std::vector<Marker>> markerSequence,
379 bool embedResource,
380 const FileSaveOptions& options,
381 std::span<const int64_t> timestamps) {
382 GltfBuilder fileBuilder;
384 const auto kCharacterIsEmpty = character.skeleton.joints.empty() && character.mesh == nullptr;
385 if (!kCharacterIsEmpty) {
386 fileBuilder.addCharacter(character, Vector3f::Zero(), Quaternionf::Identity(), options);
387 }
388 // Add potential motion or offsets, even if the character is empty
389 // (it could be a motion database for example)
390 if ((!std::get<0>(motion).empty()) || (!std::get<0>(offsets).empty())) {
391 fileBuilder.addMotion(
392 character, fps, motion, offsets, options.extensions, "default", timestamps);
393 }
394 if (!markerSequence.empty()) {
395 fileBuilder.addMarkerSequence(fps, markerSequence);
396 }
397 if (embedResource) {
398 fileBuilder.forceEmbedResources();
399 }
400
401 return fileBuilder.getDocument();
402}
403
404namespace {
405
406MarkerSequence loadMarkerSequenceFromModel(fx::gltf::Document model) {
407 MarkerSequence result;
408
409 if (model.animations.empty()) {
410 return result;
411 }
412
413 const auto& def = getMomentumExtension(model.extensionsAndExtras);
414 const float fps = def.value("fps", 120.0f);
415 result.fps = fps;
416 // TODO: result.name = model.name;
417
418 const auto& animation = model.animations.front();
419
420 for (const auto& channel : animation.channels) {
421 // make sure we're on a translation channel
422 if (channel.target.path != "translation") {
423 continue;
424 }
425
426 // get the node for the channel
427 if (channel.target.node < 0 || static_cast<size_t>(channel.target.node) >= model.nodes.size()) {
428 continue;
429 }
430 const auto& node = model.nodes.at(channel.target.node);
431
432 // ignore skins and cameras; don't ignore meshes because a marker node may have a mesh for viz
433 if (node.skin >= 0 || node.camera >= 0) {
434 continue;
435 }
436
437 const auto& extension = getMomentumExtension(node.extensionsAndExtras);
438 const std::string type = extension.value("type", "");
439 if (type == "marker") {
440 // found a marker, get the sampler
441 const auto& sampler = animation.samplers[channel.sampler];
442
443 // get the data from the sampler
444 const auto timestamps = copyAccessorBuffer<float>(model, sampler.input);
445 auto positions = copyAccessorBuffer<Vector3f>(model, sampler.output);
446 toMomentumVec3f(positions);
447 if (positions.empty()) {
448 continue;
449 }
450 MT_CHECK(
451 timestamps.size() == positions.size(),
452 "timestamps: {}, positions: {}",
453 timestamps.size(),
454 positions.size());
455
456 // resize the output array if necessary
457 const size_t length = static_cast<size_t>(std::lround(timestamps.back() * fps)) + 1;
458 if (length > result.frames.size()) {
459 result.frames.resize(length);
460 }
461
462 // go over all data and enter into the output array
463 const auto& confArray =
464 extension.count("confidence") != 0 ? extension["confidence"] : nlohmann::json();
465 for (size_t i = 0; i < positions.size(); i++) {
466 const auto index = static_cast<size_t>(std::lround(timestamps[i] * fps));
467 result.frames[index].emplace_back();
468 auto& marker = result.frames[index].back();
469
470 marker.name = node.name;
471 marker.occluded = false;
472 marker.pos = positions[i].cast<double>();
473 if (confArray.is_array() && i < confArray.size()) {
474 marker.confidence = confArray[i].get<float>();
475 }
476 }
477 }
478 }
479
480 return result;
481}
482
483} // namespace
484
485MarkerSequence loadMarkerSequence(const filesystem::path& filename) {
486 return loadMarkerSequenceFromModel(loadModel(filename));
487}
488
489MarkerSequence loadMarkerSequence(std::span<const std::byte> byteSpan) {
490 return loadMarkerSequenceFromModel(loadModel(byteSpan));
491}
492
494 const filesystem::path& filename,
495 const Character& character,
496 const float fps,
497 const MotionParameters& motion,
498 const IdentityParameters& offsets,
499 std::span<const std::vector<Marker>> markerSequence,
500 const FileSaveOptions& options,
501 std::span<const int64_t> timestamps) {
502 constexpr auto kEmbedResources = false;
503 fx::gltf::Document model = makeCharacterDocument(
504 character, fps, motion, offsets, markerSequence, kEmbedResources, options, timestamps);
505
506 GltfBuilder::save(model, filename, options.gltfFileFormat, kEmbedResources);
507}
508
510 const filesystem::path& filename,
511 const Character& character,
512 const float fps,
513 std::span<const SkeletonState> skeletonStates,
514 std::span<const std::vector<Marker>> markerSequence,
515 const FileSaveOptions& options) {
516 constexpr auto kEmbedResources = false;
517 fx::gltf::Document model = ::makeCharacterDocument(
518 character, fps, skeletonStates, markerSequence, kEmbedResources, options);
519
520 GltfBuilder::save(model, filename, options.gltfFileFormat, kEmbedResources);
521}
522
523std::vector<std::byte> saveCharacterToBytes(
524 const Character& character,
525 float fps,
526 const MotionParameters& motion,
527 const IdentityParameters& offsets,
528 std::span<const std::vector<Marker>> markerSequence,
529 const FileSaveOptions& options,
530 std::span<const int64_t> timestamps) {
531 constexpr auto kEmbedResources = false;
532 fx::gltf::Document model = makeCharacterDocument(
533 character, fps, motion, offsets, markerSequence, kEmbedResources, options, timestamps);
534
535 std::ostringstream output(std::ios::binary | std::ios::out);
536 fx::gltf::Save(model, output, {}, true);
537 const auto view = output.str();
538 const auto n = view.size();
539 std::vector<std::byte> result(n);
540 for (size_t i = 0; i < n; ++i) {
541 result[i] = static_cast<std::byte>(view[i]);
542 }
543 return result;
544}
545
546} // namespace momentum
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
Definition checks.h:36
Helper class to build a glb scene.
void setAnimationInterpolation(GltfAnimationInterpolation interpolation)
Set how the joint and blend shape animation samplers added afterwards interpolate between their keys ...
const fx::gltf::Document & getDocument()
Allow copy the document, but do not allow modify the file outside of the builder to keep metadata con...
void addMotion(const Character &character, float fps=120.0f, const MotionParameters &motion={}, const IdentityParameters &offsets={}, bool addExtensions=true, const std::string &customName="default", std::span< const int64_t > timestamps={})
Add a motion to the provided character.
void addMarkerSequence(float fps, std::span< const std::vector< momentum::Marker > > markerSequence, MarkerMesh markerMesh=MarkerMesh::UnitCube, const std::string &animName="default")
Add marker data to the file.
void addCharacter(const Character &character, const Vector3f &positionOffset=Vector3f::Zero(), const Quaternionf &rotationOffset=Quaternionf::Identity(), const FileSaveOptions &options=FileSaveOptions())
Add a character to the scene.
void save(const filesystem::path &filename, GltfFileFormat fileFormat=GltfFileFormat::Auto, bool embedResources=false)
void addSkeletonStates(const Character &character, float fps, std::span< const SkeletonState > skeletonStates, const std::string &customName="default")
Add a skeleton states to the provided character.
void forceEmbedResources()
Set all existing buffers to embed resources.
#define MT_THROW(...)
Throws a std::runtime_error with a formatted message.
Definition exception.h:31
#define MT_THROW_IF(Condition,...)
Conditionally throws a std::runtime_error with a formatted message if the condition is true.
Definition exception.h:55
#define MT_LOGW(...)
Definition log.h:180
ParameterLimits parameterLimitsFromJson(const Character &character, const nlohmann::json &j)
std::tuple< MotionParameters, IdentityParameters, float > loadMotion(const filesystem::path &gltfFilename)
Load motion data from a glTF file.
Definition gltf_io.cpp:269
::std::unique_ptr< BlendShape > BlendShape_u
Definition fwd.h:21
std::tuple< std::vector< std::string >, JointParameters > IdentityParameters
A tuple of skeleton joint names and identity parameters.
Definition types.h:179
std::tuple< std::string, JointList, CollisionGeometry_u, LocatorList, PhysicalProperties, std::vector< size_t > > loadHierarchy(const fx::gltf::Document &model)
Load the hierarchy from the model.
std::tuple< Character, std::vector< SkeletonState >, std::vector< float > > loadCharacterWithSkeletonStates(std::span< const std::byte > byteSpan)
Load a glTF character with motion in the form of skeleton states.
Definition gltf_io.cpp:352
ModelParameters applyModelParameterScales(const ParameterTransform &parameterTransform, MatrixXf &motion, const JointParameters &jointIdentity)
Apply model parameter scale conversion to motion data.
void saveGltfCharacter(const filesystem::path &filename, const Character &character, const float fps, const MotionParameters &motion, const IdentityParameters &offsets, std::span< const std::vector< Marker > > markerSequence, const FileSaveOptions &options, std::span< const int64_t > timestamps)
Save a character with motion to a glTF file.
Definition gltf_io.cpp:493
SkinWeights_u bindMeshToJoint(const Mesh_u &mesh, size_t jointId)
Bind a mesh to a single joint.
std::tuple< MatrixXf, JointParameters, float > loadMotionOnCharacterCommon(const std::variant< filesystem::path, std::span< const std::byte > > &input, const Character &character)
Load motion onto a character (common implementation).
std::vector< std::byte > saveCharacterToBytes(const Character &character, float fps, const MotionParameters &motion, const IdentityParameters &offsets, std::span< const std::vector< Marker > > markerSequence, const FileSaveOptions &options, std::span< const int64_t > timestamps)
Save a character with motion to a byte buffer.
Definition gltf_io.cpp:523
std::tuple< std::vector< std::string >, Eigen::MatrixXf > MotionParameters
A tuple of model parameter names and a matrix of poses across a sequence of frames.
Definition types.h:173
Character loadGltfCharacterInternal(const fx::gltf::Document &model, std::vector< size_t > &nodeToObjectMap)
Internal function to load a character from a glTF model with node-to-object mapping.
Definition gltf_io.cpp:240
JointList createSkeletonWithOnlyRoot()
Create a skeleton with only a root joint.
Vector3f toMomentumVec3f(const std::array< float, 3 > &vec) noexcept
fx::gltf::Document makeCharacterDocument(const Character &character, const float fps, const MotionParameters &motion, const IdentityParameters &offsets, std::span< const std::vector< Marker > > markerSequence, bool embedResource, const FileSaveOptions &options, std::span< const int64_t > timestamps)
Create a glTF document from a character.
Definition gltf_io.cpp:373
std::tuple< Character, MatrixXf, ModelParameters, float > loadCharacterWithMotionModelParameterScales(const filesystem::path &gltfFilename)
Load a glTF character with motion and apply scale parameters to the motion.
Definition gltf_io.cpp:319
std::vector< T > copyAccessorBuffer(const fx::gltf::Document &model, int32_t id)
std::tuple< Character, std::vector< SkeletonState >, std::vector< float > > loadCharacterWithSkeletonStatesCommon(const std::variant< filesystem::path, std::span< const std::byte > > &input)
Load character with skeleton states from input (common implementation).
std::tuple< Character, MatrixXf, JointParameters, float > loadCharacterWithMotionCommon(const std::variant< filesystem::path, std::span< const std::byte > > &input, bool mapParameters)
Load character with motion from input (common implementation).
constexpr size_t kParametersPerJoint
Definition types.h:21
ParameterTransform parameterTransformFromJson(const Character &character, const nlohmann::json &j)
MarkerSequence loadMarkerSequence(const filesystem::path &filename)
Load a marker sequence from a glTF file.
Definition gltf_io.cpp:485
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
Definition types.h:182
ParameterSets parameterSetsFromJson(const Character &character, const nlohmann::json &j)
Character loadGltfCharacter(const fx::gltf::Document &model)
Load a glTF character from a document.
Definition gltf_io.cpp:256
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.
std::tuple< MatrixXf, JointParameters, float > loadMotionOnCharacter(const filesystem::path &gltfFilename, const Character &character)
Load motion from a glTF file and map it to a character.
Definition gltf_io.cpp:361
std::tuple< MotionParameters, IdentityParameters, float > loadMotionFromModel(fx::gltf::Document &model)
Load motion data from a glTF model.
PoseConstraints poseConstraintsFromJson(const Character &character, const nlohmann::json &j)
std::tuple< Character, MatrixXf, JointParameters, float > loadCharacterWithMotion(const filesystem::path &gltfFilename)
Load a glTF character with motion from a file path.
Definition gltf_io.cpp:309
std::vector< int64_t > loadMotionTimestamps(const filesystem::path &gltfFilename)
Load per-frame timestamps from a glTF file.
Definition gltf_io.cpp:282
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
LocatorList locators
Points of interest attached to joints.
Definition character.h:49
SkinWeights_u skinWeights
Defines how mesh vertices are influenced by joints.
Definition character.h:58
void initInverseBindPose()
Initializes the inverse bind pose transformations.
void resetJointMap()
Resets the joint map to identity (each joint maps to itself).
PhysicalProperties physicalProperties
Joint-level physical mass and inertia data loaded from model assets.
Definition character.h:67
ParameterLimits parameterLimits
Constraints on model parameters.
Definition character.h:46
Mesh_u mesh
3D mesh representing the character's surface
Definition character.h:55
Skeleton skeleton
Skeletal structure defining the character's joints and hierarchy.
Definition character.h:36
std::string name
Character identifier.
Definition character.h:82
ParameterTransform parameterTransform
Maps model parameters to joint parameters.
Definition character.h:39
BlendShape_const_p blendShape
Shape variations that can be blended.
Definition character.h:70
std::string metadata
Metadata (as a JSON-serialized string).
Definition character.h:85
CollisionGeometry_u collision
Collision volumes for the character.
Definition character.h:64
Unified options for saving files in both FBX and GLTF formats.
bool extensions
Enable GLTF extensions (default: true) Only used for GLTF output.
GltfAnimationInterpolation gltfAnimationInterpolation
Interpolation of the joint and blend shape animation samplers (default: Step) Marker animation always...
GltfFileFormat gltfFileFormat
GLTF file format selection (default: Auto) Only used for GLTF output.
All frames from a single motion capture sequence for one subject (actor).
Definition marker.h:37
float fps
Frame rate of the capture, in frames per second.
Definition marker.h:45
std::vector< std::vector< Marker > > frames
All marker observations across the sequence. Layout: [numFrames][numMarkers].
Definition marker.h:42
static ParameterTransformT< float > empty(size_t nJointParameters)
Eigen::Index numAllModelParameters() const
Dimension of all model parameters, including pose, scaling, marker joints, and blendshape parameters ...
PoseConstraints poseConstraints
A set of predefined poses.
ParameterSets parameterSets
Convenience grouping of model parameters.
JointList joints
The list of joints in this skeleton, ordered such that every joint's parent appears earlier in the li...
Definition skeleton.h:25
istream that takes a span of const bytes as input.