Expand description
A shader-based marching cubes implementation for Bevy.
To get started, add the MarchingCubesPlugin to your app.
The plugin takes a type argument similar to a Bevy material, ChunkComputeShader.
The ShaderRef provided by this type is a wgsl compute shader that takes a coordinate and returns the density of the chunk’s mass at that point,
generally with positive values representing being inside the mass and negative values being in air,
although the threshold can be configured with ChunkGeneratorSettings.
See this example asset for more details.
The plugin also takes a type argument implementing GpuExtraBufferCache, defining additional buffers to be used in the density sampler.
This example
uses this to determine the final position of a Point Of Interest based on terrain generation.
ChunkGeneratorSettings must be inserted.
ChunkMaterial must be inserted.
An entity must also be given ChunkLoader to start generating any chunks.
Structs§
- Buffer
Cache - Holds the main vertex/triangles buffers. May be hashed and used as an identifying key for a loading chunk.
- Chunk
- Marker component for each chunk.
- Chunk
GenSystems SystemSetfor chunk generation systems.- Chunk
Generator Cache - Holds the loading states of all the chunks.
- Chunk
Generator Settings - Settings for a chunk generator. Also controls whether said generator is running.
- Chunk
Loader - Loads nearby chunks.
- Chunk
Material - Holds the actual material chunks should be spawned with.
- Chunk
Render Data - Holds the buffers for a chunk being generated.
- Clear
Buffer Cache - Event meaning any extra buffers should be cleared entirely to prevent memory leaks, like when the chunk generator is destroyed.
- GpuChunk
Generator Cache - Holds extra buffers to be used when sampling the density field.
- Marching
Cubes Plugin - The plugin. Add this to your app or the crate won’t work!
- Readback
Really Complete - Event that needs to be sent when an extra buffer has been finished reading from. Otherwise, the chunk will never finish generating.
Enums§
- Chunk
Generator Running - Controls for whether the generator should be running.
- Load
State - Whether a chunk is loading or has finished loading.
- Shader
Ref - A reference to a shader asset.
Traits§
- Chunk
Compute Shader - Reference to the shader used for sampling the density field.
- GpuExtra
Buffer Cache - Defines extra buffers to be used in the density sampler.
Functions§
- is_
generator_ running - Run condition for whether a chunk generator is running and listening to
ChunkLoaders, regardless of whether it’s actually generating anything. - value_
data - Converts a
ShaderTypeintoVec<u8>data.