From a8d7c03139f4deac5f2708b234b75a8e2e89af7e Mon Sep 17 00:00:00 2001 From: pulsareonbot Date: Tue, 7 Jul 2026 16:59:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(renderer):=20=E4=BF=AE=E6=AD=A3=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E4=B8=AD=E7=9A=84=E4=B8=AD=E6=96=87=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E4=BB=A5=E6=8F=90=E9=AB=98=E5=8F=AF=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/live2d/renderer.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/plugins/live2d/renderer.rs b/src/plugins/live2d/renderer.rs index c2608a5..7f833f2 100644 --- a/src/plugins/live2d/renderer.rs +++ b/src/plugins/live2d/renderer.rs @@ -1,4 +1,4 @@ -//! Live2D 渲染器:整合 Core + Model + GL + Animation +//! Live2D 娓叉煋鍣細鏁村悎 Core + Model + GL + Animation use super::animation::AnimationState; use super::assets::{self, Model3Json, TextureImage}; @@ -31,12 +31,12 @@ impl Live2DRenderer { height: i32, ) -> Result { let core = Arc::new(CubismCore::load(core_so_path)?); - println!("[Live2D] Core 版本: {}", core.version_string()); + println!("[Live2D] Core 鐗堟湰: {}", core.version_string()); let paths = assets::resolve_asset_paths(live2d_base_dir, model3_json_rel)?; let model3 = Model3Json::from_path(&paths.model3_json)?; println!( - "[Live2D] model3.json: 版本={} moc={} 纹理?{}", + "[Live2D] model3.json: 鐗堟湰={} moc={} 绾圭悊鏁?{}", model3.version, model3.file_references.moc, model3.file_references.textures.len() @@ -48,7 +48,7 @@ impl Live2DRenderer { let gl_ctx = RenderContext::new_fullscreen(width, height)?; let texture_ids: Vec = textures.iter().map(|t| gl_ctx.create_texture(t)).collect(); - println!("[Live2D] 已上?{} 个纹理到 GPU", texture_ids.len()); + println!("[Live2D] 宸蹭笂浼?{} 涓汗鐞嗗埌 GPU", texture_ids.len()); let canvas = model.canvas; let model_matrix = compute_model_matrix(canvas, width, height); @@ -114,7 +114,7 @@ impl Live2DRenderer { fn draw_drawable(&self, snap: &DrawableSnapshot) { let gl = &self.gl_ctx.gl; unsafe { - // 纹理 + // 绾圭悊 let tex_idx = snap.texture_index as usize; if tex_idx < self.texture_ids.len() { (gl.gl_active_texture)(gl_api::GL_TEXTURE0); @@ -122,14 +122,14 @@ impl Live2DRenderer { (gl.gl_uniform1i)(self.gl_ctx.uniform_texture, 0); } - // base color(不透明度乘?alpha? (gl.gl_uniform4f)(self.gl_ctx.uniform_base_color, 1.0, 1.0, 1.0, snap.opacity); + // base color锛堜笉閫忔槑搴︿箻鍒?alpha锛? (gl.gl_uniform4f)(self.gl_ctx.uniform_base_color, 1.0, 1.0, 1.0, snap.opacity); // multiply/screen color let mc = snap.multiply_color; (gl.gl_uniform4f)(self.gl_ctx.uniform_multiply_color, mc[0], mc[1], mc[2], mc[3]); let sc = snap.screen_color; (gl.gl_uniform4f)(self.gl_ctx.uniform_screen_color, sc[0], sc[1], sc[2], sc[3]); - // 混合模式 + // 娣峰悎妯″紡 match snap.blend_mode { core_ffi::blend_mode::NORMAL => { (gl.gl_blend_func)(gl_api::GL_SRC_ALPHA, gl_api::GL_ONE_MINUS_SRC_ALPHA); @@ -145,7 +145,7 @@ impl Live2DRenderer { } } - // 顶点数据:position(xy) + texCoord(uv) 交错 + // 椤剁偣鏁版嵁锛歱osition(xy) + texCoord(uv) 浜ら敊 let vc = snap.vertex_positions.len(); let mut vertex_data: Vec = Vec::with_capacity(vc * 4); for i in 0..vc { @@ -218,7 +218,7 @@ impl Live2DRenderer { while self.running { let start = Instant::now(); if let Err(e) = self.render_frame() { - eprintln!("[Live2D] 渲染帧失? {e}"); + eprintln!("[Live2D] 娓叉煋甯уけ璐? {e}"); break; } let elapsed = start.elapsed(); @@ -234,8 +234,8 @@ impl Live2DRenderer { } } -/// 计算 model ?NDC 变换矩阵(列优先 4x4?/// -/// Cubism 坐标:原点在 canvas 中心,Y 轴向上,单位为像素?/// 需要等比缩放使模型完整显示在窗口内?fn compute_model_matrix( +/// 璁$畻 model 鈫?NDC 鍙樻崲鐭╅樀锛堝垪浼樺厛 4x4锛?/// +/// Cubism 鍧愭爣锛氬師鐐瑰湪 canvas 涓績锛孻 杞村悜涓婏紝鍗曚綅涓哄儚绱犮€?/// 闇€瑕佺瓑姣旂缉鏀句娇妯″瀷瀹屾暣鏄剧ず鍦ㄧ獥鍙e唴銆?fn compute_model_matrix( canvas: super::model::CanvasInfo, _width: i32, _height: i32, @@ -243,12 +243,12 @@ impl Live2DRenderer { let canvas_w = canvas.size[0].max(1.0); let canvas_h = canvas.size[1].max(1.0); - // 计算缩放:让模型等比适应窗口 + // 璁$畻缂╂斁锛氳妯″瀷绛夋瘮閫傚簲绐楀彛 let scale_x = 2.0 / canvas_w; let scale_y = 2.0 / canvas_h; let scale = scale_x.min(scale_y); - // 列优先矩阵: + // 鍒椾紭鍏堢煩闃碉細 // [ scale 0 0 0 ] // [ 0 scale 0 0 ] // [ 0 0 1 0 ]