Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ KHR_materials_ior = ["gltf-json/KHR_materials_ior"]
KHR_materials_variants = ["gltf-json/KHR_materials_variants"]
KHR_materials_volume = ["gltf-json/KHR_materials_volume"]
KHR_materials_specular = ["gltf-json/KHR_materials_specular"]
KHR_materials_sheen = ["gltf-json/KHR_materials_sheen"]
KHR_materials_clearcoat = ["gltf-json/KHR_materials_clearcoat"]
KHR_materials_emissive_strength = ["gltf-json/KHR_materials_emissive_strength"]
EXT_texture_webp = ["gltf-json/EXT_texture_webp", "image/webp"]
guess_mime_type = []
Expand Down
2 changes: 2 additions & 0 deletions gltf-json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ KHR_lights_punctual = []
KHR_materials_ior = []
KHR_materials_pbrSpecularGlossiness = []
KHR_materials_specular = []
KHR_materials_sheen = []
KHR_materials_clearcoat = []
KHR_materials_transmission = []
KHR_materials_unlit = []
KHR_materials_variants = []
Expand Down
147 changes: 147 additions & 0 deletions gltf-json/src/extensions/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ pub struct Material {
)]
pub emissive_strength: Option<EmissiveStrength>,

#[cfg(feature = "KHR_materials_clearcoat")]
#[serde(
default,
rename = "KHR_materials_clearcoat",
skip_serializing_if = "Option::is_none"
)]
pub clearcoat: Option<Clearcoat>,

#[cfg(feature = "KHR_materials_sheen")]
#[serde(
default,
rename = "KHR_materials_sheen",
skip_serializing_if = "Option::is_none"
)]
pub sheen: Option<Sheen>,

#[cfg(feature = "extensions")]
#[serde(default, flatten)]
pub others: Map<String, Value>,
Expand Down Expand Up @@ -137,6 +153,13 @@ pub struct PbrSpecularGlossiness {
/// Defines the normal texture of a material.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)]
pub struct NormalTexture {
#[cfg(feature = "KHR_texture_transform")]
#[serde(
default,
rename = "KHR_texture_transform",
skip_serializing_if = "Option::is_none"
)]
pub texture_transform: Option<super::texture::TextureTransform>,
#[cfg(feature = "extensions")]
#[serde(default, flatten)]
pub others: Map<String, Value>,
Expand All @@ -145,6 +168,13 @@ pub struct NormalTexture {
/// Defines the occlusion texture of a material.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)]
pub struct OcclusionTexture {
#[cfg(feature = "KHR_texture_transform")]
#[serde(
default,
rename = "KHR_texture_transform",
skip_serializing_if = "Option::is_none"
)]
pub texture_transform: Option<super::texture::TextureTransform>,
#[cfg(feature = "extensions")]
#[serde(default, flatten)]
pub others: Map<String, Value>,
Expand Down Expand Up @@ -415,3 +445,120 @@ pub struct Specular {
#[cfg_attr(not(feature = "extras"), serde(skip_serializing))]
pub extras: Extras,
}

#[cfg(feature = "KHR_materials_clearcoat")]
#[derive(Clone, Debug, Deserialize, Serialize)]
/// Default is `0.0`
pub struct ClearcoatFactor(pub f32);

#[cfg(feature = "KHR_materials_clearcoat")]
impl Default for ClearcoatFactor {
fn default() -> Self {
Self(0f32)
}
}

#[cfg(feature = "KHR_materials_clearcoat")]
impl Validate for ClearcoatFactor {}

#[cfg(feature = "KHR_materials_clearcoat")]
#[derive(Clone, Debug, Deserialize, Serialize)]
/// Default is `0.0`
pub struct ClearcoatRoughnessFactor(pub f32);

#[cfg(feature = "KHR_materials_clearcoat")]
impl Default for ClearcoatRoughnessFactor {
fn default() -> Self {
Self(0f32)
}
}

#[cfg(feature = "KHR_materials_clearcoat")]
impl Validate for ClearcoatRoughnessFactor {}

