Replies: 4 comments 5 replies
-
This is exactly what I am looking for as well! Any guidance would be nice 😭 |
Beta Was this translation helpful? Give feedback.
-
Would |
Beta Was this translation helpful? Give feedback.
-
following |
Beta Was this translation helpful? Give feedback.
-
Ok I found the sauce: from a search of Make use of CustomEvents Because EventLoopProxy does not implement Send,Sync work around is #[derive(Debug, Clone, Copy)]
pub enum CustomEvent {
Foo,
}
thread_local! {
pub static EVENT_LOOP_PROXY: Mutex<Option<EventLoopProxy<CustomEvent>>> = Mutex::new(None);
}
#[wasm_bindgen(js_name = "fireFoo")]
pub fn fire_foo() {
EVENT_LOOP_PROXY.with(|proxy| {
if let Some(event_loop_proxy) = &*proxy.lock().unwrap() {
event_loop_proxy.send_event(CustomEvent::Foo).ok();
}
});
}
#[wasm_bindgen]
pub fn run() {
console_log::init_with_level(log::Level::Debug).expect("error initializing logger");
let event_loop: EventLoop<CustomEvent> =
EventLoopBuilder::<CustomEvent>::with_user_event().build();
let window = WindowBuilder::new()
.with_title("A fantastic window!")
.build(&event_loop)
.unwrap();
let event_loop_proxy = event_loop.create_proxy();
EVENT_LOOP_PROXY.with(move |proxy| {
*proxy.lock().unwrap() = Some(event_loop_proxy);
});
// Don't actually need spawn
event_loop.run(move |event, _, control_flow| {
...
};
} Then in typescript import init, { fireFoo} from "your-wasm"
onClick(() => fireFoo()) |
Beta Was this translation helpful? Give feedback.
-
I'm looking to make a little demo that lets you create noise textures in the browser using wgpu. The page would have form inputs that would allow you to set the seed, number of octaves, and lacunarity as well as a button to tell the wgpu code to update the canvas.
While I know how to get a winit window working in WASM, currently this method requires me running
EventLoop::run
which never returns. I want to return a control struct to the caller so that the js code can update the internal state of the wgpu code.How do I start the event loop while still returning an interface for the js code to use to update things?
Beta Was this translation helpful? Give feedback.
All reactions