Skip to content

Commit

Permalink
reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
aevyrie committed Jan 23, 2024
1 parent 49303fb commit 73498d6
Show file tree
Hide file tree
Showing 20 changed files with 1,575 additions and 1,301 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ bevy = { version = "0.12.1", default-features = false, features = [
bevy_mod_picking = { version = "0.17", default-features = false, features = [
"backend_raycast",
] }
bevy_framepace = "0.14"
63 changes: 29 additions & 34 deletions examples/demo.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use bevy::{
core_pipeline::{bloom::BloomSettings, fxaa::Fxaa, tonemapping::Tonemapping},
core_pipeline::{
bloom::BloomSettings,
experimental::taa::{TemporalAntiAliasBundle, TemporalAntiAliasPlugin},
tonemapping::Tonemapping,
},
pbr::ScreenSpaceAmbientOcclusionSettings,
prelude::*,
};
use bevy_editor_cam::{prelude::*, skybox::SkyboxCamConfig};
use bevy_editor_cam::prelude::*;

fn main() {
App::new()
.add_plugins((
DefaultPlugins,
bevy_mod_picking::DefaultPickingPlugins,
EditorCamPlugin,
TemporalAntiAliasPlugin,
))
// The camera controller works with reactive rendering:
.insert_resource(bevy::winit::WinitSettings::desktop_app())
Expand All @@ -19,56 +24,46 @@ fn main() {
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let scene = asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0");
let width = -1..=1;
for x in width.clone() {
for y in width.clone() {
for z in width.clone() {
commands.spawn((SceneBundle {
scene: scene.clone(),
transform: Transform::from_translation(IVec3::new(x, y, z).as_vec3() * 2.0)
.with_scale(Vec3::splat(1.)),
..default()
},));
}
}
}

spawn_helmets(27, &asset_server, &mut commands);
let diffuse_map = asset_server.load("environment_maps/diffuse_rgb9e5_zstd.ktx2");
let specular_map = asset_server.load("environment_maps/specular_rgb9e5_zstd.ktx2");

commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(-0.96555597, 0.3487206, 0.75903153).with_rotation(
Quat::from_array([-0.015417562, -0.45619124, -0.007905196, 0.8897131]),
),
camera: Camera {
hdr: true,
order: 1,
..default()
},
camera_3d: Camera3d {
clear_color: bevy::core_pipeline::clear_color::ClearColorConfig::None,
..default()
},
transform: Transform::from_xyz(10.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
tonemapping: Tonemapping::AcesFitted,
..default()
},
TemporalAntiAliasBundle::default(),
BloomSettings::default(),
ScreenSpaceAmbientOcclusionSettings::default(),
EnvironmentMapLight {
diffuse_map: diffuse_map.clone(),
specular_map: specular_map.clone(),
},
Fxaa::default(),
EditorCam {
orbit: OrbitKind::Constrained(Vec3::Y), // Try OrbitKind::Free,
smoothness: Smoothness::default(),
sensitivity: Sensitivity::default(),
momentum: Momentum::default(),
last_anchor_depth: 2.0,
..Default::default()
},
SkyboxCamConfig::new(diffuse_map),
bevy_editor_cam::extensions::skybox::SkyboxCamera::new(diffuse_map),
));
}

fn spawn_helmets(n: usize, asset_server: &AssetServer, commands: &mut Commands) {
let half_width = (((n as f32).powf(1.0 / 3.0) - 1.0) / 2.0) as i32;
let scene = asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0");
let width = -half_width..=half_width;
for x in width.clone() {
for y in width.clone() {
for z in width.clone() {
commands.spawn((SceneBundle {
scene: scene.clone(),
transform: Transform::from_translation(IVec3::new(x, y, z).as_vec3() * 2.0)
.with_scale(Vec3::splat(1.)),
..default()
},));
}
}
}
}
39 changes: 20 additions & 19 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ fn main() {
App::new()
.add_plugins((
DefaultPlugins,
bevy_mod_picking::DefaultPickingPlugins,
EditorCamPlugin,
bevy_mod_picking::DefaultPickingPlugins, // Prerequisite: Use picking plugin
EditorCamPlugin, // Step 1: Add camera controller plugin
))
.add_systems(Startup, setup)
.add_systems(Startup, (setup_camera, setup_scene))
.run()
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn((SceneBundle {
scene: asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0"),
..default()
},));
fn setup_camera(mut commands: Commands) {
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.4, 1.5),
..default()
},
EditorCam::default(),
// Skybox and lighting:
EnvironmentMapLight {
diffuse_map: asset_server.load("environment_maps/diffuse_rgb9e5_zstd.ktx2"),
specular_map: asset_server.load("environment_maps/specular_rgb9e5_zstd.ktx2"),
},
bevy::core_pipeline::Skybox(asset_server.load("environment_maps/diffuse_rgb9e5_zstd.ktx2")),
Camera3dBundle::default(),
EditorCam::default(), // Step 2: add camera controller component to any cameras
));
}

