use crate::{Index, FaceVertex, FaceVertexIndex, VertexIndex, FaceIndex};
use std::collections::HashMap;
pub struct AdaptiveGrid {
levels: u8,
scale: f32,
origin: [f32; 3],
indices: Vec<isize>,
subgrids: Vec<Grid>,
num_divisions: [usize; 3],
}
impl AdaptiveGrid {
const N: u8 = 2;
fn cell(i: usize, j: usize, k: usize) -> GridIndex {
let [nx, ny, nz] = num_divisions.into();
GridIndex::new(indices[nz*(ny * i + j) + k])
}
}
pub enum GridIndex {
Cell(usize),
SubGrid(usize),
Invalid,
}
impl GridIndex {
fn new(idx: isize) -> Self {
if idx < 0 {
GridIndex::SubGrid(idx as usize)
} else if idx > 0 {
GridIndex::Cell(idx as usize)
} else {
GridIndex::Invalid
}
}
}
impl MeshData {
pub fn new(verts: Vec<[f32; 3]>, indices: Vec<usize>) -> MeshData {
MeshData {
vertex_positions: verts,
indices,
}
}
}
impl_index_for_vec!(usize);
impl_index_for_vec!([f32; 3]);
pub struct TriMesh {
pub mesh_data: MeshData,
pub vertex_normals: Option<Vec<[f32; 3]>>,
}
impl TriMesh {
pub fn new(verts: Vec<[f32; 3]>, indices: Vec<usize>) -> TriMesh {
TriMesh {
mesh_data: MeshData::new(verts,indices),
vertex_normals: None,
}
}
pub fn vertex_normals(mut self, normals: Vec<[f32; 3]>) -> Self {
self.vertex_normals = Some(normals);
self
}
pub fn num_faces(&self) -> usize {
self.mesh_data.indices.len()/3
}
}
#[allow(dead_code)]
pub struct TetMesh {
mesh_data: MeshData,
}
#[allow(dead_code)]
pub struct PolyMesh {
mesh_data: MeshData,
offsets: Vec<usize>,
}
impl FaceVertex for TriMesh {
#[inline]
fn face_vertex<FI,FVI>(&self, fidx: FI, fvidx: FVI) -> VertexIndex
where FI: Into<FaceIndex> + Into<Index>,
FVI: Into<FaceVertexIndex> + Into<Index> {
let fidx_raw: Index = fidx.into();
let fvidx_raw: Index = fvidx.into();
debug_assert!({
if fvidx_raw.is_valid() {
fvidx_raw < 3
} else {
true }
});
self.mesh_data.indices[3*fidx_raw + fvidx_raw].into()
}
}