2 unstable releases
0.2.0-alpha.1 | Oct 31, 2024 |
---|---|
0.1.0 | Oct 16, 2024 |
#571 in Game dev
105KB
667 lines
Voxy
A voxel engine for Bevy.
Features:
- Uses the block_mesh crate for high-performance chunk meshing
- Chunks are meshed and lit in parallel using async tasks
- Uses the dot_vox crate to load MagicaVoxel
.vox
files- Load multiple models into a
Scene
- Hot-reload of scene files
- Emissive textures and lighting
- Load multiple models into a
use bevy::{core_pipeline::bloom::BloomSettings, prelude::*};
use voxy::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, voxy::DefaultPlugins))
.add_systems(Startup, setup)
.add_systems(Update, rotate)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// Spawn a scene with multiple models from a `.vox` file.
commands.spawn((
asset_server.load::<VoxelScene>("character.vox"),
SpatialBundle::default(),
));
// Setup default lighting.
commands.insert_resource(AmbientLight {
brightness: 500.,
..default()
});
// Setup the camera.
commands.spawn((
Camera3dBundle {
camera: Camera {
hdr: true,
..default()
},
transform: Transform::from_translation(Vec3::new(-60., 60., -60.))
.looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
},
BloomSettings::NATURAL,
));
}
// Rotate the right arm of our character.
fn rotate(models_query: Query<&VoxelSceneModels>, mut transform_query: Query<&mut Transform>) {
for models in &models_query {
if let Some(entity) = models.entities.get("right_arm") {
let mut transform = transform_query.get_mut(*entity).unwrap();
transform.rotate_around(Vec3::new(0., 24., 4.), Quat::from_rotation_x(0.01));
}
}
}
Dependencies
~27–62MB
~1M SLoC