diff options
author | metamuffin <metamuffin@disroot.org> | 2025-03-13 17:59:49 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-03-13 17:59:49 +0100 |
commit | 70d22e5162afa1b81f976acd1db534834010d3b8 (patch) | |
tree | 92982d4570eb459bb14f7a9c58bcb15de4e4cd9d /src/classes/material.rs | |
parent | 55dae4b68013a5c091abba86c725300bccfe1459 (diff) | |
download | unity-tools-70d22e5162afa1b81f976acd1db534834010d3b8.tar unity-tools-70d22e5162afa1b81f976acd1db534834010d3b8.tar.bz2 unity-tools-70d22e5162afa1b81f976acd1db534834010d3b8.tar.zst |
material parser
Diffstat (limited to 'src/classes/material.rs')
-rw-r--r-- | src/classes/material.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/classes/material.rs b/src/classes/material.rs new file mode 100644 index 0000000..354e319 --- /dev/null +++ b/src/classes/material.rs @@ -0,0 +1,70 @@ +use super::{pptr::PPtr, texture2d::Texture2D, vectors::ColorRGBA}; +use crate::object::{Value, parser::FromValue}; +use glam::Vec2; +use serde::Serialize; +use std::collections::BTreeMap; + +#[derive(Debug, Serialize)] +pub struct Material { + pub name: String, + pub shader: PPtr<Shader>, + pub properties: UnityPropertySheet, + pub lightmap_flags: u32, + pub double_sided_gi: bool, + pub custom_render_queue: i32, + pub enable_instancing_variants: bool, +} + +#[derive(Debug, Serialize)] +pub struct UnityPropertySheet { + pub colors: BTreeMap<String, ColorRGBA>, + pub floats: BTreeMap<String, f32>, + pub textures: BTreeMap<String, UnityTexEnv>, +} + +#[derive(Debug, Serialize)] +pub struct UnityTexEnv { + pub offset: Vec2, + pub scale: Vec2, + pub texture: PPtr<Texture2D>, +} + +#[derive(Debug, Serialize)] +pub struct Shader {} + +impl FromValue for Material { + fn from_value(v: Value) -> anyhow::Result<Self> { + let mut fields = v.as_class("Material")?; + Ok(Self { + custom_render_queue: fields.field("m_CustomRenderQueue")?, + double_sided_gi: fields.field("m_DoubleSidedGI")?, + properties: fields.field("m_SavedProperties")?, + enable_instancing_variants: fields.field("m_EnableInstancingVariants")?, + lightmap_flags: fields.field("m_LightmapFlags")?, + name: fields.field("m_Name")?, + shader: fields.field("m_Shader")?, + }) + } +} + +impl FromValue for UnityPropertySheet { + fn from_value(v: Value) -> anyhow::Result<Self> { + let mut fields = v.as_class("UnityPropertySheet")?; + Ok(Self { + colors: fields.field("m_Colors")?, + floats: fields.field("m_Floats")?, + textures: fields.field("m_TexEnvs")?, + }) + } +} + +impl FromValue for UnityTexEnv { + fn from_value(v: Value) -> anyhow::Result<Self> { + let mut fields = v.as_class("UnityTexEnv")?; + Ok(Self { + offset: fields.field("m_Offset")?, + scale: fields.field("m_Scale")?, + texture: fields.field("m_Texture")?, + }) + } +} |