bevy-single-variable-function-mesh 0.11.0

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

bevy-single-variable-function-mesh

License: MIT/Apache Doc Crate Bevy tracking

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.

License

Licensed under either of these: