26void addIOOptions(CLI::App& app, std::shared_ptr<IOOptions> ioOptions) {
28 app.add_option(
"-i,--input", ioOptions->inputFile,
"Marker data file (.kbd/.glb/.c3d/.trc)");
29 inputOption->required()->check(CLI::ExistingFile);
31 auto* outputOption = app.add_option(
"-o,--output", ioOptions->outputFile,
"Output glb file");
32 outputOption->required();
36 auto* modelOption = app.add_option(
37 "-m,--model", modelOptions->model,
"Model file (.fbx/.glb -- may contain calibrated model)");
38 modelOption->required()->check(CLI::ExistingFile);
40 app.add_option(
"-p,--parameters", modelOptions->parameters,
"Model parameter file (.model)");
41 app.add_option(
"-l,--locators", modelOptions->locators,
"Marker definitions (.locators)");
46 app.add_option(
"--calib-debug", config->debug,
"Save debug info for calibration");
47 debugOption->default_val(config->debug);
49 auto* calibFramesOption = app.add_option(
50 "--calib-frames", config->calibFrames,
"Number of frames used for model calibration");
51 calibFramesOption->default_val(config->calibFrames)->check(CLI::PositiveNumber);
53 auto* majorIterOption =
54 app.add_option(
"--major-iter", config->majorIter,
"Number of calibration loops to run");
55 majorIterOption->default_val(config->majorIter)->check(CLI::PositiveNumber);
57 auto* maxCalibIterOption = app.add_option(
58 "--max-calib-iter", config->maxIter,
"Max (minor) iterations in one calibration solve");
59 maxCalibIterOption->default_val(config->maxIter)->check(CLI::PositiveNumber);
61 auto* minVisPercentOption = app.add_option(
62 "--min-calib-vis-percent",
63 config->minVisPercent,
64 "Minimum percentage of visible markers used for calibration");
65 minVisPercentOption->default_val(config->minVisPercent)->check(CLI::Range(0.0, 1.0));
68 app.add_option(
"--calib-loss-alpha", config->lossAlpha,
"Alpha value of calibration loss");
69 alphaOption->default_val(config->lossAlpha);
71 auto* scaleOnlyOption = app.add_option(
72 "--global-scale-only",
73 config->globalScaleOnly,
74 "Calibrate only the global scale and not all proportions");
75 scaleOnlyOption->default_val(config->globalScaleOnly);
77 auto* locatorsOnlyOption =
78 app.add_option(
"--locators-only", config->locatorsOnly,
"Calibrate only the locator offsets");
79 locatorsOnlyOption->default_val(config->locatorsOnly);
81 auto* greedySamplingOption = app.add_option(
83 config->greedySampling,
84 "Use greedy sampling to select calibration frames");
85 greedySamplingOption->default_val(config->greedySampling)->check(CLI::NonNegativeNumber);
87 auto* enforceFloorOption = app.add_flag(
88 "--enforce-floor-in-first-frame",
89 config->enforceFloorInFirstFrame,
90 "Force all floor locators to y=0 on frame 0 with high weight");
91 enforceFloorOption->default_val(config->enforceFloorInFirstFrame);
93 auto* adaptiveFloorContactOption = app.add_flag(
94 "--adaptive-floor-contact",
95 config->adaptiveFloorContact,
96 "Enable adaptive per-locator floor contact detection during calibration");
97 adaptiveFloorContactOption->default_val(config->adaptiveFloorContact);
99 auto* poseOption = app.add_option(
101 config->firstFramePoseConstraintSet,
102 "Enforce pose constraints from named pose constraint set in first frame");
103 poseOption->default_val(config->firstFramePoseConstraintSet);
108 app.add_option(
"--tracking-debug", config->debug,
"Save debug info for tracking");
109 debugOption->default_val(config->debug);
112 app.add_option(
"--tracking-loss-alpha", config->lossAlpha,
"Alpha value of tracking loss");
113 alphaOption->default_val(config->lossAlpha);
116 app.add_option(
"--smoothing", config->smoothing,
"Smoothing weight; 0 to disable");
117 smoothOption->default_val(config->smoothing)->check(CLI::NonNegativeNumber);
119 auto* collisionErrorWeightOption = app.add_option(
120 "--collision-error-weight",
121 config->collisionErrorWeight,
122 "Collision error weight, default is 0.0");
123 collisionErrorWeightOption->default_val(config->collisionErrorWeight)
124 ->check(CLI::NonNegativeNumber);
126 auto* maxTrackingIterOption = app.add_option(
127 "--max-tracking-iter", config->maxIter,
"Max iterations for motion tracking solve");
128 maxTrackingIterOption->default_val(config->maxIter)->check(CLI::PositiveNumber);
130 auto* minVisPercentOption = app.add_option(
131 "--min-tracking-vis-percent",
132 config->minVisPercent,
133 "Minimum percentage of visible markers used for tracking");
134 minVisPercentOption->default_val(config->minVisPercent)->check(CLI::Range(0.0, 1.0));
140 auto* regOption = app.add_option(
143 "Regularize time-invariant parameters to prevent large change");
144 regOption->default_val(config->regularizer)->check(CLI::NonNegativeNumber);
146 auto* calibIdOption =
147 app.add_option(
"--calib-id", config->calibId,
"Calibrate identity parameters");
148 calibIdOption->default_val(config->calibId);
150 auto* calibLocatorsOption =
151 app.add_option(
"--calib-locators", config->calibLocators,
"Calibrate locator offsets");
152 calibLocatorsOption->default_val(config->calibLocators);
156 const std::string& modelFile) {
163 return {c, identity};
172 if (modelFiles.
model.find(
".glb") != std::string::npos &&
177 if (
id.v.size() > 0) {
192 return {character, identity};
196 const std::string& outFile,
199 Eigen::MatrixXf& finalMotion,
200 std::span<
const std::vector<momentum::Marker>> markerData,
202 const bool saveMarkerMesh ,
203 std::span<const int64_t> timestamps ) {
204 const filesystem::path output(outFile);
205 const auto ext = output.extension();
215 saveFbx(output, character, finalMotion, idVec, fps);
216 }
else if (ext ==
".glb" || ext ==
".gltf") {
230 fileBuilder.
save(outFile);
Helper class to build a glb scene.
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 save(const filesystem::path &filename, GltfFileFormat fileFormat=GltfFileFormat::Auto, bool embedResources=false)
std::tuple< momentum::Character, momentum::ModelParameters > loadCalibratedModel(const std::string &modelFile)
void addRefineOptions(CLI::App &app, std::shared_ptr< RefineConfig > config)
void addTrackingOptions(CLI::App &app, std::shared_ptr< TrackingConfig > config)
void addIOOptions(CLI::App &app, std::shared_ptr< IOOptions > ioOptions)
void addCalibrationOptions(CLI::App &app, std::shared_ptr< CalibrationConfig > config)
Character loadFullCharacter(const std::string &characterPath, const std::string ¶metersPath, const std::string &locatorsPath, LoadBlendShapes loadBlendShapes)
High level function to load a character of any type, with a local path.
void saveMotion(const std::string &outFile, const momentum::Character &character, const momentum::ModelParameters &identity, Eigen::MatrixXf &finalMotion, std::span< const std::vector< momentum::Marker > > markerData, const double fps, const bool saveMarkerMesh, std::span< const int64_t > timestamps)
Save the given character and motion to a GLB or FBX file.
void saveFbx(const filesystem::path &, const Character &, const MatrixXf &, const VectorXf &, const double, std::span< const std::vector< Marker > >, const FileSaveOptions &)
Save a character with animation to an FBX file.
void removeIdentity(const ParameterSet &idSet, const ModelParameters &identity, Eigen::MatrixXf &motionWithId)
ModelParameters jointIdentityToModelIdentity(const Character &c, const ParameterSet &idSet, const JointParameters &jointIdentity)
ModelParameters extractParameters(const ModelParameters ¶ms, const ParameterSet ¶meterSet)
LocatorList loadLocators(const filesystem::path &filename, const Skeleton &skeleton, const ParameterTransform ¶meterTransform)
ModelParametersT< float > ModelParameters
std::tuple< momentum::Character, momentum::ModelParameters > loadCharacterWithIdentity(const ModelOptions &modelFiles)
VectorX< float > VectorXf
std::tuple< Character, MatrixXf, JointParameters, float > loadCharacterWithMotion(const filesystem::path &gltfFilename)
Load a glTF character with motion from a file path.
void addModelOptions(CLI::App &app, std::shared_ptr< ModelOptions > modelOptions)
A character model with skeletal structure, mesh, and optional components.
LocatorList locators
Points of interest attached to joints.
Skeleton skeleton
Skeletal structure defining the character's joints and hierarchy.
ParameterTransform parameterTransform
Maps model parameters to joint parameters.
static EIGEN_DEVICE_FUNC Derived< Scalar > Zero(::Eigen::Index size)
std::vector< std::string > getJointNames() const