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());