// --- The below code is not important for the example ---

fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(1.0, 1.0, 0.0),
..Default::default()
});
commands.spawn(SceneBundle {
scene: asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0"),
transform: Transform::from_xyz(0.0, -0.5, -2.0),
..Default::default()
});
}
73 changes: 73 additions & 0 deletions examples/ortho.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use bevy::prelude::*;
use bevy_editor_cam::prelude::*;

fn main() {
App::new()
.add_plugins((
DefaultPlugins,
bevy_mod_picking::DefaultPickingPlugins,
EditorCamPlugin,
))
.add_systems(Startup, setup)
.run()
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
spawn_helmets(27, &asset_server, &mut commands);
let diffuse_map = asset_server.load("environment_maps/diffuse_rgb9e5_zstd.ktx2");
let specular_map = asset_server.load("environment_maps/specular_rgb9e5_zstd.ktx2");

commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(10.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
projection: Projection::Orthographic(OrthographicProjection {
scale: 0.01,
far: 20.0,
..default()
}),
..default()
},
// Skybox and lighting:
EnvironmentMapLight {
diffuse_map: diffuse_map.clone(),
specular_map: specular_map.clone(),
},
// This component makes the camera controllable with this plugin.
//
// Important: the `with_initial_anchor_depth` is critical for an orthographic camera. Unlike
// perspective, we can't rely on distant things being small to hide precision artifacts.
// This means we need to be careful with the near and far plane of the camera, especially
// because in orthographic, the depth precision is linear.
//
// This plugin uses the anchor (the point in space the user is interested in) to set the
// orthographic scale, as well as the near and far planes. This can be a bit tricky if you
// are unfamiliar with orthographic projections. Consider using an pseudo-ortho projection
// (see example) if you don't need a true ortho projection.
EditorCam::default().with_initial_anchor_depth(10.0),
// This is an extension made specifically for orthographic cameras. Because an ortho camera
// projection has no field of view, a skybox can't be sensibly rendered, only a single point
// on the skybox would be visible to the camera at any given time. While this is technically
// correct to what the camera would see, it is not visually helpful nor appealing. It is
// common for CAD software to render a skybox with a field of view that is decoupled from
// the camera field of view.
bevy_editor_cam::extensions::skybox::SkyboxCamera::new(diffuse_map),
));
}

fn spawn_helmets(n: usize, asset_server: &AssetServer, commands: &mut Commands) {
let half_width = (((n as f32).powf(1.0 / 3.0) - 1.0) / 2.0) as i32;
let scene = asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0");
let width = -half_width..=half_width;
for x in width.clone() {
for y in width.clone() {
for z in width.clone() {
commands.spawn((SceneBundle {
scene: scene.clone(),
transform: Transform::from_translation(IVec3::new(x, y, z).as_vec3() * 2.0)
.with_scale(Vec3::splat(1.)),
..default()
},));
}
}
}
}
100 changes: 100 additions & 0 deletions examples/pseudo_ortho.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use bevy::prelude::*;
use bevy_editor_cam::prelude::*;

