-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,575 additions
and
1,301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
},)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
},)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.