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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
//! # voxel-framework
//!
//! A reusable voxel engine library built on [Bevy](https://bevyengine.org/),
//! providing all the infrastructure needed to build voxel-based games and
//! simulations: chunk storage, procedural generation, greedy meshing, world
//! streaming, PBR rendering, and player interaction.
//!
//! ## Overview
//!
//! The framework is built around three core abstractions:
//!
//! - **[`voxel::VoxelType`]** — a trait that every voxel palette must implement.
//! It describes whether a voxel is solid, what color it renders as, and how
//! it serializes to and from a single byte for persistence. The built-in
//! [`voxel::DefaultVoxel`] palette covers five material types (Air, Rock,
//! IronOre, SiliconCrystal, RareMineral) and is ready to use out of the box.
//!
//! - **[`chunk::Chunk<V>`]** — the fundamental storage unit. A 16×16×16 flat
//! array of voxels stored on the heap. All generation, meshing, and I/O
//! operate on chunks identified by a [`chunk::ChunkCoord`] (an `IVec3`
//! where one unit equals `CHUNK_SIZE` world-space units).
//!
//! - **[`generator::ChunkGenerator`]** — an async-safe trait implemented by
//! procedural generators. Generators run on a Bevy `AsyncComputeTaskPool`
//! thread and produce fully populated [`chunk::Chunk<V>`] values, which are
//! then handed back to the main world for meshing and insertion.
//!
//! ## Plugin Catalog Architecture
//!
//! `voxel-framework` exposes a flat catalog of Bevy plugins grouped by
//! responsibility. Game crates compose the plugins they need instead of
//! depending on a hidden monolithic game plugin:
//!
//! | Category | Purpose | Examples |
//! |----------|---------|----------|
//! | Engine | Foundation for streamable/renderable voxel worlds | [`world::WorldPlugin`], [`mesh::MeshPlugin`], [`render::RenderPlugin`] |
//! | World Data | Chunk sources, generation, persistence, lifecycle data | [`generator::GeneratorPlugin`], [`world::PersistencePlugin`] |
//! | Gameplay | Reusable rules and interactions | [`content::VoxelContentPlugin`], [`stats::VoxelStatsPlugin`], [`effects::VoxelEffectsPlugin`], [`world::mining::MiningPlugin`], [`world::placement::PlacementPlugin`], [`player::PlayerPlugin`] |
//! | Default Implementation | Replaceable UI/audio/visual defaults | [`ui::UiPlugin`], [`ui::VoxelHudPlugin`], [`skybox::SkyboxPlugin`], [`audio::DefaultAudioPlugin`] |
//! | Convenience | Compatibility bundles, input adapters, recipes, prototyping helpers | [`VoxelCorePlugin`], [`VoxelPlugin`] |
//!
//! These categories are also represented by marker traits in
//! [`plugin_category`]. They are documentation and API classification tools;
//! Bevy composition still uses the normal [`Plugin`] trait.
//!
//! [`VoxelCorePlugin`] and [`VoxelPlugin`] remain available as convenience
//! bundles for compatibility and quick starts, but they are not the primary
//! architecture. New domain behavior should normally be modeled as an explicit
//! Engine, World Data, Gameplay, or Default Implementation plugin.
//!
//! [`generator::GeneratorPlugin`] is always **opt-in** because it is generic
//! over `V: VoxelType` and requires the caller to supply a
//! [`generator::GeneratorResource`] holding a concrete generator. Add it
//! separately after either a bundle or explicit engine plugins.
//!
//! [`ui::VoxelHudPlugin`] is also explicit and remains outside [`ui::UiPlugin`]
//! and the convenience bundles. Authors register domain-neutral presentation
//! definitions, publish screen-ready values, and may schedule same-frame
//! publishers in [`ui::HudSystemSet::Publish`]. The retained renderer preserves
//! element identity and safely hides unresolved or unavailable asset inputs.
//!
//! ## The Chunk Pipeline
//!
//! The full data flow from viewer movement to rendered geometry:
//!
//! ```text
//! ViewerPosition update
//! │
//! ▼
//! WorldPlugin — streaming system
//! Computes which chunks are within the configured render distance.
//! Emits ChunkRequested events for chunks not yet loaded.
//! │
//! ▼
//! GeneratorPlugin — async generation (AsyncComputeTaskPool)
//! Spawns a task per requested chunk. Each task calls
//! ChunkGenerator::generate(coord) → Chunk<V>.
//! When the task completes, inserts the Chunk<V> component and emits
//! ChunkModified so downstream systems are notified.
//! │
//! ▼
//! MeshPlugin — greedy mesh generation
//! Reacts to ChunkModified. Iterates the chunk with a configurable LOD
//! step, runs the greedy meshing algorithm, and uploads a Bevy Mesh asset.
//! │
//! ▼
//! RenderPlugin — PBR material + entity spawn
//! Attaches a shared chunk PBR material and a MeshBundle to the chunk
//! entity so Bevy's renderer picks it up on the next frame.
//! │
//! ▼
//! OcclusionPlugin — neighbor-solid occlusion
//! Reacts to ChunkModified and hides chunks whose six face-adjacent
//! neighbours are all loaded and fully solid.
//! ```
//!
//! ## Quick Start
//!
//! A minimal working world using the built-in asteroid generator:
//!
//! ```rust,no_run
//! use bevy::prelude::*;
//! use voxel_framework::{
//! VoxelPlugin,
//! generator::{GeneratorPlugin, GeneratorResource},
//! generator::asteroid::{AsteroidConfig, AsteroidGenerator},
//! voxel::DefaultVoxel,
//! };
//! use std::sync::Arc;
//!
//! App::new()
//! .add_plugins(DefaultPlugins)
//! .add_plugins(VoxelPlugin::<DefaultVoxel>::new())
//! .add_plugins(GeneratorPlugin::<DefaultVoxel>::new())
//! .insert_resource(GeneratorResource::<DefaultVoxel> {
//! generator: Arc::new(AsteroidGenerator::new(AsteroidConfig::default())),
//! })
//! .run();
//! ```
//!
//! Use explicit catalog plugins instead of [`VoxelPlugin`] when you want full
//! control over engine, world data, gameplay, and presentation defaults.
//!
//! ## Extending the Framework
//!
//! To use a custom voxel palette, implement [`voxel::VoxelType`] on your own type and
//! substitute it wherever the framework is generic over `V: VoxelType`:
//!
//! - [`generator::GeneratorPlugin::<YourVoxel>::new()`][`generator::GeneratorPlugin`]
//! - [`mesh::MeshPlugin::<YourVoxel>::new()`][`mesh::MeshPlugin`]
//! - [`render::RenderPlugin::<YourVoxel>::new()`][`render::RenderPlugin`]
//!
//! To drive generation, implement [`generator::ChunkGenerator`] and wrap it in
//! a [`generator::GeneratorResource`].
//!
//! See [`prelude`] for the most commonly used re-exports.
use *;
use SfxPlugin;
use FragmentPlugin;
use HotbarPlugin;
use MeshPlugin;
use RenderPlugin;
use SkyboxPlugin;
use UiPlugin;
use DefaultVoxel;
use VoxelType;
use LoadingPlugin;
use MiningPlugin;
use OcclusionPlugin;
use PlacementPlugin;
use ;
/// Convenience bundle for the historical core voxel runtime.
///
/// `VoxelCorePlugin<V>` wires up the legacy core bundle — world streaming,
/// chunk lifecycle, meshing, PBR rendering, neighbor-solid occlusion, mining,
/// placement, and loading state — without the bundled presentation defaults
/// from [`VoxelPlugin`].
///
/// In the plugin catalog taxonomy this type is a [`plugin_category::ConveniencePlugin`]:
/// it composes stricter Engine and Gameplay plugins for compatibility and quick
/// starts. New architecture should describe those individual plugins by their
/// primary categories rather than treating this bundle as the whole model.
///
/// The generic parameter `V` selects the voxel type used by the rendering,
/// meshing, and occlusion systems. Defaults to [`DefaultVoxel`] for backwards
/// compatibility: `VoxelCorePlugin::default()` and
/// `VoxelCorePlugin::<DefaultVoxel>::new()` are equivalent.
///
/// # Included systems
///
/// | Plugin | Responsibility |
/// |--------|----------------|
/// | [`WorldPlugin`] | [`world::ChunkManager`], [`world::systems::ViewerPosition`], chunk lifecycle events, and streaming |
/// | [`WorldConfigPlugin`] | Inserts the [`world::WorldConfig`] resource |
/// | `RenderPlugin<V>` | Shared chunk PBR material and entity spawn |
/// | `MeshPlugin<V>` | Greedy mesh generation and chunk despawn |
/// | `OcclusionPlugin<V>` | Neighbor-solid chunk occlusion |
/// | [`world::mining::MiningPlugin`] | Gameplay primitive for voxel removal |
/// | [`world::placement::PlacementPlugin`] | Gameplay primitive for voxel placement |
/// | [`world::loading::LoadingPlugin`] | World loading state machine |
///
/// # Not included (opt-in)
///
/// - [`generator::GeneratorPlugin`] — requires the caller to supply a
/// [`generator::GeneratorResource`].
///
/// # Example
///
/// ```rust,no_run
/// use bevy::prelude::*;
/// use voxel_framework::{VoxelCorePlugin, generator::{GeneratorPlugin, GeneratorResource}};
/// use voxel_framework::generator::asteroid::{AsteroidConfig, AsteroidGenerator};
/// use voxel_framework::voxel::DefaultVoxel;
/// use std::sync::Arc;
///
/// App::new()
/// .add_plugins(DefaultPlugins)
/// .add_plugins(VoxelCorePlugin::<DefaultVoxel>::new())
/// .add_plugins(GeneratorPlugin::<DefaultVoxel>::new())
/// .insert_resource(GeneratorResource::<DefaultVoxel> {
/// generator: Arc::new(AsteroidGenerator::new(AsteroidConfig::default())),
/// })
/// .run();
/// ```
///
/// # See also
///
/// - [`VoxelPlugin`] — broader quick-start convenience bundle.
/// Quick-start convenience bundle for demos and prototypes.
///
/// `VoxelPlugin<V>` composes [`VoxelCorePlugin<V>`] with selected presentation
/// and gameplay defaults. It is useful for examples, demos, and early
/// prototyping, but it is not the architectural definition of the full
/// framework. Production games should treat it as a convenience bundle and
/// switch to explicit catalog plugins when they need finer control.
///
/// The generic parameter `V` selects the voxel type. Defaults to
/// [`DefaultVoxel`] — `VoxelPlugin::default()` produces an asteroid-palette
/// world, `VoxelPlugin::<DefaultTerrainVoxel>::new()` produces a terrain world.
///
/// # Included beyond [`VoxelCorePlugin`]
///
/// | Plugin | Responsibility |
/// |--------|----------------|
/// | [`FragmentPlugin`] | Floating voxel debris entities ejected on mining |
/// | [`SkyboxPlugin`] | Procedural starfield and skybox rendering |
/// | [`SfxPlugin`] | Positional audio effects for mining and placement |
/// | [`UiPlugin`] | Crosshair, loading screen, and HUD overlays |
///
/// # Generator not included
///
/// [`generator::GeneratorPlugin`] is intentionally excluded because it requires
/// the caller to supply a concrete [`generator::GeneratorResource`]. Always add
/// it separately:
///
/// ```rust,no_run
/// use bevy::prelude::*;
/// use voxel_framework::{VoxelPlugin, generator::{GeneratorPlugin, GeneratorResource}};
/// use voxel_framework::generator::terrain::{TerrainConfig, TerrainGenerator};
/// use voxel_framework::voxel::DefaultTerrainVoxel;
/// use std::sync::Arc;
///
/// App::new()
/// .add_plugins(DefaultPlugins)
/// .add_plugins(VoxelPlugin::<DefaultTerrainVoxel>::new())
/// .add_plugins(GeneratorPlugin::<DefaultTerrainVoxel>::new())
/// .insert_resource(GeneratorResource::<DefaultTerrainVoxel> {
/// generator: Arc::new(TerrainGenerator::new(TerrainConfig::default())),
/// })
/// .run();
/// ```
///
/// # See also
///
/// - [`VoxelCorePlugin`] — narrower compatibility/convenience bundle.
/// - [`prelude`] — commonly used re-exports for convenience imports.