voxy

Crates.iovoxy
lib.rsvoxy
version0.2.0-alpha.1
sourcesrc
created_at2024-10-16 02:17:13.778109
updated_at2024-10-31 15:32:35.963334
descriptionVoxel engine for Bevy
homepage
repository
max_upload_size
id1411052
size232,476
Matt Hunzinger (matthunz)

documentation

README

Voxy

License Crates.io Downloads Docs CI

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
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));
        }
    }
}
Commit count: 0

cargo fmt