new rendering framework
This commit is contained in:
parent
313dca0483
commit
1d5d1f627d
|
@ -22,6 +22,7 @@ wasm-logger = "0.2"
|
||||||
serde-wasm-bindgen = "0.6"
|
serde-wasm-bindgen = "0.6"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
itertools = "0.11"
|
itertools = "0.11"
|
||||||
|
winit = "0.29"
|
||||||
|
|
||||||
[dependencies.js-sys]
|
[dependencies.js-sys]
|
||||||
version = "0.3"
|
version = "0.3"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use web_sys::FileReader;
|
use web_sys::FileReader;
|
||||||
use crate::loadar2;
|
use crate::loadar2;
|
||||||
use crate::mode::Mode;
|
use crate::mode::Mode;
|
||||||
use crate::rendering::render;
|
|
||||||
use crate::scope::ScopeState;
|
use crate::scope::ScopeState;
|
||||||
|
|
||||||
pub fn should_newline(state: &mut ScopeState) -> bool {
|
pub fn should_newline(state: &mut ScopeState) -> bool {
|
||||||
|
@ -16,7 +15,6 @@ pub fn exec(state: &mut ScopeState, command: String) {
|
||||||
} else if command == "CLF RELOAD" {
|
} else if command == "CLF RELOAD" {
|
||||||
state.command_buf = "SYSTEM PROCESSING".to_string();
|
state.command_buf = "SYSTEM PROCESSING".to_string();
|
||||||
state.command_buf_response_mode = true;
|
state.command_buf_response_mode = true;
|
||||||
render(state).expect("rerender failed");
|
|
||||||
loadar2("file");
|
loadar2("file");
|
||||||
} else if command.starts_with("MODE SET") {
|
} else if command.starts_with("MODE SET") {
|
||||||
if tokens.len() < 3 {
|
if tokens.len() < 3 {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod rendering;
|
|
||||||
pub mod mode;
|
pub mod mode;
|
||||||
pub mod scope;
|
pub mod scope;
|
||||||
pub mod equirectangular;
|
pub mod equirectangular;
|
||||||
|
@ -14,6 +13,10 @@ use js_sys::Uint8Array;
|
||||||
use log::info;
|
use log::info;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
|
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
|
||||||
|
use winit::dpi::PhysicalSize;
|
||||||
|
use winit::event_loop::EventLoop;
|
||||||
|
use winit::window::WindowBuilder;
|
||||||
|
use winit::platform::web::WindowExtWebSys;
|
||||||
use crate::command::{exec, should_newline};
|
use crate::command::{exec, should_newline};
|
||||||
use crate::mode::Mode;
|
use crate::mode::Mode;
|
||||||
use crate::mode::Mode::Reflectivity;
|
use crate::mode::Mode::Reflectivity;
|
||||||
|
@ -33,15 +36,26 @@ pub fn __nxrd_browser_init() -> AbiScopeState {
|
||||||
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
||||||
utils::set_panic_hook();
|
utils::set_panic_hook();
|
||||||
|
|
||||||
|
info!("wgpu setup");
|
||||||
|
|
||||||
|
let event_loop = EventLoop::new().expect("event loop creation failed");
|
||||||
|
let window = WindowBuilder::new().build(&event_loop).unwrap();
|
||||||
|
|
||||||
|
window.set_min_inner_size(Some(PhysicalSize::new(450, 400)));
|
||||||
|
|
||||||
|
web_sys::window()
|
||||||
|
.and_then(|win| win.document())
|
||||||
|
.and_then(|doc| {
|
||||||
|
let dst = doc.get_element_by_id("wasm-example")?;
|
||||||
|
let canvas = web_sys::Element::from(window.canvas().unwrap());
|
||||||
|
dst.append_child(&canvas).ok()?;
|
||||||
|
Some(())
|
||||||
|
})
|
||||||
|
.expect("Couldn't append canvas to document body.");
|
||||||
|
|
||||||
info!("initializing the scope");
|
info!("initializing the scope");
|
||||||
|
|
||||||
info!("finding canvas element");
|
|
||||||
|
|
||||||
let document = web_sys::window().expect("window should exist").document().expect("document should exist");
|
let document = web_sys::window().expect("window should exist").document().expect("document should exist");
|
||||||
let canvas = document.get_element_by_id("canvas").expect("canvas element should exist");
|
|
||||||
|
|
||||||
let canvas: web_sys::HtmlCanvasElement = canvas.dyn_into::<web_sys::HtmlCanvasElement>().map_err(|_| ()).expect("canvas is not a canvas");
|
|
||||||
let context = canvas.get_context("2d").expect("failed to get canvas rendering context").expect("canvas rendering context doesn't exist").dyn_into::<web_sys::CanvasRenderingContext2d>().map_err(|_| ()).expect("2d context is not a 2d context");
|
|
||||||
|
|
||||||
info!("finding form input element");
|
info!("finding form input element");
|
||||||
|
|
||||||
|
@ -51,10 +65,6 @@ pub fn __nxrd_browser_init() -> AbiScopeState {
|
||||||
let scope_state = ScopeState {
|
let scope_state = ScopeState {
|
||||||
ar2: None,
|
ar2: None,
|
||||||
scope_mode: Mode::RadarInoperative,
|
scope_mode: Mode::RadarInoperative,
|
||||||
render_state: RenderState {
|
|
||||||
canvas,
|
|
||||||
context
|
|
||||||
},
|
|
||||||
file_input: file,
|
file_input: file,
|
||||||
lat: 30.48500, // jacksonville
|
lat: 30.48500, // jacksonville
|
||||||
long: -81.70200, // jacksonville
|
long: -81.70200, // jacksonville
|
||||||
|
@ -72,12 +82,14 @@ pub fn __nxrd_browser_init() -> AbiScopeState {
|
||||||
|
|
||||||
AbiScopeState(scope_state)
|
AbiScopeState(scope_state)
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn render_abi(state: &mut AbiScopeState) {
|
pub fn render_abi(state: &mut AbiScopeState) {
|
||||||
rendering::render(&mut state.0).unwrap()
|
old_rendering::render(&mut state.0).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn load_ar2(buf: &JsValue, scope: &mut AbiScopeState) {
|
pub fn load_ar2(buf: &JsValue, scope: &mut AbiScopeState) {
|
||||||
let array = Uint8Array::new(buf);
|
let array = Uint8Array::new(buf);
|
||||||
|
|
|
@ -5,7 +5,6 @@ use crate::mode::Mode;
|
||||||
pub struct ScopeState {
|
pub struct ScopeState {
|
||||||
pub ar2: Option<Nexrad2Chunk>,
|
pub ar2: Option<Nexrad2Chunk>,
|
||||||
pub scope_mode: Mode,
|
pub scope_mode: Mode,
|
||||||
pub render_state: RenderState,
|
|
||||||
pub file_input: HtmlInputElement,
|
pub file_input: HtmlInputElement,
|
||||||
pub lat: f64,
|
pub lat: f64,
|
||||||
pub long: f64,
|
pub long: f64,
|
||||||
|
|
|
@ -16,10 +16,6 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<canvas id="canvas">
|
|
||||||
Something went wrong while loading the canvas. Sorry :/
|
|
||||||
</canvas>
|
|
||||||
|
|
||||||
<input type="file" id="file" style="display: none;" />
|
<input type="file" id="file" style="display: none;" />
|
||||||
|
|
||||||
<script src="bootstrap.js"></script>
|
<script src="bootstrap.js"></script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as wasm from "./wasm/nexrad_browser.js";
|
import * as wasm from "./wasm/nexrad_browser.js";
|
||||||
await wasm.default();
|
await wasm.default();
|
||||||
let global_context = wasm.__nxrd_browser_init();
|
let global_context = wasm.__nxrd_browser_init();
|
||||||
|
/*
|
||||||
function rescaleCanvas(canvas, ctx) {
|
function rescaleCanvas(canvas, ctx) {
|
||||||
var dpr = window.devicePixelRatio || 1;
|
var dpr = window.devicePixelRatio || 1;
|
||||||
// Get the size of the canvas in CSS pixels.
|
// Get the size of the canvas in CSS pixels.
|
||||||
|
@ -41,3 +41,5 @@ document.getElementById("file").onchange = () => {
|
||||||
let render = () => { wasm.render_abi(global_context); requestAnimationFrame(render); }
|
let render = () => { wasm.render_abi(global_context); requestAnimationFrame(render); }
|
||||||
|
|
||||||
requestAnimationFrame(render);
|
requestAnimationFrame(render);
|
||||||
|
|
||||||
|
*/
|
Loading…
Reference in New Issue