Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
momentum::GltfBuilder Class Referencefinal

Helper class to build a glb scene. More...

#include <gltf_builder.h>

Classes

struct  Impl

Public Types

enum class  MarkerMesh : uint8_t { None , UnitCube }
 Specify how marker mesh is represented in the glb file. More...

Public Member Functions

 GltfBuilder ()
 ~GltfBuilder ()
 GltfBuilder (GltfBuilder const &)=delete
void operator= (GltfBuilder const &)=delete
 GltfBuilder (GltfBuilder &&) noexcept
GltfBuilder & operator= (GltfBuilder &&) noexcept
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 setFps (float fps)
void setAnimationInterpolation (GltfAnimationInterpolation interpolation)
 Set how the joint and blend shape animation samplers added afterwards interpolate between their keys (default: Step).
GltfAnimationInterpolation getAnimationInterpolation () const
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 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 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 save (const filesystem::path &filename, GltfFileFormat fileFormat=GltfFileFormat::Auto, bool embedResources=false)
void forceEmbedResources ()
 Set all existing buffers to embed resources.
const fx::gltf::Document & getDocument ()
 Allow copy the document, but do not allow modify the file outside of the builder to keep metadata consistent.
size_t getNumCharacters ()
size_t getCharacterRootIndex (const std::string &name)
size_t getNumJoints (const std::string &name)
size_t getNumMotions ()
float getFps ()
std::vector< size_t > getCharacterMotions (const std::string &characterName)

Static Public Member Functions

static void save (fx::gltf::Document &document, const filesystem::path &filename, GltfFileFormat fileFormat=GltfFileFormat::Auto, bool embedResources=false)
static void forceEmbedResources (fx::gltf::Document &document)

Detailed Description

Helper class to build a glb scene.

It supports adding multiple characters and motions for each character. By default, momentum extension is added to the glb nodes. This is required if you want to correctly load the exported character back.

Definition at line 33 of file gltf_builder.h.

Member Enumeration Documentation

◆ MarkerMesh

enum class momentum::GltfBuilder::MarkerMesh : uint8_t
strong

Specify how marker mesh is represented in the glb file.

Enumerator
None 
UnitCube 

Definition at line 48 of file gltf_builder.h.

Constructor & Destructor Documentation

◆ GltfBuilder() [1/3]

momentum::GltfBuilder::GltfBuilder ( )

Definition at line 959 of file gltf_builder.cpp.

Referenced by addCharacter(), GltfBuilder(), GltfBuilder(), operator=(), and operator=().

◆ ~GltfBuilder()

momentum::GltfBuilder::~GltfBuilder ( )
default

◆ GltfBuilder() [2/3]

momentum::GltfBuilder::GltfBuilder ( GltfBuilder const & )
delete

References GltfBuilder().

◆ GltfBuilder() [3/3]

momentum::GltfBuilder::GltfBuilder ( GltfBuilder && )
defaultnoexcept

References GltfBuilder().

Member Function Documentation

◆ addCharacter()

void momentum::GltfBuilder::addCharacter ( const Character & character,
const Vector3f & positionOffset = Vector3f::Zero(),
const Quaternionf & rotationOffset = Quaternionf::Identity(),
const FileSaveOptions & options = FileSaveOptions() )

Add a character to the scene.

Each character will have a root node with the character's name as the parent of the skeleton root and the character mesh. positionOffset and rotationOffset can be provided as an initial offset to the character.

Definition at line 970 of file gltf_builder.cpp.

References addCharacter(), momentum::fromMomentumQuaternionf(), momentum::fromMomentumVec3f(), GltfBuilder(), MT_CHECK, momentum::parameterLimitsToJson(), momentum::parameterSetsToJson(), momentum::parameterTransformToJson(), and momentum::poseConstraintsToJson().

Referenced by addCharacter(), addMotion(), addSkeletonStates(), and momentum::makeCharacterDocument().

◆ addMarkerSequence()

void momentum::GltfBuilder::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.

Parameters
[in]fpsThe frame rate of the motion capture data in frames per second.
[in]markerSequenceA 2D vector specifying the Marker data (name/position/occlusion) for all markers across all captured frames. Size: [numFrames][numMarkers]
[in]markerMeshOptional parameter specifying the MarkerMesh type (default is MarkerMesh::None).
[in]animNameOptional parameter specifying the animation name (default is "default").

Definition at line 1164 of file gltf_builder.cpp.

References setFps().

Referenced by momentum::makeCharacterDocument(), and momentum::saveMotion().

◆ addMesh()

void momentum::GltfBuilder::addMesh ( const Mesh & mesh,
const std::string & name,
bool addColor = false )

Add a static mesh, such as an environment or a target scan.

Definition at line 1032 of file gltf_builder.cpp.

References MT_LOGW.

◆ addMotion()

void momentum::GltfBuilder::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.

