Files
craft-libs/crates/mesh-ops

craft-mesh-ops

Operations on triangle meshes, for apps that paint, bake or preview materials on 3D models. The crate has no UI, does no file or network I/O and has no unsafe code. File formats stay in craft-mesh.

  • Mesh. Positions, normals, tangents, UVs, vertex colors, indices, per-material submeshes and polygon-diagonal flags, with validate, append, subdivided, normalize_to, wireframe and UV-seam edges, and UV-tile helpers.
  • Normals and tangents. Smooth normals are area weighted. Tangents come from MikkTSpace, which glTF 2.0 recommends for meshes without tangents (https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html): w holds the bitangent sign.
  • UV unwrapping. unwrap::auto_unwrap makes a non-overlapping layout per material, splitting vertices where charts meet. It checks the mesh against its size limits and its attribute data first and returns an error without changing the mesh when a check fails. Charts are projected and packed in f64. Padding uses the requested resolution, with a minimum resolution of 16. A layout that cannot fit returns an error without changing the mesh. Missing normals use area-weighted f64 accumulation and normalization.
  • UV G-buffer. UvGBuffer records, for each texel of one material's UV space, the triangle and barycentrics under the texel center; surface_at turns them into a position, normal and tangent frame. UvGBuffer::new returns an error for a side of 0 or above MAX_SIDE (16,384), for more than MAX_TEXELS texels (8,192 × 8,192), when the triangles touch more than MAX_BAND_ENTRIES bands of 32 rows in all, and when the memory cannot be reserved.
  • Primitives. Sphere, rounded box, cube, cylinder, torus and plane with UVs and tangents, and the built-in scenes in primitives::BUILTINS. primitives::cube and primitives::rounded_box return Result<Mesh>. They reject non-finite or nonpositive dimensions and dimensions whose doubled half extents overflow. A box bevel must be finite and between zero and 95% of its smallest half extent; an invalid bevel returns GeomError::Invalid. Sphere and torus seam endpoints have identical positions and retain distinct UV endpoints. Cylinder caps share exact rim positions with the side, and rounded-box faces share exact boundary positions. Lathe profile lengths and direction normalization use f64 before the UVs and normals are stored as f32.
  • BVH. Bvh is a binned SAH tree on all three axes with a median split when no split beats a leaf. It answers closest-hit, any-hit and filtered ray casts, nearest-point queries and box queries.
  • Camera. OrbitCamera and Ray give an orbit view and picking rays.

GeomError::Invalid is the one error type. rayon parallelizes the UV G-buffer, and serde serializes OrbitCamera; both are always on.

Origin

Part Source
mesh.rs, bvh.rs, primitives.rs, gbuffer.rs, unwrap.rs, camera.rs and their tests TextureCraft crates/geom at 386630e
Mesh::subdivided and subdivision_shares_edge_midpoints MaterialCraft crates/geom/src/mesh.rs at 3133062

MikkTSpace comes from the mikktspace crate; its notice is in ATTRIBUTION.md.

Migration

App Status
TextureCraft texturecraft-geom is the source. The app switches to this crate in its own pull request.
MaterialCraft materialcraft-geom is the source of subdivided. The app switches in its own pull request.