//! Loads and renders a glTF file as a scene. use bevy::{pbr::DirectionalLightShadowMap, prelude::*}; use bevy_inspector_egui::quick::WorldInspectorPlugin; use bevy_npr::toon::{ToonBundle, ToonMaterial, ToonShaderPlugin}; use std::f32::consts::{FRAC_PI_4, PI}; fn main() { App::new() .insert_resource(DirectionalLightShadowMap { size: 4096 }) .add_plugins((DefaultPlugins, ToonShaderPlugin)) .add_plugins(WorldInspectorPlugin::new()) .add_systems(PreStartup, setup) .add_systems(PreUpdate, update_materials) .add_systems(Update, animate_light_direction) .run(); } #[derive(Component)] struct GLTFScene; fn setup( mut commands: Commands, mut _standard_materials: ResMut>, mut toon_materials: ResMut>, mut meshes: ResMut>, asset_server: Res, ) { info!("init"); commands.spawn(Camera3dBundle { transform: Transform::from_xyz(3.0, 4.0, 2.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), ..default() }); commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { shadows_enabled: true, ..default() }, ..default() }); commands .spawn(SceneBundle { scene: asset_server.load("models/tuzi.glb#Scene0".to_string()), ..Default::default() }) .insert(GLTFScene); commands.spawn(ToonBundle { mesh: meshes.add(shape::Plane::from_size(50.0).into()), material: toon_materials.add(Color::SILVER.into()), ..default() }); } fn update_materials( mut commands: Commands, mut materials: ResMut>, spheres: Query<(Entity, &Handle, &Name)>, ) { for sphere in spheres.iter() { let (entity, material, name) = sphere; info!( "update_materials, entity: {:?}, material: {:?}, name: {:?}", entity, material, name ); commands .entity(sphere.0) .remove::>(); commands .entity(sphere.0) .insert(materials.add(Color::SILVER.into())); } } fn animate_light_direction( time: Res