use std::f32::consts::PI; use bevy::{ color::palettes::css::{BISQUE, SALMON}, prelude::*, render::{ render_asset::RenderAssetUsages, render_resource::{Extent3d, TextureDimension, TextureFormat}, }, }; use bevy_egui::{ egui::{Slider, Window}, EguiContexts, EguiPlugin, }; use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin}; use bevy_shader_mtoon::{MtoonBundle, MtoonMaterial, MtoonPlugin, MtoonSun, OutlineMode}; fn main() { App::new() .insert_resource(ClearColor(Color::linear_rgb(0.1, 0.1, 0.1))) .add_plugins(( DefaultPlugins.set(ImagePlugin::default_nearest()), EguiPlugin, MtoonPlugin, PanOrbitCameraPlugin, )) .add_systems(Startup, setup) .add_systems(Update, (rotate, ui)) .run(); } fn setup( mut commands: Commands, mut images: ResMut>, mut materials: ResMut>, mut mtoon_materials: ResMut>, mut meshes: ResMut>, ) { commands.spawn(( Camera3dBundle { transform: Transform::from_xyz(0.0, 8.0, 14.0), ..default() }, PanOrbitCamera { focus: Vec3::new(0.0, 1.0, 0.0), ..default() }, )); commands.spawn(( DirectionalLightBundle { directional_light: DirectionalLight { illuminance: 10_000.0, shadows_enabled: true, ..default() }, transform: Transform::from_rotation(Quat::from_rotation_x(-PI / 3.0)), ..default() }, MtoonSun, )); let mtoon_textured = MtoonBundle { mtoon: mtoon_materials.add(MtoonMaterial { base_color_texture: Some(images.add(uv_debug_texture())), outline_width: 0.002, outline_mode: OutlineMode::Screen, ..default() }), ..default() }; let mtoon_plain = MtoonBundle { mtoon: mtoon_materials.add(MtoonMaterial { base_color: BISQUE.into(), shade_factor: SALMON.into(), outline_width: 0.2, outline_mode: OutlineMode::World, ..default() }), ..default() }; let shapes = [ meshes.add(Cuboid::default()), meshes.add(Capsule3d::default()), meshes.add(Torus::default()), meshes.add(Cylinder::default()), meshes.add(Sphere::default()), ]; let num_shapes = shapes.len(); // Spacing between shapes const X_EXTENT: f32 = 10.0; for (i, mesh) in shapes.into_iter().enumerate() { // Texture commands.spawn(( mesh.clone(), mtoon_textured.clone(), SpatialBundle { transform: Transform::from_xyz( -X_EXTENT / 2.0 + i as f32 / (num_shapes - 1) as f32 * X_EXTENT, 1.0, 3.0, ) .with_rotation(Quat::from_rotation_x(-PI / 4.0)), ..default() }, )); // Without texture commands.spawn(( mesh, mtoon_plain.clone(), SpatialBundle { transform: Transform::from_xyz( -X_EXTENT / 2.0 + i as f32 / (num_shapes - 1) as f32 * X_EXTENT, 1.0, -3.0, ) .with_rotation(Quat::from_rotation_x(-PI / 4.0)), ..default() }, )); } // Big shape to test shadows. commands.spawn(( meshes.add(Torus::default()), mtoon_textured.clone(), SpatialBundle { transform: Transform::from_xyz(0.0, 5.0, 0.0).with_scale(Vec3::splat(4.25)), ..default() }, )); // Ground commands.spawn(PbrBundle { material: materials.add(StandardMaterial::default()), mesh: meshes.add(Plane3d::default()), transform: Transform::from_scale(Vec3::splat(30.0)), ..default() }); } fn rotate(time: Res