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/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; diff --git a/src/Raw2Gltf.cpp b/src/Raw2Gltf.cpp index 0b7094a..b7d2cbd 100644 --- a/src/Raw2Gltf.cpp +++ b/src/Raw2Gltf.cpp @@ -1190,11 +1190,13 @@ ModelData *Raw2Gltf( extensionsRequired.push_back(KHR_DRACO_MESH_COMPRESSION); } - json glTFJson{ - {"asset", {{"generator", "FBX2glTF"}, {"version", "2.0"}}}, - {"scene", rootScene.ix}}; - if (!extensionsUsed.empty()) - { + json glTFJson { + { "asset", { + { "generator", "FBX2glTF v" + FBX2GLTF_VERSION }, + { "version", "2.0" }}}, + { "scene", rootScene.ix } + }; + if (!extensionsUsed.empty()) { glTFJson["extensionsUsed"] = extensionsUsed; } if (!extensionsRequired.empty()) diff --git a/src/RawModel.cpp b/src/RawModel.cpp index 230b180..148776d 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; + } } } @@ -341,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); } diff --git a/src/main.cpp b/src/main.cpp index f090672..107c68a 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; }