mod3d_base/example_objects/
triangle.rs1use super::ExampleVertices;
10use crate::{
11 BufferElementType, Mesh, Primitive, PrimitiveType, Renderable, ShortIndex, VertexAttr,
12};
13
14pub fn new<R: Renderable>(eg: &mut ExampleVertices<R>, size: f32) {
17 let vertex_data = [
18 -size, -size, 0.0, size, -size, 0.0, 0.0, size, 0.0, 0., 0., 1., 0., 0., 1., 0., 0., 1.,
19 ];
20 let index_data = [0u8, 1, 2];
21
22 let data_vertices = eg.push_byte_buffer(Box::new(vertex_data));
23 let data_indices = eg.push_byte_buffer(Box::new(index_data));
24
25 let indices = eg.push_index_accessor(data_indices, 3, BufferElementType::UInt8, 0);
26 let vertices = eg.push_data_accessor(data_vertices, 3, BufferElementType::Float32, 0, 0);
27 let normals = eg.push_data_accessor(data_vertices, 3, BufferElementType::Float32, 9 * 4, 0);
28
29 eg.push_vertices(Some(indices), vertices, &[(VertexAttr::Normal, normals)]);
31}
32
33pub fn mesh(v_id: ShortIndex, m_id: ShortIndex) -> Mesh {
39 let mut mesh = Mesh::default();
40 mesh.add_primitive(Primitive::new(PrimitiveType::Triangles, v_id, 0, 3, m_id));
41 mesh
42}