nightshade 0.13.2

A cross-platform data-oriented game engine.
Documentation
//! Signed Distance Field (SDF) sculpting system for voxel-based terrain editing.
//!
//! Create and modify terrain in real-time using CSG operations on SDF primitives:
//!
//! - [`SdfWorld`]: Main resource holding all SDF data and edits
//! - [`SdfEdit`]: A sculpting operation (add/subtract/paint primitive)
//! - [`SdfPrimitive`]: Shape types (sphere, box, capsule, cylinder)
//! - [`CsgOperation`]: Union (add), subtraction (carve), intersection, paint
//! - [`SdfClipmap`]: LOD system for efficient rendering at multiple distances
//!
//! Requires the `sdf_sculpt` feature.
//!
//! # Architecture Overview
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │                         SdfWorld                                │
//! │  ┌──────────────┐  ┌──────────────┐  ┌───────────────────────┐  │
//! │  │   Edits      │  │   BrickMap   │  │      Clipmap          │  │
//! │  │  (history)   │  │  (sparse     │  │  (LOD levels for      │  │
//! │  │              │  │   voxels)    │  │   GPU rendering)      │  │
//! │  └──────────────┘  └──────────────┘  └───────────────────────┘  │
//! └─────────────────────────────────────────────────────────────────┘
//! ```
//!
//! - **Edits**: CSG operations stored as primitives + operations
//! - **BrickMap**: Sparse voxel storage using 8³ bricks
//! - **Clipmap**: Multi-resolution representation for efficient GPU rendering
//! - **BVH**: Acceleration structure for fast edit evaluation
//!
//! # Basic Sculpting
//!
//! ```ignore
//! // Add terrain (union)
//! let edit = SdfEdit::new(
//!     SdfPrimitive::Sphere { center: Vec3::new(0.0, 0.0, 0.0), radius: 5.0 },
//!     CsgOperation::Union,
//! );
//! world.resources.sdf.add_edit(edit);
//!
//! // Carve hole (subtraction)
//! let edit = SdfEdit::new(
//!     SdfPrimitive::Sphere { center: Vec3::new(2.0, 0.0, 0.0), radius: 2.0 },
//!     CsgOperation::Subtraction,
//! );
//! world.resources.sdf.add_edit(edit);
//!
//! // Paint material
//! let edit = SdfEdit::new(
//!     SdfPrimitive::Box { center: Vec3::zeros(), half_extents: Vec3::new(1.0, 1.0, 1.0) },
//!     CsgOperation::Paint { material_id: 2 },
//! );
//! world.resources.sdf.add_edit(edit);
//! ```
//!
//! # Available Primitives
//!
//! | Primitive | Parameters |
//! |-----------|------------|
//! | `Sphere` | center, radius |
//! | `Box` | center, half_extents |
//! | `Capsule` | point_a, point_b, radius |
//! | `Cylinder` | center, axis, radius, half_height |
//!
//! # CSG Operations
//!
//! | Operation | Effect |
//! |-----------|--------|
//! | `Union` | Add material (terrain building) |
//! | `Subtraction` | Remove material (carving) |
//! | `Intersection` | Keep only overlapping regions |
//! | `Paint` | Change material without changing shape |
//!
//! # Real-Time Sculpting
//!
//! ```ignore
//! fn on_mouse_input(&mut self, world: &mut World, button: MouseButton, state: KeyState) {
//!     if button == MouseButton::Left && state == KeyState::Pressed {
//!         // Get cursor position via GPU picking
//!         if let Some(result) = world.resources.gpu_picking.take_result() {
//!             let edit = SdfEdit::new(
//!                 SdfPrimitive::Sphere {
//!                     center: result.world_position,
//!                     radius: self.brush_size,
//!                 },
//!                 if self.is_adding {
//!                     CsgOperation::Union
//!                 } else {
//!                     CsgOperation::Subtraction
//!                 },
//!             );
//!             world.resources.sdf.add_edit(edit);
//!         }
//!     }
//! }
//! ```
//!
//! # Clipmap LOD System
//!
//! The clipmap provides multiple resolution levels for efficient rendering:
//!
//! | Level | Voxel Size | Range |
//! |-------|------------|-------|
//! | 0 | 0.25m | Near camera |
//! | 1 | 0.5m | Medium |
//! | 2 | 1.0m | Far |
//! | ... | 2^n × base | ... |
//!
//! The clipmap automatically updates around the camera position.
//!
//! # Materials
//!
//! ```ignore
//! // Register a material
//! world.resources.sdf.materials.register(SdfMaterial {
//!     id: 1,
//!     name: "Rock".to_string(),
//!     color: Vec3::new(0.5, 0.5, 0.5),
//!     roughness: 0.8,
//!     ..Default::default()
//! });
//! ```
//!
//! # Performance Notes
//!
//! - Edits are batched and evaluated on background threads
//! - BrickMap uses sparse storage (only allocates where needed)
//! - Clipmap updates incrementally around camera
//! - BVH accelerates edit evaluation for large edit counts

pub mod brick_map;
pub mod bvh;
pub mod clipmap;
pub mod collision;
pub mod evaluation;
pub mod marching_cubes;
pub mod primitives;
pub mod resources;

pub use brick_map::{
    ATLAS_SIZE, BRICK_CORNER_COUNT, BRICK_SIZE, BRICKS_PER_ATLAS_DIM, BrickData, EMPTY_BRICK,
    GRID_SIZE, MAX_BRICKS, brick_index_to_atlas_coord,
};
pub use bvh::SdfEditBvh;
pub use clipmap::{BASE_VOXEL_SIZE, DEFAULT_LEVEL_COUNT, LevelBlendInfo, SdfClipmap};
pub use collision::{CollisionChunkResult, SdfCollisionMesh};
pub use evaluation::{evaluate_sdf, trilinear_gradient, trilinear_interpolate};
pub use primitives::{Aabb, CsgOperation, SdfEdit, SdfPrimitive};
pub use resources::{SdfMaterial, SdfMaterialRegistry, SdfWorld, TerrainConfig};