Skip to content

Commit 92cf282

Browse files
committed
Update convert_model to use new fbx features
Differential Revision: D85744246
1 parent 9a9a450 commit 92cf282

File tree

2 files changed

+22
-47
lines changed

2 files changed

+22
-47
lines changed

momentum/examples/convert_model/convert_model.cpp

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <momentum/io/character_io.h>
1414
#include <momentum/io/fbx/fbx_io.h>
1515
#include <momentum/io/gltf/gltf_io.h>
16-
#include <momentum/io/motion/mmo_io.h>
16+
#include <momentum/io/marker/marker_io.h>
1717
#include <momentum/io/skeleton/locator_io.h>
1818
#include <momentum/io/skeleton/parameter_transform_io.h>
1919
#include <momentum/io/skeleton/parameters_io.h>
@@ -32,6 +32,7 @@ struct Options {
3232
std::string output_model_file;
3333
std::string output_locator_local;
3434
std::string output_locator_global;
35+
std::string fbx_namespace;
3536
bool save_markers = false;
3637
bool character_mesh_save = false;
3738
};
@@ -50,7 +51,7 @@ std::shared_ptr<Options> setupOptions(CLI::App& app) {
5051
app.add_option("-l,--locator", opt->input_locator_file, "Input locator file (.locators)")
5152
->check(CLI::ExistingFile);
5253

53-
app.add_option("-d,--motion", opt->input_motion_file, "Input motion data file (.mmo/.glb/.fbx)")
54+
app.add_option("-d,--motion", opt->input_motion_file, "Input motion data file (.glb/.fbx)")
5455
->check(CLI::ExistingFile);
5556

5657
app.add_option("-o,--out", opt->output_model_file, "Output file (.fbx/.glb)")->required();
@@ -63,11 +64,10 @@ std::shared_ptr<Options> setupOptions(CLI::App& app) {
6364
"--out-locator-global",
6465
opt->output_locator_global,
6566
"Output a locator file (.locators) in global space for authoring a template");
67+
app.add_option("--fbx-namespace", opt->fbx_namespace, "Namespace in output fbx file");
6668

6769
app.add_flag(
68-
"--save-markers",
69-
opt->save_markers,
70-
"Save marker data from motion file in output (glb only)");
70+
"--save-markers", opt->save_markers, "Save marker data from input motion file in the output");
7171
app.add_flag(
7272
"-c,--character-mesh",
7373
opt->character_mesh_save,
@@ -109,23 +109,11 @@ int main(int argc, char** argv) {
109109

110110
MarkerSequence markerSequence;
111111
bool saveMarkers = options->save_markers;
112-
if (saveMarkers && oextension == ".fbx") {
113-
MT_LOGW("We cannot save marker data in .fbx yet, sorry!");
114-
saveMarkers = false;
115-
}
116112

117113
if (hasMotion) {
118114
const auto motionPath = filesystem::path(options->input_motion_file);
119115
const auto motionExt = motionPath.extension();
120-
if (motionExt == ".mmo") {
121-
MT_LOGI("Loading motion from mmo...");
122-
MT_THROW_IF(!hasModel, "mmo file requires an input character.");
123-
std::tie(poses, offsets) = loadMmo(motionPath.string(), character);
124-
125-
if (saveMarkers) {
126-
MT_LOGW("No marker data in .mmo file {}", motionPath.string());
127-
}
128-
} else if (motionExt == ".glb") {
116+
if (motionExt == ".glb") {
129117
MT_LOGI("Loading motion from glb...");
130118
if (hasModel) {
131119
std::tie(poses, offsets, fps) = loadMotionOnCharacter(motionPath, character);
@@ -138,10 +126,6 @@ int main(int argc, char** argv) {
138126
MT_LOGW("Ignoring input locators {}.", options->input_locator_file);
139127
}
140128
}
141-
142-
if (saveMarkers) {
143-
markerSequence = loadMarkerSequence(motionPath);
144-
}
145129
} else if (motionExt == ".fbx") {
146130
MT_LOGI("Loading motion from fbx...");
147131
int motionIndex = -1;
@@ -200,38 +184,29 @@ int main(int argc, char** argv) {
200184
fps = framerate;
201185
offsets = character.parameterTransform.zero().v;
202186
}
203-
204-
if (saveMarkers) {
205-
MT_LOGW("No marker data in .fbx file {}", motionPath.string());
206-
}
207187
} else {
208188
MT_LOGW(
209189
"Unknown motion file format: {}. Exporting without motion.",
210190
options->input_motion_file);
211191
}
212-
} else if (saveMarkers) {
213-
MT_LOGW("No motion file to read marker data from");
192+
}
193+
if (saveMarkers) {
194+
markerSequence = loadMarkers(options->input_motion_file)[0];
214195
}
215196

216197
// save output
217-
if (oextension == ".fbx") {
218-
MT_LOGI("Saving fbx file...");
219-
saveFbx(
220-
options->output_model_file, character, poses, offsets, fps, options->character_mesh_save);
221-
} else if (oextension == ".glb" || oextension == ".gltf") {
222-
MT_LOGI("Saving gltf/glb file...");
223-
if (hasMotion) {
224-
saveGltfCharacter(
225-
options->output_model_file,
226-
character,
227-
fps,
228-
{character.parameterTransform.name, poses},
229-
{character.skeleton.getJointNames(), offsets},
230-
markerSequence.frames);
231-
} else {
232-
saveGltfCharacter(options->output_model_file, character);
233-
}
234-
}
198+
MT_LOGI("Saving {}...", options->output_model_file);
199+
FileSaveOptions saveOptions;
200+
saveOptions.mesh = options->character_mesh_save;
201+
saveOptions.fbxNamespace = options->fbx_namespace;
202+
saveCharacter(
203+
options->output_model_file,
204+
character,
205+
poses,
206+
offsets,
207+
saveMarkers ? markerSequence.frames : std::vector<std::vector<Marker>>{},
208+
fps,
209+
saveOptions);
235210
if (!options->output_locator_local.empty()) {
236211
saveLocators(
237212
options->output_locator_local,

momentum/io/gltf/gltf_builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class GltfBuilder final {
8686
void addMarkerSequence(
8787
float fps,
8888
std::span<const std::vector<momentum::Marker>> markerSequence,
89-
MarkerMesh markerMesh = MarkerMesh::None,
89+
MarkerMesh markerMesh = MarkerMesh::UnitCube,
9090
const std::string& animName = "default");
9191

9292
// Save the file with the provided filename. If the fileFormat is 'GltfFileFormat::Extension',

0 commit comments

Comments
 (0)