Skip to content

Commit 81eb888

Browse files
yutingyemeta-codesync[bot]
authored andcommitted
Merge fbx_io.cpp and fbx_io_openfbx_only.cpp using preprocessor directives (#781)
Summary: Pull Request resolved: #781 Reviewed By: cstollmeta Differential Revision: D86063345 fbshipit-source-id: f57fc437e0a83c5ff182aa900d5061b94d4bc97c
1 parent 377b07f commit 81eb888

File tree

6 files changed

+100
-130
lines changed

6 files changed

+100
-130
lines changed

CMakeLists.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@ include(GNUInstallDirs)
5959
#===============================================================================
6060

6161
mt_option(BUILD_SHARED_LIBS "Build as shared libraries" ON)
62-
mt_option(MOMENTUM_ENABLE_FBX_SAVING "Enable FBX saving via Autodesk FBX SDK (FBX loading always available via OpenFBX)" OFF)
62+
63+
# MOMENTUM_BUILD_WITH_FBXSDK environment variable controls whether FBX SDK is available
64+
# If not set or OFF, MOMENTUM_ENABLE_FBX_SAVING is forced to OFF
65+
# This ensures the open source build only uses FBX SDK when explicitly available
66+
if(DEFINED ENV{MOMENTUM_BUILD_WITH_FBXSDK} AND "$ENV{MOMENTUM_BUILD_WITH_FBXSDK}")
67+
# FBX SDK is available, allow enabling FBX saving
68+
mt_option(MOMENTUM_ENABLE_FBX_SAVING "Enable FBX saving via Autodesk FBX SDK (FBX loading always available via OpenFBX)" $ENV{MOMENTUM_BUILD_WITH_FBXSDK})
69+
else()
70+
# FBX SDK is not available, force FBX saving to OFF
71+
set(MOMENTUM_ENABLE_FBX_SAVING OFF CACHE BOOL "Enable FBX saving via Autodesk FBX SDK (FBX loading always available via OpenFBX)" FORCE)
72+
if(DEFINED MOMENTUM_ENABLE_FBX_SAVING_OVERRIDE AND MOMENTUM_ENABLE_FBX_SAVING_OVERRIDE)
73+
message(WARNING "MOMENTUM_ENABLE_FBX_SAVING was requested but MOMENTUM_BUILD_WITH_FBXSDK environment variable is not set. FBX SDK support requires MOMENTUM_BUILD_WITH_FBXSDK=ON. Forcing MOMENTUM_ENABLE_FBX_SAVING to OFF.")
74+
endif()
75+
endif()
6376
mt_option(MOMENTUM_BUILD_PYMOMENTUM "Build Python binding" OFF)
6477
mt_option(MOMENTUM_BUILD_TESTING "Enable building tests" OFF)
6578
mt_option(MOMENTUM_BUILD_EXAMPLES "Enable building examples" OFF)
@@ -359,7 +372,6 @@ mt_library(
359372
)
360373

361374
if(MOMENTUM_ENABLE_FBX_SAVING)
362-
set(io_fbx_sources_var io_fbx_sources)
363375
find_package(FbxSdk MODULE REQUIRED)
364376

365377
# Fix FBX SDK header typos for Clang 19 compatibility
@@ -377,7 +389,6 @@ if(MOMENTUM_ENABLE_FBX_SAVING)
377389
set(io_fbx_private_link_libraries fbxsdk::fbxsdk)
378390
else()
379391
# When FBX SDK is not available, use OpenFBX-only mode (OpenFBX is always available)
380-
set(io_fbx_sources_var io_fbx_sources_openfbx_only)
381392
set(io_fbx_private_link_libraries )
382393
endif()
383394

@@ -388,14 +399,18 @@ mt_library(
388399
PRIVATE_HEADERS_VARS
389400
io_fbx_private_headers
390401
SOURCES_VARS
391-
${io_fbx_sources_var}
402+
io_fbx_sources
392403
PRIVATE_LINK_LIBRARIES
393404
io_common
394405
io_skeleton
395406
${io_fbx_private_link_libraries}
396407
OpenFBX
397408
)
398409

410+
if(MOMENTUM_ENABLE_FBX_SAVING)
411+
target_compile_definitions(io_fbx PRIVATE MOMENTUM_WITH_FBX_SDK)
412+
endif()
413+
399414
mt_library(
400415
NAME io_gltf
401416
HEADERS_VARS

cmake/build_variables.bzl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,6 @@ io_fbx_sources = [
433433
"io/fbx/polygon_data.cpp",
434434
]
435435

436-
io_fbx_sources_openfbx_only = [
437-
"io/fbx/fbx_io_openfbx_only.cpp",
438-
"io/fbx/openfbx_loader.cpp",
439-
"io/fbx/polygon_data.cpp",
440-
]
441-
442436
io_fbx_test_sources = [
443437
"test/io/io_fbx_test.cpp",
444438
]

momentum/io/fbx/fbx_io.cpp

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
#include "momentum/io/fbx/fbx_io.h"
99

1010
#include "momentum/character/character.h"
11+
#include "momentum/common/exception.h"
12+
#include "momentum/io/fbx/openfbx_loader.h"
13+
14+
#ifdef MOMENTUM_WITH_FBX_SDK
1115
#include "momentum/character/character_state.h"
1216
#include "momentum/character/collision_geometry_state.h"
1317
#include "momentum/character/marker.h"
1418
#include "momentum/character/skin_weights.h"
15-
#include "momentum/common/exception.h"
1619
#include "momentum/common/filesystem.h"
1720
#include "momentum/common/log.h"
1821
#include "momentum/io/fbx/fbx_memory_stream.h"
19-
#include "momentum/io/fbx/openfbx_loader.h"
2022
#include "momentum/io/skeleton/locator_io.h"
2123
#include "momentum/io/skeleton/parameter_limits_io.h"
2224
#include "momentum/io/skeleton/parameter_transform_io.h"
@@ -37,9 +39,12 @@
3739
#endif
3840

3941
#include <variant>
42+
#endif // MOMENTUM_WITH_FBX_SDK
4043

4144
namespace momentum {
4245

46+
#ifdef MOMENTUM_WITH_FBX_SDK
47+
4348
namespace {
4449

4550
[[nodiscard]] ::fbxsdk::FbxAxisSystem::EUpVector toFbx(const FBXUpVector upVector) {
@@ -736,6 +741,8 @@ void saveFbxCommon(
736741

737742
} // namespace
738743

744+
#endif // MOMENTUM_WITH_FBX_SDK
745+
739746
Character loadFbxCharacter(
740747
const filesystem::path& inputPath,
741748
KeepLocators keepLocators,
@@ -776,6 +783,12 @@ std::tuple<Character, std::vector<MatrixXf>, float> loadFbxCharacterWithMotion(
776783
inputSpan, keepLocators, permissive, loadBlendShapes, stripNamespaces);
777784
}
778785

786+
MarkerSequence loadFbxMarkerSequence(const filesystem::path& filename, bool stripNamespaces) {
787+
return loadOpenFbxMarkerSequence(filename, stripNamespaces);
788+
}
789+
790+
#ifdef MOMENTUM_WITH_FBX_SDK
791+
779792
void saveFbx(
780793
const filesystem::path& filename,
781794
const Character& character,
@@ -784,7 +797,7 @@ void saveFbx(
784797
const double framerate,
785798
const bool saveMesh,
786799
const FBXCoordSystemInfo& coordSystemInfo,
787-
bool permissive,
800+
const bool permissive,
788801
const std::vector<std::vector<Marker>>& markerSequence,
789802
std::string_view fbxNamespace) {
790803
CharacterParameters params;
@@ -838,7 +851,7 @@ void saveFbxWithJointParams(
838851
const double framerate,
839852
const bool saveMesh,
840853
const FBXCoordSystemInfo& coordSystemInfo,
841-
bool permissive,
854+
const bool permissive,
842855
const std::vector<std::vector<Marker>>& markerSequence,
843856
std::string_view fbxNamespace) {
844857
// Call the helper function to save FBX file with joint values.
@@ -864,7 +877,7 @@ void saveFbxWithSkeletonStates(
864877
const double framerate,
865878
const bool saveMesh,
866879
const FBXCoordSystemInfo& coordSystemInfo,
867-
bool permissive,
880+
const bool permissive,
868881
const std::vector<std::vector<Marker>>& markerSequence,
869882
std::string_view fbxNamespace) {
870883
const size_t nFrames = skeletonStates.size();
@@ -909,8 +922,61 @@ void saveFbxModel(
909922
fbxNamespace);
910923
}
911924

912-
MarkerSequence loadFbxMarkerSequence(const filesystem::path& filename, bool stripNamespaces) {
913-
return loadOpenFbxMarkerSequence(filename, stripNamespaces);
925+
#else // !MOMENTUM_WITH_FBX_SDK
926+
927+
void saveFbx(
928+
const filesystem::path& /* filename */,
929+
const Character& /* character */,
930+
const MatrixXf& /* poses */,
931+
const VectorXf& /* identity */,
932+
const double /* framerate */,
933+
const bool /* saveMesh */,
934+
const FBXCoordSystemInfo& /* coordSystemInfo */,
935+
const bool /* permissive */,
936+
const std::vector<std::vector<Marker>>& /* markerSequence */,
937+
std::string_view /* fbxNamespace */) {
938+
MT_THROW(
939+
"FBX saving is not supported in OpenFBX-only mode. FBX loading is available via OpenFBX, but saving requires the full Autodesk FBX SDK.");
940+
}
941+
942+
void saveFbxWithJointParams(
943+
const filesystem::path& /* filename */,
944+
const Character& /* character */,
945+
const MatrixXf& /* jointParams */,
946+
const double /* framerate */,
947+
const bool /* saveMesh */,
948+
const FBXCoordSystemInfo& /* coordSystemInfo */,
949+
const bool /* permissive */,
950+
const std::vector<std::vector<Marker>>& /* markerSequence */,
951+
std::string_view /* fbxNamespace */) {
952+
MT_THROW(
953+
"FBX saving is not supported in OpenFBX-only mode. FBX loading is available via OpenFBX, but saving requires the full Autodesk FBX SDK.");
914954
}
915955

956+
void saveFbxWithSkeletonStates(
957+
const filesystem::path& /* filename */,
958+
const Character& /* character */,
959+
std::span<const SkeletonState> /* skeletonStates */,
960+
const double /* framerate */,
961+
const bool /* saveMesh */,
962+
const FBXCoordSystemInfo& /* coordSystemInfo */,
963+
const bool /* permissive */,
964+
const std::vector<std::vector<Marker>>& /* markerSequence */,
965+
std::string_view /* fbxNamespace */) {
966+
MT_THROW(
967+
"FBX saving is not supported in OpenFBX-only mode. FBX loading is available via OpenFBX, but saving requires the full Autodesk FBX SDK.");
968+
}
969+
970+
void saveFbxModel(
971+
const filesystem::path& /* filename */,
972+
const Character& /* character */,
973+
const FBXCoordSystemInfo& /* coordSystemInfo */,
974+
bool /* permissive */,
975+
std::string_view /* fbxNamespace */) {
976+
MT_THROW(
977+
"FBX saving is not supported in OpenFBX-only mode. FBX loading is available via OpenFBX, but saving requires the full Autodesk FBX SDK.");
978+
}
979+
980+
#endif // MOMENTUM_WITH_FBX_SDK
981+
916982
} // namespace momentum

momentum/io/fbx/fbx_io_openfbx_only.cpp

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

momentum/io/fbx/fbx_memory_stream.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#ifdef MOMENTUM_WITH_FBX_SDK
9+
810
#include "momentum/io/fbx/fbx_memory_stream.h"
911

1012
namespace momentum {
@@ -113,3 +115,5 @@ void FbxMemoryStream::ClearError() {
113115
}
114116

115117
} // namespace momentum
118+
119+
#endif // MOMENTUM_WITH_FBX_SDK

momentum/io/fbx/fbx_memory_stream.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#ifdef MOMENTUM_WITH_FBX_SDK
11+
1012
#include <fbxsdk.h>
1113
#include <fbxsdk/core/fbxstream.h>
1214
#include <span>
@@ -64,3 +66,5 @@ class FbxMemoryStream : public FbxStream {
6466
};
6567

6668
} // namespace momentum
69+
70+
#endif // MOMENTUM_WITH_FBX_SDK

0 commit comments

Comments
 (0)