Skip to main content

rpfm_lib/files/rigidmodel/materials/
uk_54.rs

1//---------------------------------------------------------------------------//
2// Copyright (c) 2017-2026 Ismael Gutiérrez González. All rights reserved.
3//
4// This file is part of the Rusted PackFile Manager (RPFM) project,
5// which can be found here: https://github.com/Frodo45127/rpfm.
6//
7// This file is licensed under the MIT license, which can be found here:
8// https://github.com/Frodo45127/rpfm/blob/master/LICENSE.
9//---------------------------------------------------------------------------//
10
11use super::*;
12
13//---------------------------------------------------------------------------//
14//                            Implementation
15//---------------------------------------------------------------------------//
16
17/// Materials of types 54, 56 and 57: the strings of the default material, its pivot and its matrix index, with no vertex format.
18/// Types 56 and 57 have a second name, after the first one.
19impl Material {
20    pub fn read_uk_54<R: ReadBytes>(data: &mut R, version: u32, mtype: MaterialType) -> Result<Self> {
21        Ok(Self {
22            name: read_padded_string(data, version, PADDED_SIZE_32)?,
23            name2: if mtype != MaterialType::Uk54 { read_padded_string(data, version, PADDED_SIZE_32)? } else { String::new() },
24            texture_directory: read_padded_string(data, version, PADDED_SIZE_256)?,
25            filters: read_padded_string(data, version, PADDED_SIZE_256)?,
26            v_pivot: Vector3::new(data.read_f32()?, data.read_f32()?, data.read_f32()?),
27            i_matrix_index: data.read_i32()?,
28            ..Default::default()
29        })
30    }
31
32    pub fn write_uk_54<W: WriteBytes>(&self, data: &mut W, version: u32, mtype: MaterialType) -> Result<()> {
33        write_padded_string(data, version, &self.name, PADDED_SIZE_32)?;
34        if mtype != MaterialType::Uk54 {
35            write_padded_string(data, version, &self.name2, PADDED_SIZE_32)?;
36        }
37        write_padded_string(data, version, &self.texture_directory, PADDED_SIZE_256)?;
38        write_padded_string(data, version, &self.filters, PADDED_SIZE_256)?;
39        data.write_f32(self.v_pivot.x)?;
40        data.write_f32(self.v_pivot.y)?;
41        data.write_f32(self.v_pivot.z)?;
42        data.write_i32(self.i_matrix_index)
43    }
44}