use crate::ngui::{Object, V, pair, pptr, st};
#[must_use]
pub fn tex_env(texture: (i32, i64), scale: [f32; 2], offset: [f32; 2]) -> V {
st(
"UnityTexEnv",
vec![
("m_Texture", pptr("Texture", texture)),
("m_Scale", super::xyz("Vector2f", &scale)),
("m_Offset", super::xyz("Vector2f", &offset)),
],
)
}
fn color(value: [f32; 4]) -> V {
st(
"ColorRGBA",
["r", "g", "b", "a"]
.iter()
.zip(value)
.map(|(name, x)| (*name, V::Float(x)))
.collect(),
)
}
fn map(shape: V, entries: Vec<V>) -> V {
V::Vector("map".to_owned(), Box::new(shape), entries)
}
fn name(value: &str) -> V {
V::Str(value.as_bytes().to_vec())
}
#[must_use]
pub fn material(
path_id: i64,
material_name: &[u8],
shader: (i32, i64),
floats: &[(&str, f32)],
colors: &[(&str, [f32; 4])],
textures: &[(&str, V)],
) -> Object {
Object::new(
path_id,
21,
st(
"Material",
vec![
("m_Name", V::Str(material_name.to_vec())),
("m_Shader", pptr("Shader", shader)),
("m_CustomRenderQueue", V::Int(-1)),
(
"m_SavedProperties",
st(
"UnityPropertySheet",
vec![
(
"m_Floats",
map(
pair(name(""), V::Float(0.)),
floats
.iter()
.map(|(n, v)| pair(name(n), V::Float(*v)))
.collect(),
),
),
(
"m_Colors",
map(
pair(name(""), color([0.; 4])),
colors
.iter()
.map(|(n, v)| pair(name(n), color(*v)))
.collect(),
),
),
(
"m_TexEnvs",
map(
pair(name(""), tex_env((0, 0), [1.; 2], [0.; 2])),
textures
.iter()
.map(|(n, v)| pair(name(n), v.clone()))
.collect(),
),
),
],
),
),
],
),
)
}
#[must_use]
pub fn shader(path_id: i64, shader_name: &[u8]) -> Object {
Object::new(
path_id,
48,
st(
"Shader",
vec![
("m_Name", V::Str(shader_name.to_vec())),
(
"m_ParsedForm",
st(
"SerializedShader",
vec![("m_Name", V::Str(shader_name.to_vec()))],
),
),
],
),
)
}