use super::ExampleVertices;
use crate::{
BufferElementType, Mesh, Primitive, PrimitiveType, Renderable, ShortIndex, VertexAttr,
VertexDesc,
};
pub fn new<R: Renderable>(eg: &mut ExampleVertices<R>, size: f32)
where
<R as Renderable>::Descriptor: Unpin,
{
let height = (2.0_f32 / 3.0).sqrt();
let centroid = height / 4.0;
let r3_2 = (3.0_f32).sqrt() * 0.5;
let s = 1.0 / (3.0_f32).sqrt();
let x = (23.0_f32 / 24.0).sqrt();
let vertex_data = [
size * 2.0 * s,
0.,
0.,
x,
0.,
-centroid,
-size * s,
size * 0.5,
0.,
-x * 0.5,
x * r3_2,
-centroid,
-size * s,
-size * 0.5,
0.,
-x * 0.5,
-x * r3_2,
-centroid,
0.,
0.,
size * height,
0.,
0.,
1.,
];
let index_data = [0u8, 1, 2, 3, 0, 1];
let data_indices = eg.push_byte_buffer(Box::new(index_data));
let data_vertices = eg.push_byte_buffer(Box::new(vertex_data));
let indices = eg.push_index_accessor(data_indices, 6, BufferElementType::UInt8, 0);
let desc = eg.push_descriptor(data_vertices, 0, 0, 0); let normals = eg.push_data_accessor(
desc,
VertexDesc::vec(VertexAttr::Normal, BufferElementType::Float32, 3, 3 * 4),
);
let vertices = eg.push_data_accessor(
desc,
VertexDesc::vec(VertexAttr::Position, BufferElementType::Float32, 3, 0),
);
eg.push_vertices(Some(indices), vertices, &[normals]);
}
pub fn mesh(v_id: ShortIndex, m_id: ShortIndex) -> Mesh {
let mut mesh = Mesh::default();
mesh.add_primitive(Primitive::new(
PrimitiveType::TriangleStrip,
v_id,
0,
6,
m_id,
));
mesh
}