4个版本 (破坏性)
0.4.0 | 2023年6月5日 |
---|---|
0.3.0 | 2023年6月5日 |
0.2.0 | 2023年6月3日 |
0.1.0 | 2023年5月18日 |
#392 在 图形API
每月42次下载
325KB
455 行
Voxgen
维护者: @wodend
一个过程式体素生成库
提供使用流行的3D过程式生成技术生成 MagicaVoxel 模型的函数。
到目前为止,仅实现了2D L系统,例如:
所有提供的体素生成函数都操作实现了 VoxelBuffer
特性的类型。
原始体素缓冲区
通过设置单个体素值来操作体素缓冲区。
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>(())
海龟图形
使用LOGO风格的命令操作 VoxelBuffer
。
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();
L系统
解释L系统字符串,并使用 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);
依赖项
~3.5MB
~74K SLoC