Maintainers: @wodend
Provides functions for generating MagicaVoxel models using popular 3D procedural generation techniques.
So far, only 2D L Systems are implemented, for example:
All voxel generation functions provided operate on types that implement the VoxelBuffer
trait.
Manipulate a buffer of voxels by setting individual voxel values.
```rust use voxgen::voxel_buffer::{ArrayVoxelBuffer, Rgba, VoxelBuffer};
let mut vol = ArrayVoxelBuffer::new(32, 32, 32);
// Draw a simple 2D red cross and save as a MagicaVoxel .vox file. for x in 15..=17 { for y in 8..24 { // Modify a pixel by assigning a new value to it's mutable pointer. *vol.voxelmut(x, y, 0) = Rgba([255, 0, 0, 255]); *vol.voxelmut(y, x, 0) = Rgba([255, 0, 0, 255]); } }
vol.save("test/volumes/red_cross.vox")?;
```
Manipulate a VoxelBuffer
using LOGO-style turtle graphics commands.
```rust use voxgen::turtle_graphics::TurtleGraphics;
// Draw a line and save the output. let mut turtle = TurtleGraphics::new(3, 3, 3);
// Move the turtle 1 step forward (east) without drawing. turtle.step(1.0);
// Turn the turtle pi/2 radians left (facing north). turtle.left(std::f32::consts::FRACPI2);
// Draw a line 2 steps down the middle of the y axis. turtle.draw(2.0);
// Save the current drawing as a magicavoxel .vox file. turtle.buf().save("test/volumes/midyline.vox").unwrap(); ```
Inteprets L System strings and renders them using TurtleGraphics
.
```rust use voxgen::l_system::{LSystem, RenderOptions};
// Render a Koch curve. let lsystem = LSystem::new( "koch", "F-F-F-F", vec!["F→F-F+F+FF-F-F+F"], ); // Builder pattern for custom rendering options. // Default path is test/volumes/{lsystemname}{derivationlength}.vox. RenderOptions::new() .offsetx(-20.0) .offsety(-20.0) .render(lsystem); ```