easygpu_lyon/builder/
lyon_builders.rs

1use lyon_tessellation::{
2    FillGeometryBuilder, FillVertex, FillVertexConstructor, GeometryBuilder, GeometryBuilderError,
3    StrokeGeometryBuilder, StrokeVertex, StrokeVertexConstructor, VertexId,
4};
5
6use crate::builder::ShapeBuilder;
7use crate::shape::Vertex;
8
9impl FillVertexConstructor<Vertex> for ShapeBuilder {
10    fn new_vertex(&mut self, mut vertex: FillVertex) -> Vertex {
11        let position = vertex.position();
12        let attributes = vertex.interpolated_attributes();
13        self.new_vertex(position, attributes)
14    }
15}
16
17impl StrokeVertexConstructor<Vertex> for ShapeBuilder {
18    fn new_vertex(&mut self, mut vertex: StrokeVertex) -> Vertex {
19        let position = vertex.position();
20        let attributes = vertex.interpolated_attributes();
21        self.new_vertex(position, attributes)
22    }
23}
24
25impl FillGeometryBuilder for ShapeBuilder {
26    fn add_fill_vertex(
27        &mut self,
28        mut vertex: FillVertex,
29    ) -> Result<VertexId, GeometryBuilderError> {
30        let position = vertex.position();
31        let attributes = vertex.interpolated_attributes();
32        self.add_vertex(position, attributes)
33    }
34}
35
36impl StrokeGeometryBuilder for ShapeBuilder {
37    fn add_stroke_vertex(
38        &mut self,
39        mut vertex: StrokeVertex,
40    ) -> Result<VertexId, GeometryBuilderError> {
41        let position = vertex.position();
42        let attributes = vertex.interpolated_attributes();
43        self.add_vertex(position, attributes)
44    }
45}
46
47impl GeometryBuilder for ShapeBuilder {
48    fn begin_geometry(&mut self) {}
49
50    fn end_geometry(&mut self) {}
51
52    fn add_triangle(&mut self, a: VertexId, b: VertexId, c: VertexId) {
53        self.indicies.push(a.0 as u16);
54        self.indicies.push(b.0 as u16);
55        self.indicies.push(c.0 as u16);
56    }
57
58    fn abort_geometry(&mut self) {
59        self.vertices.clear();
60        self.indicies.clear();
61    }
62}
63
64// impl FillGeometryBuilder for ShapeBuilder {
65//     fn add_fill_vertex(&mut self, vertex: FillVertex) -> Result<VertexId,
66// GeometryBuilderError> {         let color = self.default_color;
67//         self.add_vertex(vertex.position(), &color.interpolated_attributes())
68//     }
69// }
70
71// // impl StrokeGeometryBuilder for ShapeBuilder {
72// //     fn add_stroke_vertex(
73// //         &mut self,
74// //         vertex: StrokeVertex,
75// //     ) -> Result<VertexId, GeometryBuilderError> {
76// //         todo!()
77// //     }
78// // }