bevy-sculpter 0.18.0

SDF-based voxel sculpting and Surface Nets meshing for Bevy
Documentation

bevy-sculpter

Crates.io Docs.rs License

Screenshot

SDF-based voxel sculpting and Surface Nets meshing for Bevy.

⚠️ Early Development: This crate is under heavy development. Expect breaking changes between versions until 1.0.

Features

  • Density Fields: SDF-based volumetric representation with chunked storage
  • Surface Nets Meshing: Smooth mesh generation from density fields with seamless chunk boundaries
  • Sculpting Brushes: Smooth, hard (CSG), blur, and flatten brushes
  • Raycasting: Sphere-tracing and DDA-based raycasting into density fields
  • SDF Redistancing: Fast Sweeping Method for restoring proper signed distance fields

Bevy Compatibility

bevy-sculpter Bevy
0.18 0.18
0.1 0.17

Quick Start

use bevy::prelude::*;
use bevy_sculpter::prelude::*;
use chunky_bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(ChunkyPlugin::default())
        .add_plugins(SurfaceNetsPlugin)
        .insert_resource(DensityFieldMeshSize(vec3(10., 10., 10.)))
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands) {
    // Create a chunk with a sphere
    let mut field = DensityField::new();
    bevy_sculpter::helpers::fill_centered_sphere(&mut field, 12.0);
    
    commands.spawn((
        Chunk,
        ChunkPos(ivec3(0, 0, 0)),
        field,
        DensityFieldDirty,
    ));

    // Camera and lighting...
}

Sculpting

The crate provides several brush types for modifying density fields:

use bevy_sculpter::helpers::*;

// Hard CSG operations (instant)
brush_sphere(&mut field, center, radius, true);  // Add material
brush_sphere(&mut field, center, radius, false); // Remove material

// Smooth continuous brushes (for held input)
brush_smooth_timed(&mut field, center, radius, rate, delta_time, falloff);

// Surface smoothing
brush_blur(&mut field, center, radius, strength, falloff);

// Terrain flattening
brush_flatten(&mut field, center, radius, target_height, strength, falloff);

Examples

Run the interactive sculpting example:

cargo run --example sculpt

Controls:

  • Middle click + drag: Rotate camera
  • Right click (hold): Add material
  • Left click (hold): Remove material
  • Ctrl + click: Hard brush (instant CSG)
  • B: Toggle brush mode (Smooth/Blur)
  • Scroll: Adjust brush size
  • [ / ]: Adjust brush strength
  • WASD/Space/Shift: Move camera

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Acknowledgments

Surface Nets implementation inspired by fast-surface-nets-rs by bonsairobo.