// Optional mesh adapter (design D1, ports & adapters). The NURBS core
// (tycho_nurbs) is math-only and outputs a neutral Double-precision Tessellation;
// this module is the ONLY place that knows about tycho_geometry::MeshData. It
// down-casts Double vectors to Float at the boundary, mirroring tycho_math's f64
// "high-precision construction, down-cast for GPU upload" pattern. Consumers that
// render via tycho_3d depend on this adapter; pure-CAD/analysis consumers depend
// only on the math-only core.
///|
/// Convert a neutral NURBS tessellation to a Float `MeshData` (positions/normals
/// down-cast DVec3 -> Vec3, uvs DVec2 -> Vec2; indices already UInt).
pub fn to_mesh_data(t : @nurbs.Tessellation) -> @tgeo.MeshData {
let n = t.positions.length()
let positions : FixedArray[@tmath.Vec3] = FixedArray::make(n, @tmath.Vec3::zero())
let normals : FixedArray[@tmath.Vec3] = FixedArray::make(n, @tmath.Vec3::zero())
let uvs : FixedArray[@tmath.Vec2] = FixedArray::make(n, @tmath.Vec2::zero())
for i = 0; i < n; i = i + 1 {
positions[i] = t.positions[i].to_vec3()
normals[i] = t.normals[i].to_vec3()
uvs[i] = t.uvs[i].to_vec2()
}
@tgeo.MeshData::new(positions, normals, uvs, t.indices)
}
///|
/// Tessellate a NURBS surface and convert straight to `MeshData`. None if the
/// tessellation fails (invalid segment counts or evaluation failure).
pub fn surface_to_mesh(
srf : @nurbs.NurbsSurface3,
segs_u : Int,
segs_v : Int,
) -> @tgeo.MeshData? {
match srf.tessellate(segs_u, segs_v) {
None => None
Some(t) => Some(to_mesh_data(t))
}
}