10 breaking releases

0.15.0 Nov 30, 2024
0.10.0 Jul 15, 2024
0.9.0 Mar 16, 2024
0.8.1 Nov 16, 2023
0.2.0 Nov 4, 2020

#425 in Game dev

Download history 11/week @ 2024-09-22 8/week @ 2024-09-29 2/week @ 2024-10-13 7/week @ 2024-11-03 91/week @ 2024-11-24 44/week @ 2024-12-01

135 downloads per month

MIT license

33KB
167 lines

Load MagicaVoxel Vox file for bevy engine.

bevy_vox bevy
follow >=0.15
0.10 0.14

Example

use bevy::prelude::*;
use bevy_vox::VoxPlugin;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(VoxPlugin { swap_yz: true })
        .insert_resource(AmbientLight {
            color: Color::WHITE,
            brightness: 0.5,
        })
        .add_systems(Startup, setup)
        .add_systems(Update, rotate_model)
        .run();
}

#[derive(Component)]
struct VoxModel;

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    // add entities to the world
    commands.spawn((
        SceneRoot(asset_server.load("2x2x2.vox")),
        Transform::from_xyz(-1.0, 0.0, 0.0),
        VoxModel,
    ));

    // light
    commands.spawn((
        PointLight {
            intensity: 3_000_000.0,
            ..Default::default()
        },
        Transform::from_xyz(3.0, -3.5, 4.5),
    ));

    // camera
    commands.spawn((
        Camera3d::default(),
        Transform::from_xyz(6.0, -6.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y),
    ));
}

fn rotate_model(mut query: Query<&mut Transform, With<VoxModel>>, time: Res<Time>) {
    for mut transform in query.iter_mut() {
        transform.rotation = Quat::from_euler(EulerRot::XYZ, 0.0, time.elapsed_secs(), 0.0);
    }
}

Dependencies

~41–74MB
~1.5M SLoC