diff --git a/code/integration-and-debugging/wgpu_in_web/src/particle_ink.rs b/code/integration-and-debugging/wgpu_in_web/src/particle_ink.rs index 3ab807afd..6b391d455 100644 --- a/code/integration-and-debugging/wgpu_in_web/src/particle_ink.rs +++ b/code/integration-and-debugging/wgpu_in_web/src/particle_ink.rs @@ -48,14 +48,24 @@ impl ParticleInk { pub fn new(app: &AppSurface, gen: &ParticleGen) -> Self { let particle_count = gen.count as usize; let scale_factor = app.scale_factor; - let tex_size = gen.text_tex.size; + + let surface_size = vec2(app.config.width as f32, app.config.height as f32); + let mut tex_size = vec2( + gen.text_tex.size.width as f32, + gen.text_tex.size.height as f32, + ); + // 如果 tex_size 的 x 或 y 大于 surface_size,则等比缩放 tex_size + if tex_size.x > surface_size.x || tex_size.y > surface_size.y { + let scale_factor = (surface_size.x / tex_size.x).min(surface_size.y / tex_size.y); + tex_size *= scale_factor; + } // 视口位置与大小 let viewport = Vec4::new( - (app.config.width as f32 - tex_size.width as f32) / 2.0, - (app.config.height as f32 - tex_size.height as f32) / 2.0, - tex_size.width as f32, - tex_size.height as f32, + (app.config.width as f32 - tex_size.x as f32) / 2.0, + (app.config.height as f32 - tex_size.y as f32) / 2.0, + tex_size.x, + tex_size.y, ); // 粒子像素尺寸 diff --git a/code/utils/src/lib.rs b/code/utils/src/lib.rs index 8d88b8e50..6e651ee01 100644 --- a/code/utils/src/lib.rs +++ b/code/utils/src/lib.rs @@ -51,7 +51,7 @@ pub(crate) fn application_root_dir() -> String { "/" } } else if host.contains("jinleili.github.io") { - href + String::from("https://jinleili.github.io/learn-wgpu-zh/") } else { String::from("https://cannot.access/") } diff --git a/code/utils/src/load_texture.rs b/code/utils/src/load_texture.rs index 6f7add56d..d6750aff9 100644 --- a/code/utils/src/load_texture.rs +++ b/code/utils/src/load_texture.rs @@ -14,7 +14,6 @@ pub struct AnyTexture { #[cfg(target_arch = "wasm32")] pub async fn get_web_img(img_name: &str) -> Result, reqwest::Error> { - log::info!("super::application_root_dir(): {}", super::application_root_dir()); let url = reqwest::Url::parse(&format!("{}{}", super::application_root_dir(), img_name,)).unwrap(); let data = reqwest::get(url).await?.bytes().await?.to_vec();