fix: auto add rootnode and cut animation curve promblem
This commit is contained in:
parent
739ee5db94
commit
a1125165b0
|
@ -45,11 +45,11 @@ find_package(Threads REQUIRED)
|
||||||
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_BINARY_DIR}")
|
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_BINARY_DIR}")
|
||||||
|
|
||||||
# stuff we get from Conan
|
# stuff we get from Conan
|
||||||
find_package(boost_filesystem MODULE REQUIRED)
|
find_package(Boost REQUIRED COMPONENTS filesystem)
|
||||||
find_package(boost_optional MODULE REQUIRED)
|
find_package(LibXml2 MODULE REQUIRED)
|
||||||
find_package(libxml2 MODULE REQUIRED)
|
find_package(ZLIB MODULE REQUIRED)
|
||||||
find_package(zlib MODULE REQUIRED)
|
|
||||||
find_package(fmt MODULE REQUIRED)
|
find_package(fmt MODULE REQUIRED)
|
||||||
|
find_package(libiconv MODULE REQUIRED)
|
||||||
|
|
||||||
# create a compilation database for e.g. clang-tidy
|
# create a compilation database for e.g. clang-tidy
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
@ -201,25 +201,21 @@ endif()
|
||||||
|
|
||||||
target_link_libraries(libFBX2glTF
|
target_link_libraries(libFBX2glTF
|
||||||
${FRAMEWORKS}
|
${FRAMEWORKS}
|
||||||
boost_filesystem::boost_filesystem
|
Boost::filesystem
|
||||||
boost_optional::boost_optional
|
|
||||||
${DRACO_LIB}
|
${DRACO_LIB}
|
||||||
optimized ${FBXSDK_LIBRARY}
|
optimized ${FBXSDK_LIBRARY}
|
||||||
debug ${FBXSDK_LIBRARY_DEBUG}
|
debug ${FBXSDK_LIBRARY_DEBUG}
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
libxml2::libxml2
|
${LIBXML2_LIBRARIES}
|
||||||
zlib::zlib
|
${ZLIB_LIBRARIES}
|
||||||
|
${ICONV_LIBRARIES}
|
||||||
${CMAKE_DL_LIBS}
|
${CMAKE_DL_LIBS}
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (APPLE)
|
#find_package(libiconv MODULE REQUIRED)
|
||||||
find_package(Iconv MODULE REQUIRED)
|
#target_link_libraries(libFBX2glTF libiconv)
|
||||||
target_link_libraries(libFBX2glTF Iconv)
|
|
||||||
else()
|
|
||||||
find_package(libiconv MODULE REQUIRED)
|
|
||||||
target_link_libraries(libFBX2glTF libiconv::libiconv)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_include_directories(libFBX2glTF PUBLIC
|
target_include_directories(libFBX2glTF PUBLIC
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
|
@ -244,3 +240,4 @@ install (TARGETS libFBX2glTF appFBX2glTF
|
||||||
RUNTIME DESTINATION bin
|
RUNTIME DESTINATION bin
|
||||||
ARCHIVE DESTINATION lib
|
ARCHIVE DESTINATION lib
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
15
conanfile.py
15
conanfile.py
|
@ -9,17 +9,17 @@ from conans import ConanFile, CMake
|
||||||
class FBX2glTFConan(ConanFile):
|
class FBX2glTFConan(ConanFile):
|
||||||
settings = "os", "compiler", "build_type", "arch"
|
settings = "os", "compiler", "build_type", "arch"
|
||||||
requires = (
|
requires = (
|
||||||
("boost_filesystem/1.69.0@bincrafters/stable"),
|
("boost/1.81.0"),
|
||||||
("libiconv/1.15@bincrafters/stable"),
|
("libiconv/1.15"),
|
||||||
("zlib/1.2.11@conan/stable"),
|
("zlib/1.2.13"),
|
||||||
("libxml2/2.9.9@bincrafters/stable"),
|
("libxml2/2.9.9"),
|
||||||
("fmt/5.3.0@bincrafters/stable"),
|
("fmt/5.3.0"),
|
||||||
)
|
)
|
||||||
generators = "cmake_find_package", "cmake_paths"
|
generators = "cmake_find_package", "cmake_paths"
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
if (
|
if (
|
||||||
self.settings.compiler == "gcc"
|
self.settings.get_safe("compiler") == "gcc"
|
||||||
and self.settings.compiler.libcxx == "libstdc++"
|
and self.settings.compiler.libcxx == "libstdc++"
|
||||||
):
|
):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
|
@ -31,3 +31,4 @@ class FBX2glTFConan(ConanFile):
|
||||||
cmake.definitions["FBXSDK_SDKS"] = os.getenv("FBXSDK_SDKS", "sdk")
|
cmake.definitions["FBXSDK_SDKS"] = os.getenv("FBXSDK_SDKS", "sdk")
|
||||||
cmake.configure()
|
cmake.configure()
|
||||||
cmake.build()
|
cmake.build()
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "utils/String_Utils.hpp"
|
#include "utils/String_Utils.hpp"
|
||||||
|
|
||||||
bool verboseOutput = false;
|
bool verboseOutput = false;
|
||||||
|
bool optAnimation = false;
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
GltfOptions gltfOptions;
|
GltfOptions gltfOptions;
|
||||||
|
@ -34,6 +35,7 @@ int main(int argc, char* argv[]) {
|
||||||
"-v,--verbose",
|
"-v,--verbose",
|
||||||
verboseOutput,
|
verboseOutput,
|
||||||
"Include blend shape tangents, if reported present by the FBX SDK.");
|
"Include blend shape tangents, if reported present by the FBX SDK.");
|
||||||
|
app.add_flag("--optAni", optAnimation, "Delete the curve that hasn't changed");
|
||||||
|
|
||||||
app.add_flag_function("-V,--version", [&](size_t count) {
|
app.add_flag_function("-V,--version", [&](size_t count) {
|
||||||
fmt::printf("FBX2glTF version %s\nCopyright (c) 2016-2018 Oculus VR, LLC.\n", FBX2GLTF_VERSION);
|
fmt::printf("FBX2glTF version %s\nCopyright (c) 2016-2018 Oculus VR, LLC.\n", FBX2GLTF_VERSION);
|
||||||
|
@ -47,6 +49,7 @@ int main(int argc, char* argv[]) {
|
||||||
std::string outputPath;
|
std::string outputPath;
|
||||||
app.add_option("-o,--output", outputPath, "Where to generate the output, without suffix.");
|
app.add_option("-o,--output", outputPath, "Where to generate the output, without suffix.");
|
||||||
|
|
||||||
|
|
||||||
app.add_flag(
|
app.add_flag(
|
||||||
"-e,--embed",
|
"-e,--embed",
|
||||||
gltfOptions.embedResources,
|
gltfOptions.embedResources,
|
||||||
|
|
|
@ -41,6 +41,8 @@ using workaround_fifo_map = nlohmann::fifo_map<K, V, nlohmann::fifo_map_compare<
|
||||||
using json = nlohmann::basic_json<workaround_fifo_map>;
|
using json = nlohmann::basic_json<workaround_fifo_map>;
|
||||||
|
|
||||||
extern bool verboseOutput;
|
extern bool verboseOutput;
|
||||||
|
extern bool optAnimation;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Centralises all the laborious downcasting from your OS' 64-bit
|
* Centralises all the laborious downcasting from your OS' 64-bit
|
||||||
|
|
|
@ -753,7 +753,7 @@ static void ReadAnimations(RawModel& raw, FbxScene* pScene, const GltfOptions& o
|
||||||
eMode = FbxTime::eFrames60;
|
eMode = FbxTime::eFrames60;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const double epsilon = 1e-5f;
|
const double epsilon = 1e-5f;
|
||||||
|
|
||||||
const int animationCount = pScene->GetSrcObjectCount<FbxAnimStack>();
|
const int animationCount = pScene->GetSrcObjectCount<FbxAnimStack>();
|
||||||
for (size_t animIx = 0; animIx < animationCount; animIx++) {
|
for (size_t animIx = 0; animIx < animationCount; animIx++) {
|
||||||
|
@ -847,20 +847,26 @@ static void ReadAnimations(RawModel& raw, FbxScene* pScene, const GltfOptions& o
|
||||||
const FbxQuaternion localRotation = localTransform.GetQ();
|
const FbxQuaternion localRotation = localTransform.GetQ();
|
||||||
const FbxVector4 localScale = computeLocalScale(pNode, pTime);
|
const FbxVector4 localScale = computeLocalScale(pNode, pTime);
|
||||||
|
|
||||||
hasTranslation |=
|
|
||||||
(fabs(localTranslation[0] - baseTranslation[0]) > epsilon ||
|
|
||||||
fabs(localTranslation[1] - baseTranslation[1]) > epsilon ||
|
|
||||||
fabs(localTranslation[2] - baseTranslation[2]) > epsilon);
|
|
||||||
hasRotation |=
|
|
||||||
(fabs(localRotation[0] - baseRotation[0]) > epsilon ||
|
|
||||||
fabs(localRotation[1] - baseRotation[1]) > epsilon ||
|
|
||||||
fabs(localRotation[2] - baseRotation[2]) > epsilon ||
|
|
||||||
fabs(localRotation[3] - baseRotation[3]) > epsilon);
|
|
||||||
hasScale |=
|
|
||||||
(fabs(localScale[0] - baseScaling[0]) > epsilon ||
|
|
||||||
fabs(localScale[1] - baseScaling[1]) > epsilon ||
|
|
||||||
fabs(localScale[2] - baseScaling[2]) > epsilon);
|
|
||||||
|
|
||||||
|
if (!optAnimation) {
|
||||||
|
hasTranslation = true;
|
||||||
|
hasRotation = true;
|
||||||
|
hasScale = true;
|
||||||
|
} else {
|
||||||
|
hasTranslation |=
|
||||||
|
(fabs(localTranslation[0] - baseTranslation[0]) > epsilon ||
|
||||||
|
fabs(localTranslation[1] - baseTranslation[1]) > epsilon ||
|
||||||
|
fabs(localTranslation[2] - baseTranslation[2]) > epsilon);
|
||||||
|
hasRotation |=
|
||||||
|
(fabs(localRotation[0] - baseRotation[0]) > epsilon ||
|
||||||
|
fabs(localRotation[1] - baseRotation[1]) > epsilon ||
|
||||||
|
fabs(localRotation[2] - baseRotation[2]) > epsilon ||
|
||||||
|
fabs(localRotation[3] - baseRotation[3]) > epsilon);
|
||||||
|
hasScale |=
|
||||||
|
(fabs(localScale[0] - baseScaling[0]) > epsilon ||
|
||||||
|
fabs(localScale[1] - baseScaling[1]) > epsilon ||
|
||||||
|
fabs(localScale[2] - baseScaling[2]) > epsilon);
|
||||||
|
}
|
||||||
channel.translations.push_back(toVec3f(localTranslation) * scaleFactor);
|
channel.translations.push_back(toVec3f(localTranslation) * scaleFactor);
|
||||||
channel.rotations.push_back(toQuatf(localRotation));
|
channel.rotations.push_back(toQuatf(localRotation));
|
||||||
channel.scales.push_back(toVec3f(localScale));
|
channel.scales.push_back(toVec3f(localScale));
|
||||||
|
@ -1148,9 +1154,11 @@ bool LoadFBXFile(
|
||||||
}
|
}
|
||||||
// this is always 0.01, but let's opt for clarity.
|
// this is always 0.01, but let's opt for clarity.
|
||||||
scaleFactor = FbxSystemUnit::m.GetConversionFactorFrom(FbxSystemUnit::cm);
|
scaleFactor = FbxSystemUnit::m.GetConversionFactorFrom(FbxSystemUnit::cm);
|
||||||
|
FbxNode* rootNode = pScene->GetRootNode();
|
||||||
ReadNodeHierarchy(raw, pScene, pScene->GetRootNode(), 0, "");
|
ReadNodeHierarchy(raw, pScene, rootNode->GetChild(0), 0, "");
|
||||||
ReadNodeAttributes(raw, pScene, pScene->GetRootNode(), textureLocations);
|
ReadNodeAttributes(raw, pScene, rootNode->GetChild(0), textureLocations);
|
||||||
|
// ReadNodeHierarchy(raw, pScene, pScene->GetRootNode(), 0, "");
|
||||||
|
// ReadNodeAttributes(raw, pScene, pScene->GetRootNode(), textureLocations);
|
||||||
ReadAnimations(raw, pScene, options);
|
ReadAnimations(raw, pScene, options);
|
||||||
|
|
||||||
pScene->Destroy();
|
pScene->Destroy();
|
||||||
|
|
Loading…
Reference in New Issue