truck_polymesh/
lib.rs

1//! Defines polyline-polygon data structure and some algorithms handling mesh.
2
3#![cfg_attr(not(debug_assertions), deny(warnings))]
4#![deny(clippy::all, rust_2018_idioms)]
5#![warn(
6    missing_docs,
7    missing_debug_implementations,
8    trivial_casts,
9    trivial_numeric_casts,
10    unsafe_code,
11    unstable_features,
12    unused_import_braces,
13    unused_qualifications
14)]
15
16use array_macro::array;
17use serde::{Deserialize, Serialize};
18
19/// re-export `truck_base`.
20pub mod base {
21    pub use truck_base::{
22        assert_near, bounding_box::BoundingBox, cgmath64::*, hash, hash::HashGen, tolerance::*,
23    };
24    pub use truck_geotrait::*;
25}
26pub use base::*;
27
28/// attribution container for polygin mesh
29pub trait Attributes<V> {
30    /// attribution
31    type Output;
32    /// get attribution corresponding to vertex
33    fn get(&self, vertex: V) -> Option<Self::Output>;
34}
35
36/// standard attributions
37#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
38pub struct StandardAttributes {
39    /// positions
40    pub positions: Vec<Point3>,
41    /// texture uv coordinates
42    pub uv_coords: Vec<Vector2>,
43    /// normals at vertices
44    pub normals: Vec<Vector3>,
45}
46
47/// standard attribution
48#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
49pub struct StandardAttribute {
50    /// position
51    pub position: Point3,
52    /// texture uv coordinate
53    pub uv_coord: Option<Vector2>,
54    /// normal at vertex
55    pub normal: Option<Vector3>,
56}
57
58/// Index vertex of a face of the polygon mesh
59#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug, Serialize, Deserialize)]
60pub struct StandardVertex {
61    /// index of vertex's position
62    pub pos: usize,
63    /// index of vertex's texture coordinate
64    pub uv: Option<usize>,
65    /// index of vertex's normal
66    pub nor: Option<usize>,
67}
68
69/// Faces of polygon mesh
70///
71/// To optimize for the case where the polygon mesh consists only triangles and quadrangle,
72/// there are vectors which consist by each triangles and quadrilaterals, internally.
73#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
74pub struct Faces<V = StandardVertex> {
75    tri_faces: Vec<[V; 3]>,
76    quad_faces: Vec<[V; 4]>,
77    other_faces: Vec<Vec<V>>,
78}
79
80/// Polygon mesh
81///
82/// The polygon data is held in a method compliant with wavefront obj.
83/// Position, uv (texture) coordinates, and normal vectors are held in separate arrays,
84/// and each face vertex accesses those values by an indices triple.
85#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
86pub struct PolygonMesh<V = StandardVertex, A = StandardAttributes> {
87    attributes: A,
88    faces: Faces<V>,
89}
90
91/// structured quadrangle mesh
92#[derive(Clone, Debug, Serialize)]
93pub struct StructuredMesh {
94    positions: Vec<Vec<Point3>>,
95    uv_division: Option<(Vec<f64>, Vec<f64>)>,
96    normals: Option<Vec<Vec<Vector3>>>,
97}
98
99/// polyline curve
100#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
101pub struct PolylineCurve<P>(pub Vec<P>);
102
103mod attributes;
104/// Defines errors
105pub mod errors;
106mod expand;
107/// Defines triangle
108pub mod faces;
109mod meshing_shape;
110/// wavefront obj I/O
111pub mod obj;
112/// Defines [`PolygonMeshEditor`](./polygon_mesh/struct.PolygonMeshEditor.html).
113pub mod polygon_mesh;
114/// Defines generalized polyline curve.
115pub mod polyline_curve;
116/// STL I/O
117pub mod stl;
118mod structured_mesh;