From d99c9f1dba04389059127d4af2838c38a9971f19 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:13:18 +0000 Subject: [PATCH] fix: inline tessellation in io_gltf to avoid circular dep --- src/foundation/io_gltf.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/foundation/io_gltf.cpp b/src/foundation/io_gltf.cpp index f1d20c9..e9fa81c 100644 --- a/src/foundation/io_gltf.cpp +++ b/src/foundation/io_gltf.cpp @@ -296,13 +296,32 @@ bool write_brep_gltf(const std::string& filepath, const brep::BrepModel& model, const auto& surf = model.surface(surf_id); - // Tessellate using the surface evaluator + // Inline tessellation: sample surface uniformly, create quad mesh int res = std::max(4, tessellation_res); - auto eval = [&surf](double u, double v) -> core::Point3D { - return surf.evaluate(u, v); - }; + std::vector verts; + std::vector> tris; - auto [verts, tris] = curves::tessellate(eval, res, res); + auto [u_min, u_max] = surf.domain_u(); + auto [v_min, v_max] = surf.domain_v(); + + for (int j = 0; j <= res; ++j) { + double v = v_min + (v_max - v_min) * static_cast(j) / res; + for (int i = 0; i <= res; ++i) { + double u = u_min + (u_max - u_min) * static_cast(i) / res; + verts.push_back(surf.evaluate(u, v)); + } + } + + for (int j = 0; j < res; ++j) { + for (int i = 0; i < res; ++i) { + int a = j * (res + 1) + i; + int b = a + 1; + int c = a + (res + 1); + int d = c + 1; + tris.push_back({a, b, d}); + tris.push_back({a, d, c}); + } + } // Offset indices int base = static_cast(all_verts.size());