fn main() {
App::new()
.add_plugins((
DefaultPlugins,
bevy_mod_picking::DefaultPickingPlugins,
bevy::core_pipeline::experimental::taa::TemporalAntiAliasPlugin,
EditorCamPlugin,
))
.add_systems(Startup, setup)
.run()
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
spawn_helmets(27, &asset_server, &mut commands);
let diffuse_map = asset_server.load("environment_maps/diffuse_rgb9e5_zstd.ktx2");
let specular_map = asset_server.load("environment_maps/specular_rgb9e5_zstd.ktx2");

commands
.spawn((
Camera3dBundle {
transform: Transform::from_xyz(10.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
// projection: Projection::Perspective(PerspectiveProjection {
// fov: 0.001,
// ..default()
// }),
projection: Projection::Orthographic(OrthographicProjection {
scale: 0.01,
far: 20.0,
..default()
}),
camera: Camera {
hdr: true,
..Default::default()
},
..default()
},
// Skybox and lighting:
EnvironmentMapLight {
diffuse_map: diffuse_map.clone(),
specular_map: specular_map.clone(),
},
// This component makes the camera controllable with this plugin:
EditorCam::default(),
// This is an extension made specifically for orthographic cameras. Because an ortho
// camera projection has no field of view, a skybox can't be sensibly rendered, only a
// single point on the skybox would be visible to the camera at any given time. While
// this is technically correct to what the camera would see, it is not visually helpful
// nor appealing. It is common for CAD software to render a skybox with a field of view
// that is decoupled from the camera field of view.
bevy_editor_cam::extensions::skybox::SkyboxCamera::new(diffuse_map),
))
.insert(bevy::core_pipeline::experimental::taa::TemporalAntiAliasBundle::default())
.insert(bevy::pbr::ScreenSpaceAmbientOcclusionBundle::default());

commands.add(|world: &mut World| {
let material = world
.resource_mut::<Assets<StandardMaterial>>()
.add(Color::BLUE.into());
let mesh = world.resource_mut::<Assets<Mesh>>().add(
shape::Cylinder {
radius: 0.1,
height: 15.0,
resolution: 32,
segments: 3,
}
.into(),
);
for x in 0..12 {
for z in 0..40 {
world.spawn(PbrBundle {
mesh: mesh.clone(),
material: material.clone(),
transform: Transform::from_xyz(x as f32 * 6.0 + 5.0, 0.0, z as f32 * 7.0 + 5.0),
..Default::default()
});
}
}
});
}

fn spawn_helmets(n: usize, asset_server: &AssetServer, commands: &mut Commands) {
let half_width = (((n as f32).powf(1.0 / 3.0) - 1.0) / 2.0) as i32;
let scene = asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0");
let width = -half_width..=half_width;
for x in width.clone() {
for y in width.clone() {
for z in width.clone() {
commands.spawn((SceneBundle {
scene: scene.clone(),
transform: Transform::from_translation(IVec3::new(x, y, z).as_vec3() * 2.0)
.with_scale(Vec3::splat(1.)),
..default()
},));
}
}
}
}
27 changes: 21 additions & 6 deletions examples/split_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use bevy::{
core_pipeline::clear_color::ClearColorConfig, prelude::*, render::camera::Viewport,
window::WindowResized,
};
use bevy_editor_cam::cam_component::EditorCam;
use bevy_editor_cam::prelude::*;

fn main() {
App::new()
.add_plugins((
DefaultPlugins,
bevy_mod_picking::DefaultPickingPlugins,
bevy_editor_cam::plugin::EditorCamPlugin,
EditorCamPlugin,
))
.add_systems(Startup, setup)
.add_systems(Update, set_camera_viewports)
Expand All @@ -20,10 +20,7 @@ fn main() {

/// set up a simple 3D scene
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(SceneBundle {
scene: asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0"),
..default()
});
spawn_helmets(27, &asset_server, &mut commands);

// Left Camera
commands.spawn((
Expand Down Expand Up @@ -109,3 +106,21 @@ fn set_camera_viewports(
});
}
}

fn spawn_helmets(n: usize, asset_server: &AssetServer, commands: &mut Commands) {
let half_width = (((n as f32).powf(1.0 / 3.0) - 1.0) / 2.0) as i32;
let scene = asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0");
let width = -half_width..=half_width;
for x in width.clone() {
for y in width.clone() {
for z in width.clone() {
commands.spawn((SceneBundle {
scene: scene.clone(),
transform: Transform::from_translation(IVec3::new(x, y, z).as_vec3() * 2.0)
.with_scale(Vec3::splat(1.)),
..default()
},));
}
}
}
}
Loading

0 comments on commit 73498d6

Please sign in to comment.