mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 02:36:54 +01:00
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, withvalidate,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):
wholds the bitangent sign. - UV unwrapping.
unwrap::auto_unwrapmakes 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 inf64. 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-weightedf64accumulation and normalization. - UV G-buffer.
UvGBufferrecords, for each texel of one material's UV space, the triangle and barycentrics under the texel center;surface_atturns them into a position, normal and tangent frame.UvGBuffer::newreturns an error for a side of 0 or aboveMAX_SIDE(16,384), for more thanMAX_TEXELStexels (8,192 × 8,192), when the triangles touch more thanMAX_BAND_ENTRIESbands 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::cubeandprimitives::rounded_boxreturnResult<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 returnsGeomError::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 usef64before the UVs and normals are stored asf32. - BVH.
Bvhis 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.
OrbitCameraandRaygive 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. |