Skip to content

Commit

Permalink
Slightly improve texture matrices (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
scurest committed Jan 6, 2022
1 parent 075ba9a commit eabc16e
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/nitro/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ fn read_material(cur: Cur, name: Name) -> Result<Material> {
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,
});
Expand Down Expand Up @@ -239,24 +239,24 @@ fn read_material(cur: Cur, name: Name) -> Result<Material> {


let texture_mat: Matrix4<f64>;
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::<u32>()?);
let x2 = fx32(cur.next::<u32>()?);
x = Some((x1, x2));
}
if misc.bits(2,3) == 0 {
if flags.bits(2,3) == 0 {
let y1 = cur.next::<u16>()?;
let y2 = cur.next::<u16>()?;
y = Some((y1, y2));
}
if misc.bits(3,4) == 0 {
if flags.bits(3,4) == 0 {
let z1 = fx32(cur.next::<u32>()?);
let z2 = fx32(cur.next::<u32>()?);
z = Some((z1, z2));
Expand All @@ -265,22 +265,21 @@ fn read_material(cur: Cur, name: Name) -> Result<Material> {
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 {
Expand Down

0 comments on commit eabc16e

Please # to comment.