Code Monkey home page Code Monkey logo

bevy_vox_mesh's Introduction

bevy_vox_mesh

A plugin for the bevy engine which allows loading magica voxel .vox files directly into usable meshes. This uses mesh vertex coloring.

Bevy compatibility

Bevy version Plugin version
0.5 0.1, 0.2
0.8 0.4
0.9 0.5
0.10 0.6
0.11 0.7, 0.7.1
0.12 0.8

Usage

demo screenshot

use bevy::prelude::*;
use bevy_vox_mesh::VoxMeshPlugin;
use std::f32::consts::PI;

fn main() {
    App::default()
        .add_plugins(DefaultPlugins)
        .add_plugin(VoxMeshPlugin::default())
        .add_startup_system(setup)
        .run();
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut stdmats: ResMut<Assets<StandardMaterial>>,
    assets: Res<AssetServer>,
) {
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..Default::default()
    });

    commands.spawn(PbrBundle {
        transform: Transform::from_scale((0.01, 0.01, 0.01).into())
            * Transform::from_rotation(Quat::from_axis_angle(Vec3::Y, PI)),
        mesh: assets.load("chicken.vox"),
        material: stdmats.add(Color::rgb(1., 1., 1.).into()),
        ..Default::default()
    });
}

Take a look in the examples/ directory for a complete working example.

Acknowledgements

This asset loader is powered by the awesome block-mesh-rs crate.

Ported to bevy 0.12.0 thanks to @baranyildirim.

bevy_vox_mesh's People

Contributors

athilenius avatar baranyildirim avatar game4all avatar zzhgithub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bevy_vox_mesh's Issues

Models are flipped on the x-axis

If you compare how an asymmetrical model appears in MV with Bevy, when loading via bevy_vox_mesh, the model is flipped on the x axis.

eg: the monu1 model that ships with MagicaVoxel as viewed in MV:

image

Same model in bevy:

image

I believe the fix for this is to change the linearisation in voxel.rs lines 35-37 to:

        let index =
            model_shape.linearize([model.size.x - voxel.x as u32, voxel.z as u32 + 1, voxel.y as u32 + 1])
                as usize;

this seems like the right place to flip the x axis, as this is where the Y and Z axes get swapped

.Vox Meshes are imported offset within large blank mesh

In the "basic" example, if you spawn a cube at the same location as a .vox model, it appears that the .vox model is imported within a larger shape, but is positioned at one of the corners of the invisible shape. If you rotate the transform of the .vox mesh, it rotates around the center point of the invisible shape.

Loaded mesh shifted

Light gray voxel is loaded from ".vox" file with Transform::from_translation(Vec3::ZERO). But in fact it located at (1,1,1)
Untitled

Add an example illustrating loading multiple objects from a file

It would be great to add an example load .vox with multiple objects.

Maybe it will be useful for someone:
The firsts mesh: asset_server.load("path/to/vox/name.vox"),
The second mesh: asset_server.load("path/to/vox/name.vox#model1"),
The third mesh: asset_server.load("path/to/vox/name.vox#model2"),

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.