#bevy #stl

bevy_stl

STL loader for bevy, based on stl_io

10 releases (breaking)

0.8.0 Mar 23, 2023
0.7.0 Nov 26, 2022
0.5.0 Apr 22, 2022
0.4.0 Jan 28, 2022
0.2.0 Dec 26, 2020

#103 in Game dev

Download history 321/week @ 2023-02-17 525/week @ 2023-02-24 625/week @ 2023-03-03 761/week @ 2023-03-10 912/week @ 2023-03-17 926/week @ 2023-03-24 521/week @ 2023-03-31 580/week @ 2023-04-07 741/week @ 2023-04-14 965/week @ 2023-04-21 732/week @ 2023-04-28 1051/week @ 2023-05-05 998/week @ 2023-05-12 905/week @ 2023-05-19 1126/week @ 2023-05-26 889/week @ 2023-06-02

4,084 downloads per month
Used in optima

MIT license

135KB
101 lines

bevy_stl

Crate version

Crate license

A STL loader for bevy.

STL is a very simple format, which supports only triangular geometry (positions + normals), without any color / uv / texture information.

It is supported as an output format by most CAD software.

Alternatives

  • by default bevy can load glTF scenes, which is a much better choice if you are looking for a way to load more complex models / scenes, including materials, animations, etc.
  • bevy_obj can load Wavefront .obj files, which can carry more information than STL (such as color, material, UV coordinates)

Usage

  1. Add bevy_stl to your Cargo.toml
  2. Add bevy_stl::StlPlugin plugin to the bevy App
  3. Load STL assets by passing paths with ".stl" extension to asset_server.load(..)

Example

fn main() {
    App::new()
        .add_plugin(bevy_stl::StlPlugin)
        .add_startup_system(setup)
        // ...
        .run();
}

fn setup(commands: &mut Commands, asset_server: Res<AssetServer>, mut materials: ResMut<Assets<StandardMaterial>>) {
    commands
        .spawn(PbrBundle {
            mesh: asset_server.load("disc.stl"),
            material: materials.add(Color::rgb(0.9, 0.4, 0.3).into()),
            ..Default::default()
        })
        // ...
}

You can find a more complete example in examples/spinning_disc.rs - use cargo run --example spinning_disc --release to run it.

Optional Features

Wireframe

By default bevy_stl produces a triangle mesh (PrimitiveTopology::TriangleList). When the optional wireframe feature is enabled, an additional line mesh is produced (PrimitiveTopology::LineList).

The feature can be enabled via Cargo.toml:

[dependencies.bevy_stl]
features = ["wireframe"]

When enabled, the mesh can be accessed by appending the wireframe label to the path passed to the asset loader:

  // This returns the triangle mesh (the default):
  asset_server.load("disc.stl")

  // This returns the wireframe mesh:
  asset_server.load("disc.stl#wireframe")

Dependencies

~21–58MB
~1M SLoC