From ba71a21565706ebbc4480ba7650dab2d12c3af8e Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Sat, 26 Mar 2022 09:37:09 +0000 Subject: [PATCH] Actually do some rendering for testing --- examples/window/expanding_window.rs | 52 ++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/examples/window/expanding_window.rs b/examples/window/expanding_window.rs index 968039c3480d0e..9b9e12481d9542 100644 --- a/examples/window/expanding_window.rs +++ b/examples/window/expanding_window.rs @@ -18,10 +18,6 @@ fn main() { .run(); } -fn setup(mut commands: Commands) { - commands.spawn_bundle(OrthographicCameraBundle::new_3d()); -} - enum Phase { ContractingY, ContractingX, @@ -31,7 +27,17 @@ enum Phase { use Phase::*; -fn change_window_size(mut windows: ResMut, mut phase: ResMut) { +fn change_window_size( + mut windows: ResMut, + mut phase: ResMut, + mut first_complete: Local, +) { + // Put off rendering for one frame, as currently for a frame where + // resizing happens, nothing is presented. + if !*first_complete { + *first_complete = true; + return; + } let primary = windows.get_primary_mut().unwrap(); let height = primary.height(); let width = primary.width(); @@ -62,3 +68,39 @@ fn change_window_size(mut windows: ResMut, mut phase: ResMut) { } } } + +/// A simple 3d scene, taken from the `3d_scene` example +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + // plane + commands.spawn_bundle(PbrBundle { + mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), + material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + ..default() + }); + // cube + commands.spawn_bundle(PbrBundle { + mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + transform: Transform::from_xyz(0.0, 0.5, 0.0), + ..default() + }); + // light + commands.spawn_bundle(PointLightBundle { + point_light: PointLight { + intensity: 1500.0, + shadows_enabled: true, + ..default() + }, + transform: Transform::from_xyz(4.0, 8.0, 4.0), + ..default() + }); + // camera + commands.spawn_bundle(PerspectiveCameraBundle { + transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + }); +}