From 15e406383d513dd51ff7eb2cb2c06216d58556f3 Mon Sep 17 00:00:00 2001 From: plule <630159+plule@users.noreply.github.com> Date: Wed, 3 Apr 2024 23:12:08 +0200 Subject: [PATCH] Write layers --- src/dot_vox_data.rs | 13 +++++++++++++ src/lib.rs | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/dot_vox_data.rs b/src/dot_vox_data.rs index 7a64c08..1a66eca 100644 --- a/src/dot_vox_data.rs +++ b/src/dot_vox_data.rs @@ -29,6 +29,7 @@ impl DotVoxData { self.write_scene_graph(&mut children_buffer)?; self.write_palette_chunk(&mut children_buffer)?; self.write_materials(&mut children_buffer)?; + self.write_layers(&mut children_buffer)?; let num_main_children_bytes = children_buffer.len() as u32; self.write_main_chunk(writer, num_main_children_bytes)?; @@ -169,6 +170,18 @@ impl DotVoxData { Ok(()) } + fn write_layers(&self, writer: &mut W) -> Result<(), io::Error> { + for (i, layer) in self.layers.iter().enumerate() { + let id = i as u32; + let mut chunk = Vec::new(); + chunk.extend_from_slice(&id.to_le_bytes()); + Self::write_dict(&mut chunk, &layer.attributes); + chunk.extend_from_slice(&u32::MAX.to_le_bytes()); + Self::write_leaf_chunk(writer, "LAYR", &chunk)?; + } + Ok(()) + } + fn write_leaf_chunk(writer: &mut W, id: &str, chunk: &[u8]) -> Result<(), io::Error> { let num_children_bytes: u32 = 0; diff --git a/src/lib.rs b/src/lib.rs index 2db72a0..36f0b21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -443,8 +443,8 @@ mod tests { write_and_load(placeholder( DEFAULT_PALETTE.to_vec(), DEFAULT_MATERIALS.to_vec(), - Vec::new(), - Vec::new(), + placeholder::SCENES.to_vec(), + placeholder::LAYERS.to_vec(), )); } }