fix: inline tessellation in io_gltf to avoid circular dep
This commit is contained in:
@@ -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<core::Point3D> verts;
|
||||
std::vector<std::array<int, 3>> 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<double>(j) / res;
|
||||
for (int i = 0; i <= res; ++i) {
|
||||
double u = u_min + (u_max - u_min) * static_cast<double>(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<int>(all_verts.size());
|
||||
|
||||
Reference in New Issue
Block a user