Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial 6 Questions: WASM view skew and camera controller speed #584

Open
ExpertOfNil opened this issue Dec 21, 2024 · 0 comments
Open

Comments

@ExpertOfNil
Copy link

I just finished "Uniform Buffers and 3D Camera" and noticed 2 things that made me wonder if I had made some mistakes:

  1. When creating the winit window, I use with_inner_size to set the window size to PhysicalSize::new(1920, 1080). After implementing the camera, the native application no longer has a skew due to the aspect ratio. However, the WASM variant still does. For reference, I'm using wasm-pack build --target web with plain HTML. Is this expected? If so, how can I resolve it?

    My canvas setup:

        // ...
    let window = WindowBuilder::new()
        .with_title("insight")
        .with_inner_size(window_size)
        .build(&event_loop)
        .unwrap();
    
    #[cfg(target_arch = "wasm32")]
    {
        use winit::platform::web::WindowExtWebSys;
    
        web_sys::window()
            .and_then(|win| win.document())
            .and_then(|doc| {
                let dst = doc.get_element_by_id("view-canvas")?;
                let canvas = window.canvas()?;
                //canvas.set_width(size.width);
                //canvas.set_height(size.height);
                //let canvas = web_sys::Element::from(window.canvas()?);
                let canvas_element = canvas.into();
                dst.append_child(&canvas_element).ok()?;
                Some(())
            })
            .expect("Couldn't append canvas to document body.");
    
        if window.request_inner_size(window_size).is_none() {
            log::error!("Window size request returned None");
        };
    }
    // ...

    My index.html:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Learn WGPU</title>
        <style>
            * {
                margin:0px;
                padding:0px;
            }
            body {
                width: 100%;
                height: 100%;
            }
            canvas {
                background-color: black;
                display: block;
            }
        </style>
    </head>
    
    <body id="view-canvas">
          <script type="module">
              import init from "./pkg/insight.js";
              init().then(() => {
                  console.log("WASM Loaded");
              });
          </script>
    </body>
    
    </html>
  2. The CameraController speed is way faster on the native build. Is this simply due to a much faster update cycle?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant