Skip to content

Commit 127cdeb

Browse files
committed
Add a consolidated struct FileSaveOptions for both gltf and fbx options (#770)
Summary: Pull Request resolved: #770 This change adds a new struct to consolidate file saving options. It is not yet being used. Follow up diffs will start to update the code. Differential Revision: D86034154
1 parent 911df08 commit 127cdeb

File tree

9 files changed

+131
-54
lines changed

9 files changed

+131
-54
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,13 @@ else()
381381
set(io_fbx_private_link_libraries )
382382
endif()
383383

384+
# Header-only library for file save options
385+
mt_library(
386+
NAME io_file_save_options
387+
HEADERS_VARS
388+
io_file_save_options_public_headers
389+
)
390+
384391
mt_library(
385392
NAME io_fbx
386393
HEADERS_VARS
@@ -391,6 +398,7 @@ mt_library(
391398
${io_fbx_sources_var}
392399
PRIVATE_LINK_LIBRARIES
393400
io_common
401+
io_file_save_options
394402
io_skeleton
395403
${io_fbx_private_link_libraries}
396404
OpenFBX
@@ -406,6 +414,7 @@ mt_library(
406414
PUBLIC_LINK_LIBRARIES
407415
character
408416
io_common
417+
io_file_save_options
409418
io_skeleton
410419
fx-gltf::fx-gltf
411420
PRIVATE_LINK_LIBRARIES

cmake/build_variables.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ io_common_test_sources = [
377377
"test/io/common/stream_utils_test.cpp",
378378
]
379379

380+
io_file_save_options_public_headers = [
381+
"io/file_save_options.h",
382+
]
383+
380384
io_skeleton_public_headers = [
381385
"io/skeleton/locator_io.h",
382386
"io/skeleton/mppca_io.h",
@@ -441,7 +445,6 @@ io_fbx_test_sources = [
441445

442446
io_gltf_public_headers = [
443447
"io/gltf/gltf_builder.h",
444-
"io/gltf/gltf_file_format.h",
445448
"io/gltf/gltf_io.h",
446449
]
447450

momentum/io/character_io.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <momentum/character/fwd.h>
1111
#include <momentum/character/marker.h>
1212
#include <momentum/common/filesystem.h>
13+
#include <momentum/io/file_save_options.h>
1314
#include <momentum/math/fwd.h>
1415
#include <momentum/math/types.h>
1516

momentum/io/fbx/fbx_io.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <momentum/character/fwd.h>
1111
#include <momentum/character/marker.h>
1212
#include <momentum/common/filesystem.h>
13+
#include <momentum/io/file_save_options.h>
1314
#include <momentum/math/types.h>
1415

1516
#include <span>
@@ -18,36 +19,12 @@
1819

1920
namespace momentum {
2021

21-
// UpVector Specifies which canonical axis represents up in the system
22-
// (typically Y or Z). Maps to fbxsdk::FbxAxisSystem::EUpVector
23-
enum class FBXUpVector { XAxis = 1, YAxis = 2, ZAxis = 3 };
24-
25-
// FrontVector Vector with origin at the screen pointing toward the camera.
26-
// This is a subset of enum EUpVector because axis cannot be repeated.
27-
// We use the system of "parity" to define this vector because its value (X,Y or
28-
// Z axis) really depends on the up-vector. The EPreDefinedAxisSystem list the
29-
// up-vector, parity and coordinate system values for the predefined systems.
30-
// Maps to fbxsdk::FbxAxisSystem::EFrontVector
31-
enum class FBXFrontVector { ParityEven = 1, ParityOdd = 2 };
32-
33-
// CoordSystem Specifies the third vector of the system.
34-
// Maps to fbxsdk::FbxAxisSystem::ECoordSystem
35-
enum class FBXCoordSystem { RightHanded, LeftHanded };
36-
3722
// KeepLocators Specifies whether Nulls in the transform hierarchy should be turned into Locators.
3823
enum class KeepLocators { No, Yes };
3924

4025
// LoadBlendShapes Specifies whether blendshapes should be loaded or not
4126
enum class LoadBlendShapes { No, Yes };
4227

43-
// A struct containing the up, front vectors and coordinate system
44-
struct FBXCoordSystemInfo {
45-
// Default to the same orientations as FbxAxisSystem::eMayaYUp
46-
FBXUpVector upVector = FBXUpVector::YAxis;
47-
FBXFrontVector frontVector = FBXFrontVector::ParityOdd;
48-
FBXCoordSystem coordSystem = FBXCoordSystem::RightHanded;
49-
};
50-
5128
// Using keepLocators means the Nulls in the transform hierarchy will be turned into Locators.
5229
// This is different from historical momentum behavior so it's off by default.
5330
// Permissive mode allows loading mesh-only characters (without skin weights).

momentum/io/file_save_options.h

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
10+
#include <string_view>
11+
12+
namespace momentum {
13+
14+
// ============================================================================
15+
// GLTF File Format
16+
// ============================================================================
17+
18+
/// File format in which the character is saved
19+
enum class GltfFileFormat {
20+
Extension = 0, // The file extension is used for deduction (e.g. ".gltf" --> ASCII)
21+
GltfBinary = 1, // Binary format (generally .glb)
22+
GltfAscii = 2, // ASCII format (generally .gltf)
23+
};
24+
25+
/// Options for GLTF file export
26+
struct GltfOptions {
27+
/// Include GLTF extensions in the output.
28+
bool extensions = true;
29+
/// Include collision geometry in the output.
30+
bool collisions = true;
31+
/// Include locators in the output.
32+
bool locators = true;
33+
/// Include mesh geometry in the output.
34+
bool mesh = true;
35+
/// Include blend shapes in the output.
36+
bool blendShapes = true;
37+
};
38+
39+
// ============================================================================
40+
// FBX Coordinate System Options
41+
// =====================================================================
42+
43+
/// Specifies which canonical axis represents up in the system (typically Y or Z).
44+
/// Maps to fbxsdk::FbxAxisSystem::EUpVector
45+
enum class FBXUpVector { XAxis = 1, YAxis = 2, ZAxis = 3 };
46+
47+
/// Vector with origin at the screen pointing toward the camera.
48+
/// This is a subset of enum EUpVector because axis cannot be repeated.
49+
/// We use the system of "parity" to define this vector because its value (X,Y or
50+
/// Z axis) really depends on the up-vector.
51+
/// Maps to fbxsdk::FbxAxisSystem::EFrontVector
52+
enum class FBXFrontVector { ParityEven = 1, ParityOdd = 2 };
53+
54+
/// Specifies the third vector of the system.
55+
/// Maps to fbxsdk::FbxAxisSystem::ECoordSystem
56+
enum class FBXCoordSystem { RightHanded, LeftHanded };
57+
58+
/// A struct containing the up, front vectors and coordinate system for FBX export.
59+
struct FBXCoordSystemInfo {
60+
/// Default to the same orientations as FbxAxisSystem::eMayaYUp
61+
FBXUpVector upVector = FBXUpVector::YAxis;
62+
FBXFrontVector frontVector = FBXFrontVector::ParityOdd;
63+
FBXCoordSystem coordSystem = FBXCoordSystem::RightHanded;
64+
};
65+
66+
// ============================================================================
67+
// Unified File Save Options
68+
// ============================================================================
69+
70+
/// Unified options for saving files in both FBX and GLTF formats.
71+
///
72+
/// This struct consolidates save options that were previously scattered across
73+
/// multiple function parameters. Format-specific options (e.g., FBX coordinate
74+
/// system, GLTF extensions) are included but only used by their respective formats.
75+
struct FileSaveOptions {
76+
// ---- Common Options (used by both FBX and GLTF) ----
77+
78+
/// Include mesh geometry in the output (default: true)
79+
bool mesh = true;
80+
81+
/// Include locators in the output (default: true)
82+
bool locators = true;
83+
84+
/// Include collision geometry in the output (default: true)
85+
bool collisions = true;
86+
87+
/// Include blend shapes in the output (default: true)
88+
bool blendShapes = true;
89+
90+
/// Permissive mode: allow saving mesh-only characters without skin weights (default: false)
91+
bool permissive = false;
92+
93+
// ---- FBX-Specific Options ----
94+
95+
/// FBX coordinate system configuration (default: Maya Y-up)
96+
FBXCoordSystemInfo coordSystemInfo = {};
97+
98+
/// Optional namespace prefix for FBX node names (e.g., "ns" becomes "ns:")
99+
/// Only used for FBX output (default: empty = no namespace)
100+
std::string_view fbxNamespace = "";
101+
102+
// ---- GLTF-Specific Options ----
103+
104+
/// Enable GLTF extensions (default: true)
105+
/// Only used for GLTF output
106+
bool extensions = true;
107+
108+
/// GLTF file format selection (default: Extension)
109+
/// Only used for GLTF output
110+
GltfFileFormat gltfFileFormat = GltfFileFormat::Extension;
111+
};
112+
113+
} // namespace momentum

momentum/io/gltf/gltf_builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <momentum/character/marker.h>
1111
#include <momentum/character/skeleton.h>
1212
#include <momentum/common/filesystem.h>
13-
#include <momentum/io/gltf/gltf_file_format.h>
13+
#include <momentum/io/file_save_options.h>
1414
#include <momentum/io/gltf/gltf_io.h>
1515
#include <momentum/math/mesh.h>
1616
#include <momentum/math/types.h>

momentum/io/gltf/gltf_file_format.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

momentum/io/gltf/gltf_io.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <momentum/character/marker.h>
1111
#include <momentum/character/types.h>
1212
#include <momentum/common/filesystem.h>
13-
#include <momentum/io/gltf/gltf_file_format.h>
13+
#include <momentum/io/file_save_options.h>
1414
#include <momentum/math/types.h>
1515

1616
#include <fx/gltf.h>
@@ -21,14 +21,6 @@
2121

2222
namespace momentum {
2323

24-
struct GltfOptions {
25-
bool extensions = true;
26-
bool collisions = true;
27-
bool locators = true;
28-
bool mesh = true;
29-
bool blendShapes = true;
30-
};
31-
3224
Character loadGltfCharacter(const fx::gltf::Document& model);
3325

3426
Character loadGltfCharacter(const filesystem::path& gltfFilename);

pymomentum/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ mt_python_binding(
160160
character_test_helpers
161161
io
162162
io_fbx
163+
io_file_save_options
163164
io_gltf
164165
io_legacy_json
165166
io_marker

0 commit comments

Comments
 (0)