Skip to main content

rpfm_lib/files/rigidmodel/materials/
cloth.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
17impl Material {
18    pub fn read_cloth<R: ReadBytes>(data: &mut R, version: u32) -> Result<Self> {
19        let mut mat = Self::read_default(data, version)?;
20
21        // These have a ton of extra data here.
22        let uk_7_count = data.read_u32()?;
23        mat.uk_7 = Vec::with_capacity(uk_7_count as usize);
24
25        let uk_8_count = data.read_u32()?;
26        mat.uk_8 = Vec::with_capacity(uk_8_count as usize);
27
28        let uk_9_count = data.read_u32()?;
29        mat.uk_9 = Vec::with_capacity(uk_9_count as usize);
30
31        for _ in 0..mat.uk_7.capacity() {
32            let mut uk = Uk7::default();
33
34            uk.uk1 = data.read_i32()?;
35            uk.uk2 = data.read_i32()?;
36            uk.uk3 = data.read_f32()?;
37
38            mat.uk_7.push(uk);
39        }
40
41        for _ in 0..mat.uk_8.capacity() {
42            let mut uk = Uk8::default();
43
44            uk.uk1 = data.read_i32()?;
45
46            mat.uk_8.push(uk);
47        }
48
49        for _ in 0..mat.uk_9.capacity() {
50            let mut uk = Uk9::default();
51
52            uk.uk1 = data.read_i32()?;
53            uk.uk2 = data.read_i32()?;
54            uk.uk3 = data.read_i32()?;
55
56            mat.uk_9.push(uk);
57        }
58
59        Ok(mat)
60    }
61    pub fn write_cloth<W: WriteBytes>(&self, buffer: &mut W, version: u32) -> Result<()> {
62        self.write_default(buffer, version)?;
63
64        buffer.write_i32(self.uk_7.len() as i32)?;
65        buffer.write_i32(self.uk_8.len() as i32)?;
66        buffer.write_i32(self.uk_9.len() as i32)?;
67
68        for uk in self.uk_7() {
69            buffer.write_i32(uk.uk1)?;
70            buffer.write_i32(uk.uk2)?;
71            buffer.write_f32(uk.uk3)?;
72        }
73
74        for uk in self.uk_8() {
75            buffer.write_i32(uk.uk1)?;
76        }
77
78        for uk in self.uk_9() {
79            buffer.write_i32(uk.uk1)?;
80            buffer.write_i32(uk.uk2)?;
81            buffer.write_i32(uk.uk3)?;
82        }
83
84        Ok(())
85    }
86}