From 0dbbb4ac4f761f74164159f99c1d08de7724ec08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=82=E4=B9=8B=E9=92=B3?= Date: Fri, 24 Jul 2026 09:10:01 +0000 Subject: [PATCH] fix: generate json in non-binary glTF path --- src/foundation/io_gltf.cpp | 23 ++++++++++++++++------- tests/foundation/test_io_gltf.cpp | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/foundation/io_gltf.cpp b/src/foundation/io_gltf.cpp index 1a04b4c..f1d20c9 100644 --- a/src/foundation/io_gltf.cpp +++ b/src/foundation/io_gltf.cpp @@ -248,18 +248,27 @@ bool write_gltf(const std::string& filepath, const mesh::HalfedgeMesh& mesh, return true; } else { // ── glTF JSON + separate .bin ── - std::ofstream file(filepath); - if (!file) return false; - file << json; - - // Write separate bin + // Determine bin filename from output path std::string dot = "."; size_t dot_pos = filepath.rfind(dot); std::string binpath; - if (dot_pos != std::string::npos) + std::string bin_basename; + if (dot_pos != std::string::npos) { binpath = filepath.substr(0, dot_pos) + ".bin"; - else + // Extract just the filename + size_t slash_pos = binpath.rfind('/'); + bin_basename = (slash_pos != std::string::npos) + ? binpath.substr(slash_pos + 1) : binpath; + } else { binpath = filepath + ".bin"; + bin_basename = binpath; + } + + std::string json = generate_json(mesh, options, layout, bin_basename); + + std::ofstream file(filepath); + if (!file) return false; + file << json; std::ofstream bin(binpath, std::ios::binary); if (!bin) return false; diff --git a/tests/foundation/test_io_gltf.cpp b/tests/foundation/test_io_gltf.cpp index 0a1c5fd..12ced63 100644 --- a/tests/foundation/test_io_gltf.cpp +++ b/tests/foundation/test_io_gltf.cpp @@ -3,6 +3,7 @@ #include #include "vde/foundation/io_gltf.h" #include "vde/brep/modeling.h" +#include "vde/brep/modeling.h" using namespace vde::foundation; using namespace vde::mesh;