12 breaking releases

new 0.15.0 Dec 7, 2024
0.14.0 Jul 19, 2024
0.13.0 Mar 13, 2024
0.12.0 Dec 3, 2023
0.2.0 Dec 26, 2020

#224 in Game dev

Download history 366/week @ 2024-08-17 388/week @ 2024-08-24 370/week @ 2024-08-31 454/week @ 2024-09-07 361/week @ 2024-09-14 484/week @ 2024-09-21 374/week @ 2024-09-28 354/week @ 2024-10-05 380/week @ 2024-10-12 356/week @ 2024-10-19 274/week @ 2024-10-26 241/week @ 2024-11-02 282/week @ 2024-11-09 313/week @ 2024-11-16 169/week @ 2024-11-23 409/week @ 2024-11-30

1,222 downloads per month
Used in optima

MIT license

1.5MB
104 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_plugins(bevy_stl::StlPlugin)
        .add_systems(Startup, setup)
        // ...
        .run();
}

fn setup(commands: Commands, asset_server: Res<AssetServer>, mut materials: ResMut<Assets<StandardMaterial>>) {
    commands.spawn((
        Mesh3d(asset_server.load("disc.stl")),
        MeshMaterial3d(Color::rgb(0.9, 0.4, 0.3).into()),
    ));
}

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

~39–72MB
~1.5M SLoC