If addCharacter is not called before adding the motion, the character will be automatically added with the default settings.

Parameters
[in]characterThe character to add motion for.
[in]fpsFrame rate of the motion in frames per second.
[in]motionMotion parameters (parameter names and poses matrix).
[in]offsetsIdentity/offset parameters (joint names and offsets vector).
[in]addExtensionsWhether to add momentum extensions to the document.
[in]customNameCustom name for the animation (default is "default").
[in]timestampsPer-frame timestamps. Size should match motion columns.

Definition at line 1091 of file gltf_builder.cpp.

References addCharacter(), MT_THROW_IF, momentum::Character::name, and setFps().

Referenced by momentum::makeCharacterDocument(), and momentum::saveMotion().

◆ addSkeletonStates()

void momentum::GltfBuilder::addSkeletonStates ( const Character & character,
float fps,
std::span< const SkeletonState > skeletonStates,
const std::string & customName = "default" )

Add a skeleton states to the provided character.

If addCharacter is not called before adding the skeleton states, the character will be automatically added with the default settings.

Definition at line 1205 of file gltf_builder.cpp.

References addCharacter(), momentum::Character::name, and setFps().

◆ forceEmbedResources() [1/2]

void momentum::GltfBuilder::forceEmbedResources ( )

Set all existing buffers to embed resources.

Definition at line 1190 of file gltf_builder.cpp.

References forceEmbedResources().

Referenced by forceEmbedResources(), momentum::makeCharacterDocument(), and save().

◆ forceEmbedResources() [2/2]

void momentum::GltfBuilder::forceEmbedResources ( fx::gltf::Document & document)
static

Definition at line 1180 of file gltf_builder.cpp.

◆ getAnimationInterpolation()

GltfAnimationInterpolation momentum::GltfBuilder::getAnimationInterpolation ( ) const
nodiscard
Returns
The sampler interpolation used by addMotion and addSkeletonStates.

Definition at line 1073 of file gltf_builder.cpp.

◆ getCharacterMotions()

std::vector< size_t > momentum::GltfBuilder::getCharacterMotions ( const std::string & characterName)

Definition at line 1157 of file gltf_builder.cpp.

◆ getCharacterRootIndex()

size_t momentum::GltfBuilder::getCharacterRootIndex ( const std::string & name)

Definition at line 1055 of file gltf_builder.cpp.

References momentum::kInvalidIndex.

◆ getDocument()

const fx::gltf::Document & momentum::GltfBuilder::getDocument ( )

Allow copy the document, but do not allow modify the file outside of the builder to keep metadata consistent.

Definition at line 1186 of file gltf_builder.cpp.

Referenced by momentum::makeCharacterDocument().

◆ getFps()

float momentum::GltfBuilder::getFps ( )

Definition at line 1148 of file gltf_builder.cpp.

◆ getNumCharacters()

size_t momentum::GltfBuilder::getNumCharacters ( )

Definition at line 1051 of file gltf_builder.cpp.

◆ getNumJoints()

size_t momentum::GltfBuilder::getNumJoints ( const std::string & name)

Definition at line 1062 of file gltf_builder.cpp.

References momentum::kInvalidIndex.

◆ getNumMotions()

size_t momentum::GltfBuilder::getNumMotions ( )

Definition at line 1144 of file gltf_builder.cpp.

◆ operator=() [1/2]

GltfBuilder & momentum::GltfBuilder::operator= ( GltfBuilder && )
defaultnoexcept

References GltfBuilder().

◆ operator=() [2/2]

void momentum::GltfBuilder::operator= ( GltfBuilder const & )
delete

References GltfBuilder().

◆ save() [1/2]

void momentum::GltfBuilder::save ( const filesystem::path & filename,
GltfFileFormat fileFormat = GltfFileFormat::Auto,
bool embedResources = false )

◆ save() [2/2]

void momentum::GltfBuilder::save ( fx::gltf::Document & document,
const filesystem::path & filename,
GltfFileFormat fileFormat = GltfFileFormat::Auto,
bool embedResources = false )
static

Definition at line 1194 of file gltf_builder.cpp.

References forceEmbedResources().

◆ setAnimationInterpolation()

void momentum::GltfBuilder::setAnimationInterpolation ( GltfAnimationInterpolation interpolation)

Set how the joint and blend shape animation samplers added afterwards interpolate between their keys (default: Step).

Marker animation always uses Step.

Parameters
[in]interpolationSampler interpolation for addMotion and addSkeletonStates.

Definition at line 1069 of file gltf_builder.cpp.

Referenced by momentum::makeCharacterDocument().

◆ setFps()

void momentum::GltfBuilder::setFps ( float fps)

Definition at line 1077 of file gltf_builder.cpp.

References MT_LOGW.

Referenced by addMarkerSequence(), addMotion(), and addSkeletonStates().


The documentation for this class was generated from the following files: