Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
gltf_builder.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
15#include <momentum/math/mesh.h>
16#include <momentum/math/types.h>
17
18#include <fx/gltf.h>
19
20namespace fx::gltf {
21struct Document;
22} // namespace fx::gltf
23
24namespace momentum {
25
26using MotionParameters = std::tuple<std::vector<std::string>, MatrixXf>;
27using IdentityParameters = std::tuple<std::vector<std::string>, JointParameters>;
28
33class GltfBuilder final {
34 public:
36
38
39 GltfBuilder(GltfBuilder const&) = delete;
40
41 void operator=(GltfBuilder const&) = delete;
42
44
45 GltfBuilder& operator=(GltfBuilder&&) noexcept;
46
48 enum class MarkerMesh : uint8_t { None, UnitCube };
49
53 void addCharacter(
54 const Character& character,
55 const Vector3f& positionOffset = Vector3f::Zero(),
56 const Quaternionf& rotationOffset = Quaternionf::Identity(),
57 const FileSaveOptions& options = FileSaveOptions());
58
60 void addMesh(const Mesh& mesh, const std::string& name, bool addColor = false);
61
62 void setFps(float fps);
63
69
72
83 void addMotion(
84 const Character& character,
85 float fps = 120.0f,
86 const MotionParameters& motion = {},
87 const IdentityParameters& offsets = {},
88 bool addExtensions = true,
89 const std::string& customName = "default",
90 std::span<const int64_t> timestamps = {});
91
95 const Character& character,
96 float fps,
97 std::span<const SkeletonState> skeletonStates,
98 const std::string& customName = "default");
99
109 float fps,
110 std::span<const std::vector<momentum::Marker>> markerSequence,
111 MarkerMesh markerMesh = MarkerMesh::UnitCube,
112 const std::string& animName = "default");
113
114 // Save the file with the provided filename. If the fileFormat is 'GltfFileFormat::Auto',
115 // will deduct the file format by filename.
116 // When embedResources is true, it will set all the existing buffers to embed the data.
117 void save(
118 const filesystem::path& filename,
120 bool embedResources = false);
121
122 static void save(
123 fx::gltf::Document& document,
124 const filesystem::path& filename,
126 bool embedResources = false);
127
129 void forceEmbedResources();
130
131 static void forceEmbedResources(fx::gltf::Document& document);
132
135 const fx::gltf::Document& getDocument();
136
137 size_t getNumCharacters();
138
139 size_t getCharacterRootIndex(const std::string& name);
140
141 size_t getNumJoints(const std::string& name);
142
143 size_t getNumMotions();
144
145 float getFps();
146
147 std::vector<size_t> getCharacterMotions(const std::string& characterName);
148
149 private:
150 struct Impl;
151 std::unique_ptr<Impl> impl_;
152};
153
154} // namespace momentum
void setAnimationInterpolation(GltfAnimationInterpolation interpolation)
Set how the joint and blend shape animation samplers added afterwards interpolate between their keys ...
GltfBuilder(GltfBuilder &&) noexcept
GltfBuilder(GltfBuilder const &)=delete
void operator=(GltfBuilder const &)=delete
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.
std::vector< size_t > getCharacterMotions(const std::string &characterName)
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 addMesh(const Mesh &mesh, const std::string &name, bool addColor=false)
Add a static mesh, such as an environment or a target scan.
void save(const filesystem::path &filename, GltfFileFormat fileFormat=GltfFileFormat::Auto, bool embedResources=false)
MarkerMesh
Specify how marker mesh is represented in the glb file.
size_t getCharacterRootIndex(const std::string &name)
size_t getNumJoints(const std::string &name)
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.
GltfAnimationInterpolation getAnimationInterpolation() const
void forceEmbedResources()
Set all existing buffers to embed resources.
std::tuple< std::vector< std::string >, JointParameters > IdentityParameters
A tuple of skeleton joint names and identity parameters.
Definition types.h:179
Quaternion< float > Quaternionf
Definition types.h:386
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
MeshT< float > Mesh
Definition fwd.h:20
GltfAnimationInterpolation
How animation samplers written to a GLTF file interpolate between their keys.
JointParametersT< float > JointParameters
Definition types.h:135
GltfFileFormat
File format in which the character is saved.
Vector3< float > Vector3f
Definition types.h:251
MatrixX< float > MatrixXf
Definition types.h:82
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.