plasma-prp 0.1.0

Read, write, inspect, and manipulate Plasma engine PRP files used by Myst Online: Uru Live
Documentation
//! plFogEnvironment — per-region fog parameters.
//!
//! C++ ref: plPipeline/plFogEnvironment.h/.cpp

use std::io::Read;

use anyhow::Result;

use crate::core::synched_object::SynchedObjectData;
use crate::core::uoid::{Uoid, read_key_uoid};
use crate::material::layer::Color;
use crate::resource::prp::PlasmaRead;

/// Fog type.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FogType {
    Linear = 0,
    ExpX = 1,
    Exp2X = 2,
}

impl FogType {
    pub fn from_u8(v: u8) -> Self {
        match v {
            1 => Self::ExpX,
            2 => Self::Exp2X,
            _ => Self::Linear,
        }
    }
}

/// Parsed plFogEnvironment data.
#[derive(Debug, Clone)]
pub struct FogEnvironmentData {
    pub self_key: Option<Uoid>,
    pub synched: SynchedObjectData,
    pub fog_type: FogType,
    pub start: f32,
    pub end: f32,
    pub density: f32,
    pub color: Color,
}

impl FogEnvironmentData {
    pub fn read(reader: &mut impl Read) -> Result<Self> {
        let self_key = read_key_uoid(reader)?;
        let synched = SynchedObjectData::read(reader)?;

        let fog_type = FogType::from_u8(reader.read_u8()?);
        let start = reader.read_f32()?;
        let end = reader.read_f32()?;
        let density = reader.read_f32()?;
        let color = Color::read(reader)?;

        Ok(Self {
            self_key,
            synched,
            fog_type,
            start,
            end,
            density,
            color,
        })
    }
}