use super::traits::mesh_builder::*;
use crate::implementation::algorithm;
use crate::structs::block::Block;
use crate::structs::block_star_view::BlockStarView;
use crate::traits::coordinate::Coordinate;
use crate::traits::voxel_data::VoxelData;
use crate::structs::transition_sides::TransitionSides;
use crate::structs::voxel_blocks::{VoxelBlockRelayingToField, VoxelVecBlock};
use crate::traits::data_field::DataField;
use crate::traits::voxel_block::{VoxelBlock};
pub fn extract<C, V, M, B1, B2>(
blocks: &BlockStarView<C, V, B1, B2>,
threshold: V::Density,
mesh_builder: M,
) -> M
where
C: Coordinate,
V: VoxelData,
B1: VoxelBlock<C, V>,
B2: VoxelBlock<C, V>,
M: MeshBuilder<V, C>,
{
algorithm::Extractor::new(blocks, threshold, mesh_builder).extract()
}
pub enum FieldCaching {
CacheNothing,
CacheCentralBlockOnly,
}
pub fn extract_from_field<C, V, M, F: DataField<V, C>>(
field: &F,
caching_strategy: FieldCaching,
block: Block<C>,
transition_sides: TransitionSides,
threshold: V::Density,
mesh_builder: M,
) -> M
where
C: Coordinate,
V: VoxelData + Copy,
M: MeshBuilder<V, C>,
{
match caching_strategy {
FieldCaching::CacheNothing => {
let blocks = BlockStarView::new_relaying_to_field(field, block, &transition_sides);
algorithm::Extractor::new(&blocks, threshold, mesh_builder).extract()
}
FieldCaching::CacheCentralBlockOnly => {
let central = VoxelVecBlock::cache(field, block);
let mut blocks = BlockStarView::new_simple(central);
for side in transition_sides {
blocks = blocks.with_neighbour(VoxelBlockRelayingToField { field, block }, side);
}
algorithm::Extractor::new(&blocks, threshold, mesh_builder).extract()
}
}
}