rpfm_lib/files/tile_database/conversion_params/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//! Conversion parameters for tile processing.
12//!
13//! Contains settings for converting and processing terrain tiles including
14//! triangle density and decimation factors.
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 v1;
25
26//---------------------------------------------------------------------------//
27// Enum & Structs
28//---------------------------------------------------------------------------//
29
30/// Parameters for tile conversion and mesh generation.
31///
32/// Controls triangle density and decimation factors used when
33/// converting terrain data to renderable mesh formats.
34#[derive(Default, PartialEq, Clone, Debug, Getters, MutGetters, Setters, Serialize, Deserialize)]
35#[getset(get = "pub", get_mut = "pub", set = "pub")]
36pub struct ConversionParams {
37 /// Serialisation format version.
38 serialise_version: u16,
39
40 /// Target triangle density.
41 triangle_density: i32,
42 /// Maximum low-frequency heights per pixel.
43 max_lf_heights_per_pixel: i32,
44 /// Size decimation factor (LOD level 0).
45 triangle_decimation_size_factors0: f32,
46 /// Size decimation factor (LOD level 1).
47 triangle_decimation_size_factors1: f32,
48 /// Size decimation factor (LOD level 2).
49 triangle_decimation_size_factors2: f32,
50 /// Size decimation factor (LOD level 3).
51 triangle_decimation_size_factors3: f32,
52 /// Size decimation factor (LOD level 4).
53 triangle_decimation_size_factors4: f32,
54 /// Size decimation factor (LOD level 5).
55 triangle_decimation_size_factors5: f32,
56 /// Angle decimation factor (LOD level 0).
57 triangle_decimation_angle_factors0: f32,
58 /// Angle decimation factor (LOD level 1).
59 triangle_decimation_angle_factors1: f32,
60 /// Angle decimation factor (LOD level 2).
61 triangle_decimation_angle_factors2: f32,
62 /// Angle decimation factor (LOD level 3).
63 triangle_decimation_angle_factors3: f32,
64 /// Angle decimation factor (LOD level 4).
65 triangle_decimation_angle_factors4: f32,
66 /// Angle decimation factor (LOD level 5).
67 triangle_decimation_angle_factors5: f32,
68}
69
70//---------------------------------------------------------------------------//
71// Implementation of ConversionParams
72//---------------------------------------------------------------------------//
73
74impl Decodeable for ConversionParams {
75
76 fn decode<R: ReadBytes>(data: &mut R, extra_data: &Option<DecodeableExtraData>) -> Result<Self> {
77 let mut decoded = Self::default();
78 decoded.serialise_version = data.read_u16()?;
79
80 match decoded.serialise_version {
81 1 => decoded.read_v1(data, extra_data)?,
82 _ => return Err(RLibError::DecodingFastBinUnsupportedVersion(String::from("ConversionParams"), decoded.serialise_version)),
83 }
84
85 Ok(decoded)
86 }
87}
88
89impl Encodeable for ConversionParams {
90
91 fn encode<W: WriteBytes>(&mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData>) -> Result<()> {
92 buffer.write_u16(self.serialise_version)?;
93
94 match self.serialise_version {
95 1 => self.write_v1(buffer, extra_data)?,
96 _ => return Err(RLibError::EncodingFastBinUnsupportedVersion(String::from("ConversionParams"), self.serialise_version)),
97 }
98
99 Ok(())
100 }
101}