separate positionable render camera
This commit is contained in:
parent
dcab3bbe12
commit
eb51d6711b
|
|
@ -1372,6 +1372,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"bevy",
|
||||
"bevy-inspector-egui",
|
||||
"bevy_egui",
|
||||
"bevy_mod_picking",
|
||||
"bevy_transform_gizmo",
|
||||
]
|
||||
|
|
@ -9961,7 +9962,7 @@ version = "1.6.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"cfg-if 0.1.10",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
|
|
@ -10317,9 +10318,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.84"
|
||||
version = "0.2.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
|
||||
checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"wasm-bindgen-macro",
|
||||
|
|
@ -10327,16 +10328,16 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.84"
|
||||
version = "0.2.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
|
||||
checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.107",
|
||||
"syn 2.0.22",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
|
|
@ -10354,9 +10355,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.84"
|
||||
version = "0.2.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
|
||||
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
|
|
@ -10364,22 +10365,22 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.84"
|
||||
version = "0.2.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
|
||||
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.107",
|
||||
"syn 2.0.22",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.84"
|
||||
version = "0.2.87"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
|
||||
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-streams"
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ bevy = "0.10.1"
|
|||
bevy_transform_gizmo = "0.7"
|
||||
bevy_mod_picking = { version = "0.13", features=["backend_raycast"]}
|
||||
bevy-inspector-egui = {version = "0.18.3", features=["highlight_changes"]}
|
||||
bevy_egui = { version = "0.20.3", default-features=false, features=["default_fonts"]}
|
||||
|
||||
#[profile.release]
|
||||
#opt-level = "z"
|
||||
#lto = "fat"
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
lto = "fat"
|
||||
codegen-units = 1
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,5 +1,14 @@
|
|||
<html>
|
||||
<head>
|
||||
<link data-trunk rel="copy-dir" href="assets"/>
|
||||
<!-- make the canvas full height -->
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<!-- disable right click (redirect it to the app) -->
|
||||
<body oncontextmenu="return false;">
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -1,19 +1,38 @@
|
|||
use bevy::render::camera::RenderTarget;
|
||||
use bevy::render::render_resource::{TextureUsages, TextureFormat, TextureDimension, Extent3d, TextureDescriptor};
|
||||
use bevy::window::CursorGrabMode;
|
||||
use bevy::{input::mouse::MouseMotion, prelude::*};
|
||||
use bevy_mod_picking::prelude::RaycastPickCamera;
|
||||
use bevy_transform_gizmo::GizmoTransformable;
|
||||
|
||||
use std::f32::consts::*;
|
||||
use std::fmt;
|
||||
|
||||
pub(crate) const RADIANS_PER_DOT: f32 = 1.0 / 180.0;
|
||||
|
||||
const RENDER_WIDTH: u32 = 1920;
|
||||
const RENDER_HEIGHT: u32 = 1080;
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct RenderCam;
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct ViewportCam;
|
||||
|
||||
pub(crate) fn camera_setup(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut images: ResMut<Assets<Image>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
commands.spawn((
|
||||
// viewport camera
|
||||
commands.spawn(((
|
||||
Camera3dBundle {
|
||||
transform: Transform::from_xyz(0.3, 2.0, 5.0).looking_at(Vec3::new(0.0, 1.0, 0.0), Vec3::Y),
|
||||
camera: Camera {
|
||||
order: 0,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
},
|
||||
EnvironmentMapLight {
|
||||
|
|
@ -23,7 +42,70 @@ pub(crate) fn camera_setup(
|
|||
RaycastPickCamera::default(),
|
||||
bevy_transform_gizmo::GizmoPickSource::default(),
|
||||
CameraController::default(),
|
||||
));
|
||||
), ViewportCam));
|
||||
|
||||
|
||||
|
||||
// render cam
|
||||
|
||||
|
||||
let output_texture_handle = {
|
||||
let size = Extent3d {
|
||||
width: RENDER_WIDTH,
|
||||
height: RENDER_HEIGHT,
|
||||
..default()
|
||||
};
|
||||
let mut export_texture = Image {
|
||||
texture_descriptor: TextureDescriptor {
|
||||
label: None,
|
||||
size,
|
||||
dimension: TextureDimension::D2,
|
||||
format: TextureFormat::Rgba8UnormSrgb,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
usage: TextureUsages::COPY_DST
|
||||
| TextureUsages::COPY_SRC
|
||||
| TextureUsages::RENDER_ATTACHMENT,
|
||||
view_formats: &[],
|
||||
},
|
||||
..default()
|
||||
};
|
||||
export_texture.resize(size);
|
||||
images.add(export_texture)
|
||||
};
|
||||
|
||||
|
||||
let camera_proxy_mesh = asset_server.load("cameraProxy.glb#Mesh0/Primitive0");
|
||||
let camera_proxy_mat = materials.add(StandardMaterial {
|
||||
base_color: Color::BLACK,
|
||||
..default()
|
||||
});
|
||||
commands.spawn(((MaterialMeshBundle::<StandardMaterial> {
|
||||
mesh: camera_proxy_mesh,
|
||||
material: camera_proxy_mat,
|
||||
transform: Transform::from_xyz(0.0, 2.0, 5.0)
|
||||
.with_rotation(Quat::from_rotation_x(TAU/2.0))
|
||||
.with_scale(Vec3::new(0.2, 0.2, 0.2)),
|
||||
..default()
|
||||
}), GizmoTransformable))
|
||||
.with_children(|parent| {
|
||||
parent.spawn(((
|
||||
Camera3dBundle {
|
||||
transform: Transform::from_xyz(0.0, 0.0, 2.0).with_rotation(Quat::from_rotation_x(TAU/2.0)),
|
||||
camera: Camera {
|
||||
order: 1,
|
||||
target: RenderTarget::Image(output_texture_handle.clone()),
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
},
|
||||
EnvironmentMapLight {
|
||||
diffuse_map: asset_server.load("pisa_diffuse_rgb9e5_zstd.ktx2"),
|
||||
specular_map: asset_server.load("pisa_specular_rgb9e5_zstd.ktx2"),
|
||||
},
|
||||
), RenderCam));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
|
|
@ -61,7 +143,7 @@ impl Default for CameraController {
|
|||
key_up: KeyCode::E,
|
||||
key_down: KeyCode::Q,
|
||||
key_run: KeyCode::LShift,
|
||||
mouse_key_enable_mouse: MouseButton::Left,
|
||||
mouse_key_enable_mouse: MouseButton::Right,
|
||||
keyboard_key_enable_mouse: KeyCode::M,
|
||||
walk_speed: 5.0,
|
||||
run_speed: 15.0,
|
||||
|
|
@ -206,3 +288,12 @@ fn camera_controller(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct SnapToRenderCam;
|
||||
|
||||
pub(crate) fn snap_to_render_cam(mut viewport_query: Query<&mut Transform, (With<ViewportCam>, Without<RenderCam>)>, mut render_query: Query<&GlobalTransform, (With<RenderCam>, Without<ViewportCam>)>) {
|
||||
let view_tran: &mut Transform = &mut viewport_query.get_single_mut().unwrap();
|
||||
let rend_tran: &GlobalTransform = render_query.get_single_mut().unwrap();
|
||||
*view_tran = (*rend_tran).into();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use bevy::{
|
||||
prelude::*,
|
||||
prelude::*, window::{PresentMode, WindowMode},
|
||||
};
|
||||
|
||||
//use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
||||
|
|
@ -9,22 +9,37 @@ mod skybox;
|
|||
mod camera;
|
||||
mod animation;
|
||||
mod light;
|
||||
mod ui;
|
||||
|
||||
use bevy_mod_picking::{prelude::*, DefaultPickingPlugins};
|
||||
use bevy_transform_gizmo::{TransformGizmoPlugin};
|
||||
use bevy_transform_gizmo::TransformGizmoPlugin;
|
||||
use::bevy_egui::EguiPlugin;
|
||||
|
||||
use gizmo::{make_pickable, gizmo_system, SelectRoot, set_selection};
|
||||
use light::light_setup;
|
||||
use camera::{camera_setup, CameraControllerPlugin};
|
||||
use camera::{camera_setup, snap_to_render_cam, CameraControllerPlugin, SnapToRenderCam};
|
||||
use animation::{animation_setup, animation_system};
|
||||
use skybox::skybox_setup;
|
||||
use ui::ui_system;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
present_mode: PresentMode::AutoNoVsync, // Reduces input lag.
|
||||
fit_canvas_to_parent: true,
|
||||
//mode: WindowMode::Fullscreen,
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.add_plugin(CameraControllerPlugin)
|
||||
.add_plugins(DefaultPickingPlugins.build().disable::<DebugPickingPlugin>().disable::<DefaultHighlightingPlugin>())
|
||||
.add_plugins(DefaultPickingPlugins.build()
|
||||
.disable::<DebugPickingPlugin>()
|
||||
.disable::<DefaultHighlightingPlugin>()
|
||||
)
|
||||
.add_plugin(TransformGizmoPlugin::default())
|
||||
.add_plugin(EguiPlugin)
|
||||
//.add_plugin(WorldInspectorPlugin::new())
|
||||
.add_startup_system(setup)
|
||||
.add_startup_system(light_setup)
|
||||
|
|
@ -35,8 +50,12 @@ fn main() {
|
|||
.add_system(animation_system)
|
||||
.add_system(make_pickable)
|
||||
.add_event::<SelectRoot>()
|
||||
.add_event::<SnapToRenderCam>()
|
||||
.add_system(set_selection.run_if(on_event::<SelectRoot>()))
|
||||
.run();
|
||||
.add_system(ui_system)
|
||||
.add_system(snap_to_render_cam.run_if(on_event::<SnapToRenderCam>()))
|
||||
.run();
|
||||
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
|
|
@ -60,11 +79,9 @@ fn setup(mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<Standard
|
|||
unlit: true,
|
||||
..default()
|
||||
});
|
||||
commands.spawn((MaterialMeshBundle::<StandardMaterial> {
|
||||
commands.spawn(MaterialMeshBundle::<StandardMaterial> {
|
||||
mesh: floor,
|
||||
material: floor_mat,
|
||||
..default()
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_egui::{egui, EguiContexts};
|
||||
use crate::camera::SnapToRenderCam;
|
||||
|
||||
pub(crate) fn ui_system(mut ev: EventWriter::<SnapToRenderCam>, mut contexts: EguiContexts) {
|
||||
egui::Area::new("")
|
||||
.fixed_pos(egui::pos2(5.0, 5.0))
|
||||
.show(contexts.ctx_mut(), |ui| {
|
||||
if ui.button("Snap To Render Camera").clicked() {
|
||||
ev.send(SnapToRenderCam);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue