aboutsummaryrefslogtreecommitdiff
path: root/src/classes/material.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/material.rs')
-rw-r--r--src/classes/material.rs70
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")?,
+ })
+ }
+}