Skip to content

Commit

Permalink
wgpu_engine is now a framework
Browse files Browse the repository at this point in the history
+ create assets_gui binary
  • Loading branch information
Uriopass committed Aug 19, 2023
1 parent eb55a90 commit 3aa2679
Show file tree
Hide file tree
Showing 31 changed files with 1,142 additions and 1,051 deletions.
68 changes: 22 additions & 46 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"assets_gui",
"common",
"egregoria",
"egui-inspect",
Expand All @@ -16,12 +17,13 @@ resolver = "2"
default-members = ["native_app"]

[workspace.dependencies]
egui = "0.22.0"
flat_spatial = "0.6"
egui-wgpu = "0.22.0"
egui_extras = "0.22.0"
egui-winit = { version = "0.22.0", default-features = false }
egui = "0.22.0"
flat_spatial = "0.6"
egui_extras = "0.22.0"
egui-winit = { version = "0.22.0", default-features = false }
ordered-float = { version = "3.4.0", default-features = false }
winit = "0.28.6"
oddio = "0.6.2"

# Set the settings for build scripts and proc-macros.
[profile.dev.build-override]
Expand Down
12 changes: 12 additions & 0 deletions assets_gui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "assets_gui"
version = "0.1.0"
edition = "2021"

[dependencies]
common = { path = "../common" }
geom = { path = "../geom" }
wgpu_engine = { path = "../wgpu_engine" }
log = { version = "0.4.11", features=["max_level_info", "release_max_level_info"] }
beul = "1.0"
inline_tweak = "1.0.8"
156 changes: 156 additions & 0 deletions assets_gui/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
use geom::{vec3, Camera, InfiniteFrustrum, LinearColor, Matrix4, Plane, Radians, Vec2, Vec3};
use wgpu_engine::{Context, FrameContext, GfxContext, KeyCode, MouseButton};

struct State {
is_captured: bool,

camera: Camera,
}

impl wgpu_engine::framework::State for State {
fn new(ctx: &mut Context) -> Self {
let gfx = &mut ctx.gfx;

gfx.render_params.value_mut().shadow_mapping_resolution = 2048;
gfx.sun_shadowmap = GfxContext::mk_shadowmap(&gfx.device, 2048);
gfx.update_simplelit_bg();

let mut camera = Camera::new(vec3(9.0, -30.0, 13.0), 1000.0, 1000.0);
camera.dist = 0.0;
camera.pitch = Radians(0.0);
camera.yaw = Radians(-std::f32::consts::PI / 2.0);

Self {
camera,
is_captured: false,
}
}

fn update(&mut self, ctx: &mut Context) {
if ctx.input.mouse.pressed.contains(&MouseButton::Left) {
let _ = ctx
.window
.set_cursor_grab(wgpu_engine::CursorGrabMode::Confined);
ctx.window.set_cursor_visible(false);
self.is_captured = true;
}

if ctx.input.cursor_left {
let _ = ctx
.window
.set_cursor_grab(wgpu_engine::CursorGrabMode::None);
ctx.window.set_cursor_visible(true);
self.is_captured = false;
}

if ctx.input.keyboard.pressed.contains(&KeyCode::Escape) {
let _ = ctx
.window
.set_cursor_grab(wgpu_engine::CursorGrabMode::None);
ctx.window.set_cursor_visible(true);
self.is_captured = false;
}

let delta = ctx.delta;
let cam_speed = if ctx.input.keyboard.pressed_scancode.contains(&42) {
3.0
} else {
30.0
} * delta;

if ctx.input.keyboard.pressed_scancode.contains(&17) {
self.camera.pos -= self
.camera
.dir()
.xy()
.z0()
.try_normalize()
.unwrap_or(Vec3::ZERO)
* cam_speed;
}
if ctx.input.keyboard.pressed_scancode.contains(&31) {
self.camera.pos += self
.camera
.dir()
.xy()
.z0()
.try_normalize()
.unwrap_or(Vec3::ZERO)
* cam_speed;
}
if ctx.input.keyboard.pressed_scancode.contains(&30) {
self.camera.pos += self
.camera
.dir()
.perp_up()
.try_normalize()
.unwrap_or(Vec3::ZERO)
* cam_speed;
}
if ctx.input.keyboard.pressed_scancode.contains(&32) {
self.camera.pos -= self
.camera
.dir()
.perp_up()
.try_normalize()
.unwrap_or(Vec3::ZERO)
* cam_speed;
}
if ctx.input.keyboard.pressed_scancode.contains(&57) {
self.camera.pos += vec3(0.0, 0.0, 1.0) * cam_speed;
}
if ctx.input.keyboard.pressed_scancode.contains(&29) {
self.camera.pos -= vec3(0.0, 0.0, 1.0) * cam_speed;
}

if self.is_captured {
let delta = ctx.input.mouse.screen_delta;

self.camera.yaw.0 -= 0.001 * delta.x;
self.camera.pitch.0 += 0.001 * delta.y;
self.camera.pitch.0 = self.camera.pitch.0.clamp(-1.5, 1.5);
}

let sun = vec3(1.0, -1.0, 1.0).normalize();

let gfx = &mut ctx.gfx;

let viewproj = self.camera.build_view_projection_matrix();
let inv_viewproj = viewproj.invert().unwrap_or_else(Matrix4::zero);
gfx.set_proj(viewproj);
gfx.set_inv_proj(inv_viewproj);

let params = gfx.render_params.value_mut();
params.time_always = (params.time_always + delta) % 3600.0;
params.sun_col = sun.z.max(0.0).sqrt().sqrt()
* LinearColor::new(1.0, 0.95 + sun.z * 0.05, 0.95 + sun.z * 0.05, 1.0);
params.cam_pos = self.camera.eye();
params.cam_dir = self.camera.dir();
params.sun = sun;
params.viewport = Vec2::new(gfx.size.0 as f32, gfx.size.1 as f32);
self.camera.dist = 300.0;
params.sun_shadow_proj = self
.camera
.build_sun_shadowmap_matrix(
sun,
params.shadow_mapping_resolution as f32,
&InfiniteFrustrum::new([Plane::X; 5]),
)
.try_into()
.unwrap();
self.camera.dist = 0.0;
params.shadow_mapping_resolution = 2048;
}

fn render(&mut self, _fc: &mut FrameContext) {}

fn resized(&mut self, _ctx: &mut Context, size: (u32, u32)) {
self.camera.set_viewport(size.0 as f32, size.1 as f32);
}
}

fn main() {
common::logger::MyLog::init();

wgpu_engine::framework::start::<State>();
}
Loading

0 comments on commit 3aa2679

Please sign in to comment.