transvoxel/extraction.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
/*!
Main mesh extraction methods
*/
use super::implementation::algorithm::Extractor;
use super::mesh_builder::*;
use super::traits::*;
use super::voxel_source::*;
use crate::transition_sides::TransitionSides;
/**
Extracts an iso-surface mesh for a [VoxelSource]
Arguments:
* `source`: the voxel data source
* `block`: the world zone for which to extract, and its subdivisions count
* `threshold`: density value defining the iso-surface
* `transition_sides`: the set of sides of the block which need to be adapted to neighbour double-resolution blocks (twice the subdivisions)
* `mesh_builder`: builder object on which functions will be called to append vertices and triangles
* The provided mesh_builder is returned back at the end.
*/
pub fn extract<C, V, S, M>(
source: S,
block: &Block<C>,
threshold: V::Density,
transition_sides: TransitionSides,
mesh_builder: M,
) -> M
where
C: Coordinate,
V: VoxelData,
S: VoxelSource<V>,
M: MeshBuilder<V, C>,
{
Extractor::new(source, block, threshold, transition_sides, mesh_builder).extract()
}
/**
Extracts an iso-surface mesh for a [DataField]
Arguments:
* `field`: the voxel data field
* `block`: the world zone for which to extract, and its subdivisions count
* `threshold`: density value defining the iso-surface
* `transition_sides`: the set of sides of the block which need to be adapted to neighbour double-resolution blocks (twice the subdivisions)
* `mesh_builder`: builder object on which functions will be called to append vertices and triangles
* The provided mesh_builder is returned back at the end.
*/
pub fn extract_from_field<C, V, FIELD, M>(
field: FIELD,
block: &Block<C>,
threshold: V::Density,
transition_sides: TransitionSides,
mesh_builder: M,
) -> M
where
C: Coordinate,
V: VoxelData,
FIELD: DataField<V, C>,
M: MeshBuilder<V, C>,
{
let source = WorldMappingVoxelSource { field, block };
Extractor::new(source, block, threshold, transition_sides, mesh_builder).extract()
}
/**
Extracts an iso-surface mesh for a [DataField]-compatible closure
Arguments:
* `f`: the closure providing world data
* `block`: the world zone for which to extract, and its subdivisions count
* `threshold`: density value defining the iso-surface
* `transition_sides`: the set of sides of the block which need to be adapted to neighbour double-resolution blocks (twice the subdivisions)
* `mesh_builder`: builder object on which functions will be called to append vertices and triangles
* The provided mesh_builder is returned back at the end.
*/
pub fn extract_from_fn<C, V, FUN, M>(
field: FUN,
block: &Block<C>,
threshold: V::Density,
transition_sides: TransitionSides,
mesh_builder: M,
) -> M
where
C: Coordinate,
V: VoxelData,
FUN: FnMut(C, C, C) -> V,
M: MeshBuilder<V, C>,
{
let source = WorldMappingVoxelSource { field, block };
Extractor::new(source, block, threshold, transition_sides, mesh_builder).extract()
}