Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
gltf_io.h
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
8#pragma once
9
14#include <momentum/math/types.h>
15
16#include <fx/gltf.h>
17#include <span>
18
19#include <tuple>
20#include <vector>
21
22namespace momentum {
23
28Character loadGltfCharacter(const fx::gltf::Document& model);
29
36Character loadGltfCharacter(const filesystem::path& gltfFilename);
37
42Character loadGltfCharacter(std::span<const std::byte> byteSpan);
43
48std::tuple<MotionParameters, IdentityParameters, float> loadMotion(
49 const filesystem::path& gltfFilename);
50
57std::vector<int64_t> loadMotionTimestamps(const filesystem::path& gltfFilename);
58
68std::tuple<Character, MatrixXf, momentum::JointParameters, float> loadCharacterWithMotion(
69 const filesystem::path& gltfFilename);
70
76std::tuple<Character, MatrixXf, momentum::JointParameters, float> loadCharacterWithMotion(
77 std::span<const std::byte> byteSpan);
78
90std::tuple<Character, MatrixXf, momentum::ModelParameters, float>
91loadCharacterWithMotionModelParameterScales(std::span<const std::byte> byteSpan);
92
104std::tuple<Character, MatrixXf, momentum::ModelParameters, float>
105loadCharacterWithMotionModelParameterScales(const filesystem::path& gltfFilename);
106
117std::tuple<Character, std::vector<SkeletonState>, std::vector<float>>
118loadCharacterWithSkeletonStates(std::span<const std::byte> byteSpan);
119
130std::tuple<Character, std::vector<SkeletonState>, std::vector<float>>
131loadCharacterWithSkeletonStates(const filesystem::path& gltfFilename);
132
145std::tuple<MatrixXf, JointParameters, float> loadMotionOnCharacter(
146 const filesystem::path& gltfFilename,
147 const Character& character);
148
160std::tuple<MatrixXf, JointParameters, float> loadMotionOnCharacter(
161 std::span<const std::byte> byteSpan,
162 const Character& character);
163
170MarkerSequence loadMarkerSequence(const filesystem::path& filename);
171
180MarkerSequence loadMarkerSequence(std::span<const std::byte> byteSpan);
181
196fx::gltf::Document makeCharacterDocument(
197 const Character& character,
198 float fps = 120.0f,
199 const MotionParameters& motion = {},
200 const IdentityParameters& offsets = {},
201 std::span<const std::vector<Marker>> markerSequence = {},
202 bool embedResource = true,
203 const FileSaveOptions& options = FileSaveOptions(),
204 std::span<const int64_t> timestamps = {});
205
222 const filesystem::path& filename,
223 const Character& character,
224 float fps = 120.0f,
225 const MotionParameters& motion = {},
226 const IdentityParameters& offsets = {},
227 std::span<const std::vector<Marker>> markerSequence = {},
228 const FileSaveOptions& options = FileSaveOptions(),
229 std::span<const int64_t> timestamps = {});
230
244 const filesystem::path& filename,
245 const Character& character,
246 float fps,
247 std::span<const SkeletonState> skeletonStates,
248 std::span<const std::vector<Marker>> markerSequence = {},
249 const FileSaveOptions& options = FileSaveOptions());
250
266std::vector<std::byte> saveCharacterToBytes(
267 const Character& character,
268 float fps = 120.0f,
269 const MotionParameters& motion = {},
270 const IdentityParameters& offsets = {},
271 std::span<const std::vector<Marker>> markerSequence = {},
272 const FileSaveOptions& options = FileSaveOptions(),
273 std::span<const int64_t> timestamps = {});
274
275} // namespace momentum
std::tuple< MotionParameters, IdentityParameters, float > loadMotion(const filesystem::path &gltfFilename)
Load motion data from a glTF file.
Definition gltf_io.cpp:269
std::tuple< std::vector< std::string >, JointParameters > IdentityParameters
A tuple of skeleton joint names and identity parameters.
Definition types.h:179
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
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
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
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
MarkerSequence loadMarkerSequence(const filesystem::path &filename)
Load a marker sequence from a glTF file.
Definition gltf_io.cpp:485
Character loadGltfCharacter(const fx::gltf::Document &model)
Load a glTF character from a document.
Definition gltf_io.cpp:256
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< 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
Unified options for saving files in both FBX and GLTF formats.
All frames from a single motion capture sequence for one subject (actor).
Definition marker.h:37