mod model;
mod shape;
pub use model::{MeshModel, MeshTriangle, TextureImage};
pub use shape::MeshShape;
use crate::building::{BlockPalette, Shape};
use crate::blockpedia::ExtendedColorData;
use crate::{BlockState, UniversalSchematic};
const FALLBACK_RGB: [u8; 3] = [128, 128, 128];
pub fn voxelize_textured(
model_shape: &MeshShape,
palette: &BlockPalette,
schematic_name: &str,
) -> UniversalSchematic {
let mut schematic = UniversalSchematic::new(schematic_name.to_string());
model_shape.for_each_point(|x, y, z| {
let rgb = model_shape.surface_color(x, y, z).unwrap_or(FALLBACK_RGB);
let target = ExtendedColorData::from_rgb(rgb[0], rgb[1], rgb[2]);
if let Some(id) = palette.find_closest(&target) {
schematic.set_block(x, y, z, &BlockState::new(id));
}
});
schematic
}