2019-01-13 20:53:55 +00:00
|
|
|
pub mod cell;
|
|
|
|
|
2019-06-06 14:48:41 +00:00
|
|
|
use self::cell::Cell;
|
2019-01-13 20:53:55 +00:00
|
|
|
use crate::{
|
2019-01-14 18:49:53 +00:00
|
|
|
vol::{Vox, WriteVol},
|
2019-01-13 20:53:55 +00:00
|
|
|
volumes::dyna::Dyna,
|
|
|
|
};
|
2019-06-06 14:48:41 +00:00
|
|
|
use dot_vox::DotVoxData;
|
|
|
|
use vek::*;
|
2019-01-13 20:53:55 +00:00
|
|
|
|
|
|
|
/// A type representing a volume that may be part of an animated figure.
|
|
|
|
///
|
|
|
|
/// Figures are used to represent things like characters, NPCs, mobs, etc.
|
|
|
|
pub type Segment = Dyna<Cell, ()>;
|
|
|
|
|
2019-04-28 02:12:30 +00:00
|
|
|
impl From<&DotVoxData> for Segment {
|
|
|
|
fn from(dot_vox_data: &DotVoxData) -> Self {
|
2019-01-13 20:53:55 +00:00
|
|
|
if let Some(model) = dot_vox_data.models.get(0) {
|
|
|
|
let palette = dot_vox_data
|
|
|
|
.palette
|
|
|
|
.iter()
|
|
|
|
.map(|col| Rgba::from(col.to_ne_bytes()).into())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
let mut segment = Segment::filled(
|
2019-04-29 20:37:19 +00:00
|
|
|
Vec3::new(model.size.x, model.size.y, model.size.z),
|
2019-01-13 20:53:55 +00:00
|
|
|
Cell::empty(),
|
|
|
|
(),
|
|
|
|
);
|
|
|
|
|
|
|
|
for voxel in &model.voxels {
|
|
|
|
if let Some(&color) = palette.get(voxel.i as usize) {
|
|
|
|
// TODO: Maybe don't ignore this error?
|
|
|
|
let _ = segment.set(
|
|
|
|
Vec3::new(voxel.x, voxel.y, voxel.z).map(|e| e as i32),
|
|
|
|
Cell::new(color),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
segment
|
|
|
|
} else {
|
|
|
|
Segment::filled(Vec3::zero(), Cell::empty(), ())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|