use super::RenderPolyline;
use super::{IndexBuffer, RenderMesh};
use glamx::{Vec2, Vec3};
pub fn cuboid(extents: Vec3) -> RenderMesh {
let mut cuboid = unit_cuboid();
cuboid.scale_by(extents);
cuboid
}
pub fn unit_cuboid() -> RenderMesh {
let mut coords = Vec::with_capacity(8);
let mut uvs = Vec::with_capacity(4);
let mut normals = Vec::with_capacity(6);
let mut faces = Vec::with_capacity(12);
coords.push(Vec3::new(-0.5, -0.5, 0.5));
coords.push(Vec3::new(-0.5, -0.5, -0.5));
coords.push(Vec3::new(0.5, -0.5, -0.5));
coords.push(Vec3::new(0.5, -0.5, 0.5));
coords.push(Vec3::new(-0.5, 0.5, 0.5));
coords.push(Vec3::new(-0.5, 0.5, -0.5));
coords.push(Vec3::new(0.5, 0.5, -0.5));
coords.push(Vec3::new(0.5, 0.5, 0.5));
uvs.push(Vec2::new(0.0, 1.0));
uvs.push(Vec2::new(1.0, 1.0));
uvs.push(Vec2::new(0.0, 0.0));
uvs.push(Vec2::new(1.0, 0.0));
normals.push(Vec3::new(-1.0, 0.0, 0.0));
normals.push(Vec3::new(0.0, 0.0, -1.0));
normals.push(Vec3::new(1.0, 0.0, 0.0));
normals.push(Vec3::new(0.0, 0.0, 1.0));
normals.push(Vec3::new(0.0, -1.0, 0.0));
normals.push(Vec3::new(0.0, 1.0, 0.0));
faces.push([[4, 0, 0], [5, 0, 1], [0, 0, 2]]);
faces.push([[5, 0, 1], [1, 0, 3], [0, 0, 2]]);
faces.push([[5, 1, 0], [6, 1, 1], [1, 1, 2]]);
faces.push([[6, 1, 1], [2, 1, 3], [1, 1, 2]]);
faces.push([[6, 2, 1], [7, 2, 0], [3, 2, 2]]);
faces.push([[2, 2, 3], [6, 2, 1], [3, 2, 2]]);
faces.push([[7, 3, 1], [4, 3, 0], [0, 3, 2]]);
faces.push([[3, 3, 3], [7, 3, 1], [0, 3, 2]]);
faces.push([[0, 4, 2], [1, 4, 0], [2, 4, 1]]);
faces.push([[3, 4, 3], [0, 4, 2], [2, 4, 1]]);
faces.push([[7, 5, 3], [6, 5, 1], [5, 5, 0]]);
faces.push([[4, 5, 2], [7, 5, 3], [5, 5, 0]]);
RenderMesh::new(
coords,
Some(normals),
Some(uvs),
Some(IndexBuffer::Split(faces)),
)
}
pub fn rectangle(extents: Vec2) -> RenderPolyline {
let mut rectangle = unit_rectangle();
rectangle.scale_by(extents);
rectangle
}
pub fn unit_rectangle() -> RenderPolyline {
let p_ul = Vec2::new(-0.5, 0.5);
let p_ur = Vec2::new(0.5, 0.5);
let p_dl = Vec2::new(-0.5, -0.5);
let p_dr = Vec2::new(0.5, -0.5);
RenderPolyline::new(vec![p_ur, p_ul, p_dl, p_dr], None)
}