1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//! 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 use ;
pub use SdfEditBvh;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;