From f530af8bf4f82c1816a406b4230c1852f4e87913 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Thu, 3 May 2018 08:21:37 -0700 Subject: [PATCH 1/4] Use std:: whenever possible. --- src/Fbx2Raw.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Fbx2Raw.cpp b/src/Fbx2Raw.cpp index 2b072d0..3f041e2 100644 --- a/src/Fbx2Raw.cpp +++ b/src/Fbx2Raw.cpp @@ -1263,7 +1263,7 @@ static void ReadAnimations(RawModel &raw, FbxScene *pScene) for (int targetIx = 0; targetIx < targetCount; targetIx++) { if (curve) { float result = findInInterval(influence, targetIx-1); - if (!isnan(result)) { + if (!std::isnan(result)) { // we're transitioning into targetIx channel.weights.push_back(result); hasMorphs = true; @@ -1271,7 +1271,7 @@ static void ReadAnimations(RawModel &raw, FbxScene *pScene) } if (targetIx != targetCount-1) { result = findInInterval(influence, targetIx); - if (!isnan(result)) { + if (!std::isnan(result)) { // we're transitioning AWAY from targetIx channel.weights.push_back(1.0f - result); hasMorphs = true; From 3c8cad47302baf00feadc3f1c9fba6a9c3aaacef Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Thu, 3 May 2018 14:44:43 -0700 Subject: [PATCH 2/4] Fix crash from dangling surface reference. The condense operation recreates the vectors of surfaces, materials, textures and vertices so as to exclude anything that isn't referenced explicitly by a triangle. In the process, we must take care that references from other properties are cleared out. This fixes the case when a node references a mesh by id, and then the mesh is deleted because no triangle references. TODO: go through other properties and make sure the same problem doesn't exist there. It is also possible that these vectors should be replaced by maps, at least for the elements that (now) have unique IDs. --- src/RawModel.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/RawModel.cpp b/src/RawModel.cpp index 230b180..1353743 100644 --- a/src/RawModel.cpp +++ b/src/RawModel.cpp @@ -269,11 +269,20 @@ void RawModel::Condense() surfaces.clear(); + std::set survivingSurfaceIds; for (auto &triangle : triangles) { + int oldSurfaceIndex = triangle.surfaceIndex; const RawSurface &surface = oldSurfaces[triangle.surfaceIndex]; const int surfaceIndex = AddSurface(surface.name.c_str(), surface.id); surfaces[surfaceIndex] = surface; triangle.surfaceIndex = surfaceIndex; + survivingSurfaceIds.emplace(surface.id); + } + // clear out references to meshes that no longer exist + for (auto &node : nodes) { + if (node.surfaceId != 0 && survivingSurfaceIds.find(node.surfaceId) == survivingSurfaceIds.end()) { + node.surfaceId = 0; + } } } From e178a75be3b9727effbb41995a1888969cb25bf0 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Thu, 3 May 2018 18:51:35 -0700 Subject: [PATCH 3/4] Start tracking and using FBX2glTF version. --- src/FBX2glTF.h | 2 ++ src/Raw2Gltf.cpp | 2 +- src/main.cpp | 9 +++------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/FBX2glTF.h b/src/FBX2glTF.h index 27278eb..ebdfe77 100644 --- a/src/FBX2glTF.h +++ b/src/FBX2glTF.h @@ -18,6 +18,8 @@ #include #endif +const std::string FBX2GLTF_VERSION = "0.9.5"; + #include #include diff --git a/src/Raw2Gltf.cpp b/src/Raw2Gltf.cpp index b27ec90..708ca1b 100644 --- a/src/Raw2Gltf.cpp +++ b/src/Raw2Gltf.cpp @@ -1077,7 +1077,7 @@ ModelData *Raw2Gltf( json glTFJson { { "asset", { - { "generator", "FBX2glTF" }, + { "generator", "FBX2glTF v" + FBX2GLTF_VERSION }, { "version", "2.0" }}}, { "scene", rootScene.ix } }; diff --git a/src/main.cpp b/src/main.cpp index 595b184..021d9b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,7 +34,8 @@ int main(int argc, char *argv[]) { cxxopts::Options options( "FBX2glTF", - "FBX2glTF 2.0: Generate a glTF 2.0 representation of an FBX model."); + fmt::sprintf("FBX2glTF %s: Generate a glTF 2.0 representation of an FBX model.", FBX2GLTF_VERSION) + ); std::string inputPath; std::string outputPath; @@ -98,11 +99,7 @@ int main(int argc, char *argv[]) } if (options.count("version")) { - fmt::printf( - R"( -FBX2glTF version 2.0 -Copyright (c) 2016-2017 Oculus VR, LLC. -)"); + fmt::printf("FBX2glTF version %s\nCopyright (c) 2016-2017 Oculus VR, LLC.\n", FBX2GLTF_VERSION); return 0; } From 5788eea8ade2ebe03c30a12ec3e03b927555e313 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Thu, 3 May 2018 18:58:58 -0700 Subject: [PATCH 4/4] Don't tell me you did nothing. --- src/RawModel.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/RawModel.cpp b/src/RawModel.cpp index 1353743..148776d 100644 --- a/src/RawModel.cpp +++ b/src/RawModel.cpp @@ -350,7 +350,9 @@ void RawModel::TransformGeometry(ComputeNormalsOption normals) if (verboseOutput) { if (normals == ComputeNormalsOption::BROKEN) { - fmt::printf("Repaired %lu empty normals.\n", computedNormalsCount); + if (computedNormalsCount > 0) { + fmt::printf("Repaired %lu empty normals.\n", computedNormalsCount); + } } else { fmt::printf("Computed %lu normals.\n", computedNormalsCount); }