Skip to content

Commit

Permalink
Write layers (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
plule authored Apr 10, 2024
1 parent 43396c6 commit 5f0f449
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/dot_vox_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -169,6 +170,18 @@ impl DotVoxData {
Ok(())
}

fn write_layers<W: Write>(&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<W: Write>(writer: &mut W, id: &str, chunk: &[u8]) -> Result<(), io::Error> {
let num_children_bytes: u32 = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
));
}
}

0 comments on commit 5f0f449

Please sign in to comment.