#[cfg(feature = "KHR_materials_clearcoat")]
#[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)]
#[serde(default, rename_all = "camelCase")]
pub struct Clearcoat {
/// The clearcoat layer intensity.
/// If clearcoat_factor is zero, the whole clearcoat layer is disabled.
pub clearcoat_factor: ClearcoatFactor,

/// The clearcoat layer intensity texture.
/// Contains RGB components in linear space.
#[serde(skip_serializing_if = "Option::is_none")]
pub clearcoat_texture: Option<crate::texture::Info>,

/// The clearcoat layer roughness.
pub clearcoat_roughness_factor: ClearcoatRoughnessFactor,

/// The clearcoat layer roughness texture.
/// Contains RGB components in linear space.
#[serde(skip_serializing_if = "Option::is_none")]
pub clearcoat_roughness_texture: Option<crate::texture::Info>,

/// The clearcoat normal map texture.
#[serde(skip_serializing_if = "Option::is_none")]
pub clearcoat_normal_texture: Option<crate::material::NormalTexture>,

/// Optional application specific data.
#[cfg_attr(feature = "extras", serde(skip_serializing_if = "Option::is_none"))]
#[cfg_attr(not(feature = "extras"), serde(skip_serializing))]
pub extras: Extras,
}

#[cfg(feature = "KHR_materials_sheen")]
#[derive(Clone, Debug, Deserialize, Serialize)]
/// Default is `0.0, 0.0, 0.0`
pub struct SheenColorFactor(pub [f32; 3]);

#[cfg(feature = "KHR_materials_sheen")]
impl Default for SheenColorFactor {
fn default() -> Self {
Self([0f32, 0f32, 0f32])
}
}

#[cfg(feature = "KHR_materials_sheen")]
impl Validate for SheenColorFactor {}

#[cfg(feature = "KHR_materials_sheen")]
#[derive(Clone, Debug, Deserialize, Serialize)]
/// Default is `0.0`
pub struct SheenRoughnessFactor(pub f32);

#[cfg(feature = "KHR_materials_sheen")]
impl Default for SheenRoughnessFactor {
fn default() -> Self {
Self(0f32)
}
}

#[cfg(feature = "KHR_materials_sheen")]
impl Validate for SheenRoughnessFactor {}

#[cfg(feature = "KHR_materials_sheen")]
#[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)]
#[serde(default, rename_all = "camelCase")]
pub struct Sheen {
/// The sheen color in linear space.
/// If sheen_color_factor is zero, the whole sheen layer is disabled.
pub sheen_color_factor: SheenColorFactor,

/// The sheen color (RGB) texture.
/// The sheen color is in sRGB transfer function.
#[serde(skip_serializing_if = "Option::is_none")]
pub sheen_color_texture: Option<crate::texture::Info>,

/// The sheen roughness.
pub sheen_roughness_factor: SheenRoughnessFactor,

/// The sheen roughness (Alpha) texture.
#[serde(skip_serializing_if = "Option::is_none")]
pub sheen_roughness_texture: Option<crate::texture::Info>,

/// Optional application specific data.
#[cfg_attr(feature = "extras", serde(skip_serializing_if = "Option::is_none"))]
#[cfg_attr(not(feature = "extras"), serde(skip_serializing))]
pub extras: Extras,
}
6 changes: 6 additions & 0 deletions gltf-json/src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ pub const ENABLED_EXTENSIONS: &[&str] = &[
"KHR_materials_ior",
#[cfg(feature = "KHR_materials_emissive_strength")]
"KHR_materials_emissive_strength",
#[cfg(feature = "KHR_materials_clearcoat")]
"KHR_materials_clearcoat",
#[cfg(feature = "KHR_materials_sheen")]
"KHR_materials_sheen",
// Allowlisted texture extensions. Processing is delegated to the user.
#[cfg(feature = "allow_empty_texture")]
"KHR_texture_basisu",
Expand All @@ -70,5 +74,7 @@ pub const SUPPORTED_EXTENSIONS: &[&str] = &[
"KHR_materials_transmission",
"KHR_materials_ior",
"KHR_materials_emissive_strength",
"KHR_materials_clearcoat",
"KHR_materials_sheen",
"EXT_texture_webp",
];
Loading
Loading