#mesh #mesh-generation #bevy #f32 #graphics #2d-3d #generate

bevy-single-variable-function-mesh

A 2D or 3D mesh (bevy::render::mesh::Mesh) generated from a single-variable function f(f32) -> f32

8 unstable releases (3 breaking)

new 0.13.0 Mar 20, 2024
0.12.0 Nov 4, 2023
0.11.0 Aug 10, 2023
0.2.5 Jul 25, 2023
0.2.1 Dec 27, 2022

#42 in Rendering

Download history 15/week @ 2024-02-19 4/week @ 2024-02-26 1/week @ 2024-03-11 155/week @ 2024-03-18

161 downloads per month

MIT/Apache

235KB
247 lines

bevy-single-variable-function-mesh

License: MIT/Apache Doc Crate

A 2D or 3D mesh (bevy::render::mesh::Mesh) generated from a single-variable function f(f32) -> f32.

Examples

We have one math function that generates a half squircle and one that generates a half circle.

fn squircle(x: f32) -> f32 {
    (1.0 - (x).abs().powf(4.0)).powf(0.25)
}

fn circle(x: f32) -> f32 {
    (1.0 - x.powf(2.0)).powf(0.5)
}
commands.spawn(PbrBundle {
    mesh: meshes.add(
        SingleVariableFunctionMesh {
            f: squircle, // or circle
            relative_height: 0.0,
            ..default()
        }
        .into(),
    ),
    material: materials.add(StandardMaterial::default()),
    transform: Transform::from_xyz(-2.5, 1.0, 0.0),
    ..default()
});
commands.spawn(PbrBundle {
    mesh: meshes.add(
        SingleVariableFunctionMesh {
            f: squircle, // or circle
            relative_height: 0.2,
            ..default()
        }
        .into(),
    ),
    material: materials.add(StandardMaterial::default()),
    transform: Transform::from_xyz(0.0, 1.0, 0.0),
    ..default()
});
commands.spawn(PbrBundle {
    mesh: meshes.add(
        SingleVariableFunctionMesh {
            f: squircle, // or circle
            relative_height: 1.0,
            ..default()
        }
        .into(),
    ),
    material: materials.add(StandardMaterial::default()),
    transform: Transform::from_xyz(2.5, 1.0, 0.0),
    ..default()
});

Details

  • Feel free to add ideas to the bug tracker.
  • This crate will automatically search for good vertices by comparing the slopes of the input function called f.
  • The plane in the render scene was created by f: |_x: f32| -> f32 { 20.0 },.

Compatible Bevy Version

bevy bevy-single-variable-function-mesh
0.13 0.13
0.12 0.12
0.11 0.11

License

Licensed under either of these:

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~38–80MB
~1M SLoC