initial support for multiple models in one vox file

This commit is contained in:
Christof Petig 2023-03-13 00:37:29 +01:00
parent b3cd1c1e56
commit 9b3bf4c3c8
3 changed files with 361 additions and 196 deletions

View File

@ -175,6 +175,8 @@ pub mod figuredata {
pub offset: [f32; 3],
pub phys_offset: [f32; 3],
pub central: VoxSimple,
#[serde(default)]
pub model_index: u32,
}
/// manual instead of through `make_vox_spec!` so that it can be in `common`
@ -220,7 +222,7 @@ pub mod figuredata {
// need to load them in the server and sync them as an ECS resource.
let vox =
cache.load::<DotVoxAsset>(&["common.voxel.", &bone.central.0].concat())?;
let dyna = Dyna::<Cell, (), ColumnAccess>::from_vox(&vox.read().0, false);
let dyna = Dyna::<Cell, (), ColumnAccess>::from_vox(&vox.read().0, false, bone.model_index as usize);
let dyna = dyna.map_into(|cell| {
if let Some(rgb) = cell.get_color() {
Block::new(BlockKind::Misc, rgb)

View File

@ -21,7 +21,11 @@ use vek::*;
pub type Segment = Dyna<Cell, ()>;
impl From<&DotVoxData> for Segment {
fn from(dot_vox_data: &DotVoxData) -> Self { Segment::from_vox(dot_vox_data, false) }
fn from(dot_vox_data: &DotVoxData) -> Self { Segment::from_vox(dot_vox_data, false, 0) }
}
impl From<(&DotVoxData, usize)> for Segment {
fn from(spec: (&DotVoxData, usize)) -> Self { Segment::from_vox(spec.0, false, spec.1) }
}
impl Segment {
@ -30,13 +34,13 @@ impl Segment {
pub fn from_voxes(data: &[(&DotVoxData, Vec3<i32>, bool)]) -> (Self, Vec3<i32>) {
let mut union = DynaUnionizer::new();
for (datum, offset, xmirror) in data.iter() {
union = union.add(Segment::from_vox(datum, *xmirror), *offset);
union = union.add(Segment::from_vox(datum, *xmirror, 0), *offset);
}
union.unify()
}
pub fn from_vox(dot_vox_data: &DotVoxData, flipped: bool) -> Self {
if let Some(model) = dot_vox_data.models.get(0) {
pub fn from_vox(dot_vox_data: &DotVoxData, flipped: bool, model_index: usize) -> Self {
if let Some(model) = dot_vox_data.models.get(model_index) {
let palette = dot_vox_data
.palette
.iter()
@ -202,8 +206,8 @@ impl MatSegment {
})
}
pub fn from_vox(dot_vox_data: &DotVoxData, flipped: bool) -> Self {
if let Some(model) = dot_vox_data.models.get(0) {
pub fn from_vox(dot_vox_data: &DotVoxData, flipped: bool, model_index: usize) -> Self {
if let Some(model) = dot_vox_data.models.get(model_index) {
let palette = dot_vox_data
.palette
.iter()
@ -264,5 +268,9 @@ impl MatSegment {
}
impl From<&DotVoxData> for MatSegment {
fn from(dot_vox_data: &DotVoxData) -> Self { Self::from_vox(dot_vox_data, false) }
fn from(dot_vox_data: &DotVoxData) -> Self { Self::from_vox(dot_vox_data, false, 0) }
}
impl From<(&DotVoxData, usize)> for MatSegment {
fn from(spec: (&DotVoxData, usize)) -> Self { Self::from_vox(spec.0, false, spec.1) }
}

File diff suppressed because it is too large Load Diff