Crates.io | voxgen |
lib.rs | voxgen |
version | 0.4.0 |
source | src |
created_at | 2023-05-18 22:08:23.209516 |
updated_at | 2023-06-05 14:39:02.004057 |
description | Procedural voxel generation |
homepage | |
repository | https://github.com/wodend/voxgen |
max_upload_size | |
id | 868366 |
size | 378,390 |
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.
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.voxel_mut(x, y, 0) = Rgba([255, 0, 0, 255]);
*vol.voxel_mut(y, x, 0) = Rgba([255, 0, 0, 255]);
}
}
vol.save("test/volumes/red_cross.vox")?;
# Ok::<(), std::io::Error>(())
Manipulate a VoxelBuffer
using LOGO-style turtle graphics commands.
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::FRAC_PI_2);
// 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/mid_y_line.vox").unwrap();
Inteprets L System strings and renders them using TurtleGraphics
.
use voxgen::l_system::{LSystem, RenderOptions};
// Render a Koch curve.
let l_system = 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/{l_system_name}_{derivation_length}.vox.
RenderOptions::new()
.offset_x(-20.0)
.offset_y(-20.0)
.render(l_system);