mirror of
https://codeberg.org/icewind/vmt-parser.git
synced 2026-06-03 12:04:06 +02:00
sprite
This commit is contained in:
parent
497b2a57e7
commit
e6b54a8c8d
3 changed files with 55 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
pub use texture_transform::TextureTransform;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Copy, Clone, Default)]
|
||||
#[serde(from = "Vec2OrSingle<f32>")]
|
||||
pub struct Vec2(pub [f32; 2]);
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ impl From<Vec2OrSingle<f32>> for Vec2 {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
|
||||
#[derive(Debug, Serialize, Deserialize, Copy, Clone, Default)]
|
||||
#[serde(from = "Vec3OrSingle<f32>")]
|
||||
pub struct Vec3(pub [f32; 3]);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
mod eyerefract;
|
||||
mod lightmappedgeneric;
|
||||
mod sprite;
|
||||
mod unlitgeneric;
|
||||
mod unlittwotexture;
|
||||
mod vertexlitgeneric;
|
||||
|
|
@ -9,6 +10,7 @@ mod worldvertextransition;
|
|||
pub use eyerefract::EyeRefractMaterial;
|
||||
pub use lightmappedgeneric::LightMappedGenericMaterial;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
pub use sprite::{SpriteMaterial, SpriteOrientation};
|
||||
pub use unlitgeneric::UnlitGenericMaterial;
|
||||
pub use unlittwotexture::UnlitTwoTextureMaterial;
|
||||
use vdf_reader::entry::{Entry, Table};
|
||||
|
|
@ -35,6 +37,8 @@ pub enum Material {
|
|||
WorldVertexTransition(WorldVertexTransitionMaterial),
|
||||
#[serde(rename = "eyerefract")]
|
||||
EyeRefract(EyeRefractMaterial),
|
||||
#[serde(rename = "sprite")]
|
||||
Sprite(SpriteMaterial),
|
||||
#[serde(rename = "patch")]
|
||||
Patch(PatchMaterial),
|
||||
}
|
||||
|
|
@ -59,6 +63,7 @@ impl Material {
|
|||
Material::UnlitGeneric(mat) => mat.translucent,
|
||||
Material::UnlitTwoTexture(mat) => mat.translucent,
|
||||
Material::WorldVertexTransition(mat) => mat.translucent,
|
||||
Material::Sprite(mat) => mat.translucent,
|
||||
Material::Water(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
|
|
@ -85,6 +90,7 @@ impl Material {
|
|||
Material::WorldVertexTransition(mat) => {
|
||||
mat.alpha_test.then_some(mat.alpha_test_reference)
|
||||
}
|
||||
Material::Sprite(mat) => mat.alpha_test.then_some(mat.alpha_test_reference),
|
||||
Material::Water(_) => None,
|
||||
_ => None,
|
||||
}
|
||||
|
|
@ -97,6 +103,7 @@ impl Material {
|
|||
Material::UnlitGeneric(mat) => &mat.base_texture,
|
||||
Material::UnlitTwoTexture(mat) => &mat.base_texture,
|
||||
Material::WorldVertexTransition(mat) => &mat.base_texture,
|
||||
Material::Sprite(mat) => &mat.base_texture,
|
||||
Material::Water(mat) => mat.base_texture.as_deref().unwrap_or_default(),
|
||||
Material::EyeRefract(mat) => &mat.iris,
|
||||
_ => "",
|
||||
|
|
@ -131,6 +138,7 @@ impl Material {
|
|||
Material::VertexLitGeneric(mat) => mat.alpha,
|
||||
Material::UnlitGeneric(mat) => mat.alpha,
|
||||
Material::UnlitTwoTexture(mat) => mat.alpha,
|
||||
Material::Sprite(mat) => mat.alpha,
|
||||
Material::WorldVertexTransition(mat) => mat.alpha,
|
||||
_ => 1.0,
|
||||
}
|
||||
|
|
|
|||
45
src/material/sprite.rs
Normal file
45
src/material/sprite.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use super::deserialize_path;
|
||||
use crate::{default_scale, default_scale3, Vec3};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SpriteMaterial {
|
||||
/// Defines an albedo texture.
|
||||
#[serde(rename = "$basetexture", deserialize_with = "deserialize_path")]
|
||||
pub base_texture: String,
|
||||
/// Links the surface to a set of physical properties.
|
||||
#[serde(rename = "$surfaceprop", default)]
|
||||
pub surface_prop: Option<String>,
|
||||
|
||||
#[serde(rename = "$spriteorientation", default)]
|
||||
pub sprite_orientation: SpriteOrientation,
|
||||
#[serde(rename = "$spriteorigin", default)]
|
||||
pub sprite_origin: Vec3,
|
||||
|
||||
/// 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,
|
||||
/// Specifies a mask to use to determine binary opacity.
|
||||
#[serde(rename = "$alphatestreference", default = "default_scale")]
|
||||
pub alpha_test_reference: f32,
|
||||
/// Specifies that the material should be partially see-through.
|
||||
#[serde(rename = "$translucent", default)]
|
||||
pub translucent: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SpriteOrientation {
|
||||
ParallelUpright,
|
||||
#[default]
|
||||
VpParallel,
|
||||
Oriented,
|
||||
VpParallelOriented,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue