Skip to main content

rpfm_lib/files/tile_database/texture/
mod.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
11//! Texture definitions for terrain rendering.
12//!
13//! Textures define the visual properties of terrain surfaces including
14//! reflectivity, smoothness, and blending parameters.
15
16use serde_derive::{Serialize, Deserialize};
17
18use crate::binary::{ReadBytes, WriteBytes};
19use crate::error::{Result, RLibError};
20use crate::files::{Decodeable, EncodeableExtraData, Encodeable};
21
22use super::*;
23
24mod v4;
25
26//---------------------------------------------------------------------------//
27//                              Enum & Structs
28//---------------------------------------------------------------------------//
29
30/// A terrain texture with material properties.
31///
32/// Defines surface rendering properties including reflectivity and smoothness
33/// values at different interpolation points.
34#[derive(Default, PartialEq, Clone, Debug, Getters, MutGetters, Setters, Serialize, Deserialize)]
35#[getset(get = "pub", get_mut = "pub", set = "pub")]
36pub struct Texture {
37    /// Serialisation format version.
38    serialise_version: u16,
39
40    /// Texture identifier name.
41    name: String,
42    /// Mid-distance detail strength.
43    mid_distance_strength: f32,
44    /// Reflectivity at lerp point 0.
45    lerp_reflectivity0: f32,
46    /// Smoothness at lerp point 0.
47    lerp_smoothness0: f32,
48    /// Reflectivity at lerp point 1.
49    lerp_reflectivity1: f32,
50    /// Smoothness at lerp point 1.
51    lerp_smoothness1: f32,
52    /// Reflectivity at lerp point 2.
53    lerp_reflectivity2: f32,
54    /// Smoothness at lerp point 2.
55    lerp_smoothness2: f32,
56    /// Reflectivity at lerp point 3.
57    lerp_reflectivity3: f32,
58    /// Smoothness at lerp point 3.
59    lerp_smoothness3: f32,
60    /// Pixel scale for texture blending.
61    blend_pixel_scale: f32,
62    /// Pixel scale for outfield blending.
63    outfield_blend_pixel_scale: f32,
64}
65
66//---------------------------------------------------------------------------//
67//                      Implementation of Texture
68//---------------------------------------------------------------------------//
69
70impl Decodeable for Texture {
71
72    fn decode<R: ReadBytes>(data: &mut R, extra_data: &Option<DecodeableExtraData>) -> Result<Self> {
73        let mut decoded = Self::default();
74        decoded.serialise_version = data.read_u16()?;
75
76        match decoded.serialise_version {
77            4 => decoded.read_v4(data, extra_data)?,
78            _ => return Err(RLibError::DecodingFastBinUnsupportedVersion(String::from("Texture"), decoded.serialise_version)),
79        }
80
81        Ok(decoded)
82    }
83}
84
85impl Encodeable for Texture {
86
87    fn encode<W: WriteBytes>(&mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData>) -> Result<()> {
88        buffer.write_u16(self.serialise_version)?;
89
90        match self.serialise_version {
91            4 => self.write_v4(buffer, extra_data)?,
92            _ => return Err(RLibError::EncodingFastBinUnsupportedVersion(String::from("Texture"), self.serialise_version)),
93        }
94
95        Ok(())
96    }
97}