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
mod loader;

use bevy::prelude::{App, AssetApp, Plugin};
pub use loader::VoxLoader;

/// Adds support for Vox file loading to Apps
#[derive(Default)]
pub struct VoxPlugin {
    /// MagicaVoxel considers Z as the vertical dimension. Setting this to true will use Y as height
    pub swap_yz: bool,
}

impl VoxPlugin {
    pub fn swap() -> Self {
        Self { swap_yz: false }
    }
}

impl Plugin for VoxPlugin {
    fn build(&self, app: &mut App) {
        app.preregister_asset_loader::<VoxLoader>(&["vox"]);
    }

    fn finish(&self, app: &mut App) {
        app.register_asset_loader(VoxLoader {
            swap_yz: self.swap_yz,
        });
    }
}