Skip to content

Commit b3866ee

Browse files
jeongseok-metafacebook-github-bot
authored andcommitted
Consolidate FBX loading API (#264)
Summary: Pull Request resolved: #264 ## Context Now that (I believe) the FBX loaders in Momentum with OpenFBX and FBXSDK are identical for what we want to achieve (we have tests for this), it would be good to consolidate them into one. Eventually, in the upper stack of this Diff, we merge io_openfbx into io_fbx, where we use OpenFBX for loading and FBXSDK for saving. This way the users no longer need to know which one to use with different API. ## This Diff Update downstream to always use `io_fbx` for loading Reviewed By: juliencbmeta Differential Revision: D72579404 fbshipit-source-id: 34cbcdf5be8d4f4b3d19e2f7ab803e7a3a46d7d6
1 parent 8370ea5 commit b3866ee

File tree

9 files changed

+72
-28
lines changed

9 files changed

+72
-28
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ mt_library(
445445
io_gltf
446446
io_motion
447447
io_marker
448-
io_openfbx
449448
io_shape
450449
io_skeleton
451450
)
@@ -740,7 +739,7 @@ if(MOMENTUM_BUILD_EXAMPLES)
740739
NAME fbx_viewer
741740
SOURCES_VARS fbx_viewer_sources
742741
LINK_LIBRARIES
743-
io_openfbx
742+
io_fbx
744743
rerun
745744
CLI11::CLI11
746745
rerun_sdk

momentum/examples/convert_model/convert_model.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <momentum/io/fbx/fbx_io.h>
1515
#include <momentum/io/gltf/gltf_io.h>
1616
#include <momentum/io/motion/mmo_io.h>
17-
#include <momentum/io/openfbx/openfbx_io.h>
1817
#include <momentum/io/skeleton/locator_io.h>
1918
#include <momentum/io/skeleton/parameter_transform_io.h>
2019
#include <momentum/io/skeleton/parameters_io.h>
@@ -146,7 +145,7 @@ int main(int argc, char** argv) {
146145
} else if (motionExt == ".fbx") {
147146
MT_LOGI("Loading motion from fbx...");
148147
int motionIndex = -1;
149-
auto [c, motions, framerate] = loadOpenFbxCharacterWithMotion(motionPath, true, false);
148+
auto [c, motions, framerate] = loadFbxCharacterWithMotion(motionPath, true, false);
150149
// Validate the motion
151150
if (motions.empty() || (motions.size() == 1 && motions.at(0).cols() == 0)) {
152151
MT_LOGW("No motion loaded from file");

momentum/examples/fbx_viewer/fbx_viewer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <momentum/common/log.h>
1212
#include <momentum/gui/rerun/logger.h>
1313
#include <momentum/gui/rerun/logging_redirect.h>
14-
#include <momentum/io/openfbx/openfbx_io.h>
14+
#include <momentum/io/fbx/fbx_io.h>
1515

1616
#include <CLI/CLI.hpp>
1717
#include <rerun.hpp>
@@ -70,8 +70,8 @@ int main(int argc, char* argv[]) {
7070

7171
rec.log_static("world", ViewCoordinates::RUB); // Set an up-axis
7272

73-
const auto [character, motions, fps] = loadOpenFbxCharacterWithMotion(
74-
options->fbxFile, true /*keepLocators*/, options->permissive);
73+
const auto [character, motions, fps] =
74+
loadFbxCharacterWithMotion(options->fbxFile, true /*keepLocators*/, options->permissive);
7575
// Validate the loaded motion
7676
if (motions.empty() || (motions.size() == 1 && motions.at(0).cols() == 0)) {
7777
MT_LOGW("No motion loaded from file");

momentum/io/character_io.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include "momentum/io/character_io.h"
99

1010
#include "momentum/character/character.h"
11+
#include "momentum/io/fbx/fbx_io.h"
1112
#include "momentum/io/gltf/gltf_io.h"
12-
#include "momentum/io/openfbx/openfbx_io.h"
1313
#include "momentum/io/shape/pose_shape_io.h"
1414
#include "momentum/io/skeleton/locator_io.h"
1515
#include "momentum/io/skeleton/mppca_io.h"
@@ -50,7 +50,7 @@ namespace {
5050
if (format == CharacterFormat::Gltf) {
5151
return loadGltfCharacter(filepath);
5252
} else if (format == CharacterFormat::Fbx) {
53-
return loadOpenFbxCharacter(filepath, true);
53+
return loadFbxCharacter(filepath, true);
5454
} else {
5555
return {};
5656
}
@@ -62,7 +62,7 @@ namespace {
6262
if (format == CharacterFormat::Gltf) {
6363
return loadGltfCharacter(fileBuffer);
6464
} else if (format == CharacterFormat::Fbx) {
65-
return loadOpenFbxCharacter(fileBuffer, true);
65+
return loadFbxCharacter(fileBuffer, true);
6666
} else {
6767
return {};
6868
}

momentum/io/fbx/fbx_io.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,25 @@ void saveFbxCommon(
547547

548548
} // namespace
549549

550-
Character loadFbxCharacter(const filesystem::path& inputPath, bool permissive) {
551-
return loadOpenFbxCharacter(inputPath, false, permissive);
550+
Character loadFbxCharacter(const filesystem::path& inputPath, bool keepLocators, bool permissive) {
551+
return loadOpenFbxCharacter(inputPath, keepLocators, permissive);
552552
}
553553

554-
Character loadFbxCharacter(gsl::span<const std::byte> inputSpan, bool permissive) {
555-
return loadOpenFbxCharacter(inputSpan, false, permissive);
554+
Character
555+
loadFbxCharacter(gsl::span<const std::byte> inputSpan, bool keepLocators, bool permissive) {
556+
return loadOpenFbxCharacter(inputSpan, keepLocators, permissive);
557+
}
558+
559+
std::tuple<Character, std::vector<MatrixXf>, float>
560+
loadFbxCharacterWithMotion(const filesystem::path& inputPath, bool keepLocators, bool permissive) {
561+
return loadOpenFbxCharacterWithMotion(inputPath, keepLocators, permissive);
562+
}
563+
564+
std::tuple<Character, std::vector<MatrixXf>, float> loadFbxCharacterWithMotion(
565+
gsl::span<const std::byte> inputSpan,
566+
bool keepLocators,
567+
bool permissive) {
568+
return loadOpenFbxCharacterWithMotion(inputSpan, keepLocators, permissive);
556569
}
557570

558571
void saveFbx(

momentum/io/fbx/fbx_io.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,33 @@ struct FBXCoordSystemInfo {
3939
FBXCoordSystem coordSystem = FBXCoordSystem::RightHanded;
4040
};
4141

42+
// Using keepLocators means the Nulls in the transform hierarchy will be turned into Locators.
43+
// This is different from historical momentum behavior so it's off by default.
4244
// Permissive mode allows loading mesh-only characters (without skin weights).
43-
Character loadFbxCharacter(const filesystem::path& inputPath, bool permissive = false);
45+
Character loadFbxCharacter(
46+
const filesystem::path& inputPath,
47+
bool keepLocators = false,
48+
bool permissive = false);
4449

50+
// Using keepLocators means the Nulls in the transform hierarchy will be turned into Locators.
51+
// This is different from historical momentum behavior so it's off by default.
4552
// Permissive mode allows loading mesh-only characters (without skin weights).
46-
Character loadFbxCharacter(gsl::span<const std::byte> inputSpan, bool permissive = false);
53+
Character loadFbxCharacter(
54+
gsl::span<const std::byte> inputSpan,
55+
bool keepLocators = false,
56+
bool permissive = false);
57+
58+
// Permissive mode allows loading mesh-only characters (without skin weights).
59+
std::tuple<Character, std::vector<MatrixXf>, float> loadFbxCharacterWithMotion(
60+
const filesystem::path& inputPath,
61+
bool keepLocators = false,
62+
bool permissive = false);
63+
64+
// Permissive mode allows loading mesh-only characters (without skin weights).
65+
std::tuple<Character, std::vector<MatrixXf>, float> loadFbxCharacterWithMotion(
66+
gsl::span<const std::byte> inputSpan,
67+
bool keepLocators = false,
68+
bool permissive = false);
4769

4870
// Permissive mode allows saving mesh-only characters (without skin weights).
4971
void saveFbx(

momentum/io/fbx/fbx_io_unsupported.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,29 @@
99

1010
#include "momentum/character/character.h"
1111
#include "momentum/common/exception.h"
12+
#include "momentum/io/openfbx/openfbx_io.h"
1213

1314
namespace momentum {
1415

15-
Character loadFbxCharacter(const filesystem::path& inputPath, bool permissive) {
16-
MT_THROW("FbxSDK is not supported on your platform. Please use loadOpenFbxCharacter instead.");
17-
return Character();
16+
Character loadFbxCharacter(const filesystem::path& inputPath, bool keepLocators, bool permissive) {
17+
return loadOpenFbxCharacter(inputPath, keepLocators, permissive);
1818
}
1919

20-
Character loadFbxCharacter(gsl::span<const std::byte> inputSpan, bool permissive) {
21-
MT_THROW("FbxSDK is not supported on your platform. Please use loadOpenFbxCharacter instead.");
22-
return Character();
20+
Character
21+
loadFbxCharacter(gsl::span<const std::byte> inputSpan, bool keepLocators, bool permissive) {
22+
return loadOpenFbxCharacter(inputSpan, keepLocators, permissive);
23+
}
24+
25+
std::tuple<Character, std::vector<MatrixXf>, float>
26+
loadFbxCharacterWithMotion(const filesystem::path& inputPath, bool keepLocators, bool permissive) {
27+
return loadOpenFbxCharacterWithMotion(inputPath, keepLocators, permissive);
28+
}
29+
30+
std::tuple<Character, std::vector<MatrixXf>, float> loadFbxCharacterWithMotion(
31+
gsl::span<const std::byte> inputSpan,
32+
bool keepLocators,
33+
bool permissive) {
34+
return loadOpenFbxCharacterWithMotion(inputSpan, keepLocators, permissive);
2335
}
2436

2537
void saveFbx(

pymomentum/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ mt_python_binding(
155155
io_fbx
156156
io_gltf
157157
io_marker
158-
io_openfbx
159158
io_shape
160159
io_skeleton
161160
io_urdf

pymomentum/geometry/momentum_geometry.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include <momentum/character/skeleton_state.h>
2020
#include <momentum/character/skin_weights.h>
2121
#include <momentum/common/checks.h>
22+
#include <momentum/io/fbx/fbx_io.h>
2223
#include <momentum/io/gltf/gltf_io.h>
23-
#include <momentum/io/openfbx/openfbx_io.h>
2424
#include <momentum/io/shape/blend_shape_io.h>
2525
#include <momentum/io/skeleton/locator_io.h>
2626
#include <momentum/io/skeleton/mppca_io.h>
@@ -192,7 +192,7 @@ momentum::Character loadFBXCharacterFromFile(
192192
const std::optional<std::string>& configPath,
193193
const std::optional<std::string>& locatorsPath,
194194
bool permissive) {
195-
momentum::Character result = momentum::loadOpenFbxCharacter(
195+
momentum::Character result = momentum::loadFbxCharacter(
196196
filesystem::path(fbxPath), keepLocators, permissive);
197197
if (configPath && !configPath->empty()) {
198198
result = loadConfigFromFile(result, *configPath);
@@ -219,7 +219,7 @@ std::tuple<momentum::Character, std::vector<Eigen::MatrixXf>, float>
219219
loadFBXCharacterWithMotionFromFile(
220220
const std::string& fbxPath,
221221
bool permissive) {
222-
auto [character, motion, fps] = momentum::loadOpenFbxCharacterWithMotion(
222+
auto [character, motion, fps] = momentum::loadFbxCharacterWithMotion(
223223
filesystem::path(fbxPath), keepLocators, permissive);
224224
transposeMotionInPlace(motion);
225225
return {character, motion, fps};
@@ -229,7 +229,7 @@ std::tuple<momentum::Character, std::vector<Eigen::MatrixXf>, float>
229229
loadFBXCharacterWithMotionFromBytes(
230230
const py::bytes& fbxBytes,
231231
bool permissive) {
232-
auto [character, motion, fps] = momentum::loadOpenFbxCharacterWithMotion(
232+
auto [character, motion, fps] = momentum::loadFbxCharacterWithMotion(
233233
toSpan<std::byte>(fbxBytes), keepLocators, permissive);
234234
transposeMotionInPlace(motion);
235235
return {character, motion, fps};
@@ -276,7 +276,7 @@ momentum::Character loadConfigFromFile(
276276
momentum::Character loadFBXCharacterFromBytes(
277277
const pybind11::bytes& bytes,
278278
bool permissive) {
279-
return momentum::loadOpenFbxCharacter(
279+
return momentum::loadFbxCharacter(
280280
toSpan<std::byte>(bytes), keepLocators, permissive);
281281
}
282282

0 commit comments

Comments
 (0)