2 unstable releases

0.2.0 Jul 5, 2024
0.1.0 Jun 7, 2024

#1025 in Game dev

MIT/Apache

40KB
154 lines

bevy_plane_cut

Maintenance CI crates-io api-docs

A plane cut material for the bevy game engine.

simple example

Install

Install the crate.

cargo add bevy_plane_cut

Usage

Add Plugin to App

use bevy::prelude::*;
fn main() {
    App::new()
        .add_plugins(bevy_plane_cut::PlaneCutPlugin)
        .run();
}

Add Material to Object

use bevy::{
    prelude::*,
    color::palettes::basic,
    pbr::ExtendedMaterial,
};
use bevy_plane_cut::*;

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<PlaneCutMaterial>>) {

    commands.spawn(MaterialMeshBundle {
        mesh: meshes.add(Sphere::new(1.0)),
        material: materials.add(ExtendedMaterial {
            base: StandardMaterial {
                base_color: basic::RED.into(),
                ..default()
            },
            extension: PlaneCutExt {
                plane: Vec4::new(-1.0, 1.0, -2.0, 0.0),
                color: Color::linear_rgb(0.0, 0.0, 0.7),
                shaded: true,
                space: Space::World,
            },
        }),
        ..default()
    });
}

Examples

Run the "simple" example like so:

cargo run --example simple

This will show a red sphere with a light rotating around it and blue plane cut.

  • simple - A red sphere with a plane cut.
  • simple_screenspace - A red sphere with a plane cut in screen space.
  • moving_cut - A red sphere with a plane cut moving in and out.

Not Working Examples

simple_deferred

  • simple_deferred - same as simple but using deferred renderer. NOTE: This one does not look right on my macOS machine.
  • deferred - A red sphere rendered with deferred renderer. This has no plane cut at all and it still does not look right. I'm using macOS, so I'd be curious if it looks correct on other platforms.
  • two_cuts - This is a material that has been extended by PlaneCutExt twice. However, it has a bug. See two_cuts.rs example for more details. PRs welcome!

Compatibility

bevy_plane_cut bevy
0.2 0.14
0.1 0.13

License

This crate is licensed under the MIT License or the Apache License 2.0. The examples are licensed under the CC0 license.

Acknowlegments

Dependencies

~24MB
~455K SLoC