From 27f668a914df59b0cb6543f216cdf05a35043344 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Sun, 25 Jul 2021 13:35:52 +0200 Subject: [PATCH] Add the orthographic_pipelined example --- Cargo.toml | 4 ++ examples/3d/orthographic_pipelined.rs | 71 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 examples/3d/orthographic_pipelined.rs diff --git a/Cargo.toml b/Cargo.toml index 476fa13047cc5a..82c1eb3eafb3fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -162,6 +162,10 @@ path = "examples/3d/msaa.rs" name = "orthographic" path = "examples/3d/orthographic.rs" +[[example]] +name = "orthographic_pipelined" +path = "examples/3d/orthographic_pipelined.rs" + [[example]] name = "parenting" path = "examples/3d/parenting.rs" diff --git a/examples/3d/orthographic_pipelined.rs b/examples/3d/orthographic_pipelined.rs new file mode 100644 index 00000000000000..31f80170bb4b09 --- /dev/null +++ b/examples/3d/orthographic_pipelined.rs @@ -0,0 +1,71 @@ +use bevy::{ + ecs::prelude::*, + math::Vec3, + pbr2::{PbrBundle, PointLightBundle, StandardMaterial}, + prelude::{App, Assets, Transform}, + render2::{ + camera::OrthographicCameraBundle, + color::Color, + mesh::{shape, Mesh}, + }, + PipelinedDefaultPlugins, +}; + +fn main() { + App::new() + .add_plugins(PipelinedDefaultPlugins) + .add_startup_system(setup.system()) + .run(); +} + +/// set up a simple 3D scene +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + // set up the camera + let mut camera = OrthographicCameraBundle::new_3d(); + camera.orthographic_projection.scale = 3.0; + camera.transform = Transform::from_xyz(5.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y); + + // camera + commands.spawn_bundle(camera); + + // 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::default() + }); + // cubes + 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(1.5, 0.5, 1.5), + ..Default::default() + }); + 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(1.5, 0.5, -1.5), + ..Default::default() + }); + 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(-1.5, 0.5, 1.5), + ..Default::default() + }); + 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(-1.5, 0.5, -1.5), + ..Default::default() + }); + // light + commands.spawn_bundle(PointLightBundle { + transform: Transform::from_xyz(3.0, 8.0, 5.0), + ..Default::default() + }); +}