1#![warn(missing_docs)]
9
10pub mod math;
11
12mod mesh;
13pub use mesh::*;
14
15mod operations;
16pub use operations::*;
17
18use thiserror::Error;
19#[derive(Debug, Error)]
23#[allow(missing_docs)]
24pub enum Error {
25 #[error("configuration is not valid: {0}")]
26 ActionWillResultInInvalidMesh(String),
27 #[error("action will produce a non-manifold mesh: {0}")]
28 ActionWillResultInNonManifoldMesh(String),
29 #[error("the mesh has ended up in an invalid state: {0}")]
30 MeshIsInvalid(String),
31}
32
33#[cfg(test)]
34mod test_utility {
35 use super::*;
36 use three_d_asset::{Indices, Positions, TriMesh};
37 pub(crate) fn subdivided_triangle() -> Mesh {
41 TriMesh {
42 indices: Indices::U8(vec![0, 2, 3, 0, 3, 1, 0, 1, 2]),
43 positions: Positions::F64(vec![
44 vec3(0.0, 0.0, 0.0),
45 vec3(-3.0, -1.0, 0.0),
46 vec3(3.0, -1.0, 0.0),
47 vec3(0.0, 2.0, 0.0),
48 ]),
49 ..Default::default()
50 }
51 .into()
52 }
53
54 pub(crate) fn triangle() -> Mesh {
56 TriMesh {
57 indices: Indices::U8(vec![0, 1, 2]),
58 positions: Positions::F64(vec![
59 vec3(-3.0, -1.0, 0.0),
60 vec3(3.0, -1.0, 0.0),
61 vec3(0.0, 2.0, 0.0),
62 ]),
63 ..Default::default()
64 }
65 .into()
66 }
67
68 pub(crate) fn square() -> Mesh {
70 TriMesh {
71 indices: Indices::U8(vec![0, 1, 2, 2, 1, 3]),
72 positions: Positions::F64(vec![
73 vec3(-1.0, -1.0, 0.0),
74 vec3(1.0, -1.0, 0.0),
75 vec3(-1.0, 1.0, 0.0),
76 vec3(1.0, 1.0, 0.0),
77 ]),
78 ..Default::default()
79 }
80 .into()
81 }
82
83 pub(crate) fn triangle_strip() -> Mesh {
84 TriMesh {
85 indices: Indices::U8(vec![0, 1, 2, 2, 1, 3, 3, 1, 4, 3, 4, 5]),
86 positions: Positions::F64(vec![
87 vec3(0.0, 0.0, 0.0),
88 vec3(0.0, 0.0, 1.0),
89 vec3(1.0, 0.0, 0.5),
90 vec3(1.0, 0.0, 1.5),
91 vec3(0.0, 0.0, 2.0),
92 vec3(0.0, 0.0, 2.5),
93 ]),
94 ..Default::default()
95 }
96 .into()
97 }
98
99 pub(crate) fn cube() -> Mesh {
100 TriMesh {
101 indices: Indices::U8(vec![
102 0, 1, 2, 0, 2, 3, 4, 7, 6, 4, 6, 5, 0, 4, 5, 0, 5, 1, 1, 5, 6, 1, 6, 2, 2, 6, 7, 2,
103 7, 3, 4, 0, 3, 4, 3, 7,
104 ]),
105 positions: Positions::F64(vec![
106 vec3(1.0, -1.0, -1.0),
107 vec3(1.0, -1.0, 1.0),
108 vec3(-1.0, -1.0, 1.0),
109 vec3(-1.0, -1.0, -1.0),
110 vec3(1.0, 1.0, -1.0),
111 vec3(1.0, 1.0, 1.0),
112 vec3(-1.0, 1.0, 1.0),
113 vec3(-1.0, 1.0, -1.0),
114 ]),
115 ..Default::default()
116 }
117 .into()
118 }
119}