From eabc16e7162ad094806631e01f4df665b3dc861c Mon Sep 17 00:00:00 2001 From: scurest Date: Thu, 6 Jan 2022 03:17:00 -0600 Subject: [PATCH] Slightly improve texture matrices (#42) --- src/nitro/model.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/nitro/model.rs b/src/nitro/model.rs index 7138994..0f4a9db 100644 --- a/src/nitro/model.rs +++ b/src/nitro/model.rs @@ -203,13 +203,13 @@ fn read_material(cur: Cur, name: Name) -> Result { teximage_param: u32, unknown3: u32, // seems like a boolean flag pltt_base: u16, - misc: u16, + flags: u16, // only read if unknown3 != 0? width: u16, height: u16, - unknown5: (fix32(1,19,12)), // usually 1.0 - unknown6: (fix32(1,19,12)), // usually 1.0 + scale1: (fix32(1,19,12)), // usually 1.0 + scale2: (fix32(1,19,12)), // usually 1.0 end: Cur, }); @@ -239,24 +239,24 @@ fn read_material(cur: Cur, name: Name) -> Result { let texture_mat: Matrix4; - if misc.bits(0,1) != 0 { + if flags.bits(0,1) != 0 { // Read texture matrix let mut x: Option<(f64, f64)> = None; let mut y: Option<(u16, u16)> = None; let mut z: Option<(f64, f64)> = None; let mut cur = end; let fx32 = |x| fix32(x, 1, 19, 12); - if misc.bits(1,2) == 0 { + if flags.bits(1,2) == 0 { let x1 = fx32(cur.next::()?); let x2 = fx32(cur.next::()?); x = Some((x1, x2)); } - if misc.bits(2,3) == 0 { + if flags.bits(2,3) == 0 { let y1 = cur.next::()?; let y2 = cur.next::()?; y = Some((y1, y2)); } - if misc.bits(3,4) == 0 { + if flags.bits(3,4) == 0 { let z1 = fx32(cur.next::()?); let z2 = fx32(cur.next::()?); z = Some((z1, z2)); @@ -265,22 +265,21 @@ fn read_material(cur: Cur, name: Name) -> Result { texture_mat = match (x, y, z) { (None, None, None) => Matrix4::one(), (Some((x1, x2)), None, None) => { - let c = 0.0; // TODO: this isn't actually zero Matrix4::new( - x1, 0.0, 0.0, 0.0, - 0.0, x2, 0.0, 0.0, + 1.0, 0.0, 0.0, x1, + 0.0, 1.0, 0.0, x2, 0.0, 0.0, 0.0, 0.0, - 0.0, c, 0.0, 1.0, + 0.0, 0.0, 0.0, 1.0, ) } _ => { // TODO - warn!("material: texture matrix is unimplemented"); + //warn!("material: texture matrix is unimplemented"); Matrix4::one() } } - // TODO: some kind of scaling involving unknown5/6 goes here + // TODO: some kind of scaling involving scale1/scale2 goes here // skipped when they are 1.0 } else {