unlit generic

This commit is contained in:
Robin Appelman 2023-12-18 19:55:02 +01:00
commit 12793d367c
7 changed files with 89 additions and 2 deletions

View file

@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LightMappedGenericMaterial {
/// Defines an diffuse texture.
/// Defines an albedo texture.
#[serde(rename = "$basetexture")]
pub base_texture: String,
/// Use this material as a decal.
@ -85,4 +85,8 @@ pub struct LightMappedGenericMaterial {
/// Prevents fog from overdrawing a material.
#[serde(rename = "$nofog", default)]
pub no_fog: bool,
/// Ignore z filtering
#[serde(rename = "$ignorez", default)]
pub ignore_z: bool,
}

View file

@ -1,10 +1,14 @@
mod lightmappedgeneric;
mod unlitgeneric;
use lightmappedgeneric::LightMappedGenericMaterial;
pub use crate::material::unlitgeneric::UnlitGenericMaterial;
pub use lightmappedgeneric::LightMappedGenericMaterial;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Material {
#[serde(rename = "lightmappedgeneric")]
LightMappedGeneric(LightMappedGenericMaterial),
#[serde(rename = "unlitgeneric")]
UnlitGeneric(UnlitGenericMaterial),
}

View file

@ -0,0 +1,49 @@
use crate::{default_scale, default_scale3, Vec3};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnlitGenericMaterial {
/// Defines an albedo texture.
#[serde(rename = "$basetexture")]
pub base_texture: String,
/// Links the surface to a set of physical properties.
#[serde(rename = "$surfaceprop")]
pub surface_prop: Option<String>,
/// Tells this material is used for models and not brushes.
#[serde(rename = "$model", default)]
pub model: bool,
/// Independently scales the red, green and blue channels of an albedo.
#[serde(rename = "$color", default = "default_scale3")]
pub color: Vec3,
/// Scales the opacity of an entire material.
#[serde(rename = "$alpha", default = "default_scale")]
pub alpha: f32,
/// Specifies a mask to use to determine binary opacity.
#[serde(rename = "$alphatest", default)]
pub alpha_test: bool,
/// Disables backface culling.
#[serde(rename = "$nocull", default)]
pub no_cull: bool,
/// Specifies that the material should be partially see-through.
#[serde(rename = "$translucent", default)]
pub translucent: bool,
/// Ignore z filtering
#[serde(rename = "$ignorez", default)]
pub ignore_z: bool,
/// Prevents fog from overdrawing a material.
#[serde(rename = "$nofog", default)]
pub no_fog: bool,
/// Allow the player's flashlight to illuminate the material.
#[serde(rename = "$receiveflashlight", default)]
pub receive_flash_light: bool,
/// Possibly used to allow shadows to form from this decal.
#[serde(rename = "singlepassflashlight", default)]
pub single_pass_flash_light: bool,
#[serde(rename = "$no_fullbright", default)]
pub no_full_bright: bool,
}

View file

@ -0,0 +1,9 @@
"unlitgeneric"
{
"$translucent" 1
"$baseTexture" "vgui\pve\mvm_backpack"
"$vertexcolor" 1
"$no_fullbright" 1
"$ignorez" 1
"%keywords" "tf"
}

View file

@ -4,6 +4,7 @@ use test_case::test_case;
use vmt_parser::from_str;
#[test_case("tests/data/concretefloor003.vmt")]
#[test_case("tests/data/mvm_backpack.vmt")]
fn test_serde(path: &str) {
let raw = read_to_string(path).unwrap();
match from_str(&raw) {

View file

@ -28,4 +28,5 @@ lightmappedgeneric(LightMappedGenericMaterial(
r#$envmap: None,
r#$phong: false,
r#$nofog: false,
r#$ignorez: false,
))

View file

@ -0,0 +1,19 @@
---
source: tests/parse.rs
expression: result
---
unlitgeneric(UnlitGenericMaterial(
r#$basetexture: "vgui\\pve\\mvm_backpack",
r#$surfaceprop: None,
r#$model: false,
r#$color: Vec3((1.0, 1.0, 1.0)),
r#$alpha: 1.0,
r#$alphatest: false,
r#$nocull: false,
r#$translucent: true,
r#$ignorez: true,
r#$nofog: false,
r#$receiveflashlight: false,
singlepassflashlight: false,
r#$no_fullbright: true,
))