4 releases

0.2.1 Mar 12, 2023
0.2.0 Mar 12, 2023
0.1.3 Jan 12, 2023
0.1.1 Nov 21, 2022

#38 in Rendering

Download history 2/week @ 2022-12-05 20/week @ 2022-12-12 38/week @ 2022-12-19 6/week @ 2022-12-26 30/week @ 2023-01-02 34/week @ 2023-01-09 7/week @ 2023-01-16 12/week @ 2023-01-23 18/week @ 2023-01-30 50/week @ 2023-02-06 39/week @ 2023-02-13 34/week @ 2023-02-20 16/week @ 2023-02-27 44/week @ 2023-03-06 28/week @ 2023-03-13 17/week @ 2023-03-20

108 downloads per month

MIT license

22KB
218 lines

Bevy Points

crates.io

Points mesh plugin for Bevy.

Example

Usage

System setup

Add the plugin to your app:

use bevy::prelude::*;
use bevy_points::prelude::*;

fn main() {
    App::new()
        .add_plugin(PointsPlugin);
}

Apply a component to a MaterialMeshBundle

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<PointsMaterial>>,
) {
    let n = 320; // # of points
    let h = 3.0; // spiral height
    commands.spawn(MaterialMeshBundle {
        mesh: meshes.add(
            PointsMesh::from_iter((0..n).map(|i| {
                let t01 = (i as f32) / ((n - 1) as f32);
                let r = t01 * TAU * 4.0; // spiral fineness
                Vec3::new(r.cos(), (t01 - 0.5) * h, r.sin())
            }))
            .into(),
        ),
        material: materials.add(PointsMaterial {
            settings: PointsShaderSettings {
                point_size: 20.,    // Defines the size of the points. 
                ..Default::default()
            },
            perspective: true,      // Specify whether points' size is attenuated by the camera depth. 
            circle: true,           // Specify whether the shape of points is circular or rectangular.
            ..Default::default()
        }),
        ..Default::default()
    });

    commands.spawn(MaterialMeshBundle {
        mesh: meshes.add(
            // Mesh can be converted to PointsMesh.
            PointsMesh::from(Mesh::from(shape::Icosphere::default()))
            .into()
        ),
        material: materials.add(PointsMaterial {
            settings: PointsShaderSettings {
                color: Color::BLUE,
                opacity: 0.5,
                ..Default::default()
            },
            alpha_mode: AlphaMode::Blend,
            ..Default::default()
        }),
        ..Default::default()
    });
}

Compatibility

bevy bevy_points
0.9 0.1
0.10 0.2

Dependencies

~22–57MB
~1M SLoC