Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support KHR_texture_transform extension for Normal and Occlusion textures #412

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions gltf-json/src/extensions/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ pub struct NormalTexture {
#[cfg(feature = "extensions")]
#[serde(default, flatten)]
pub others: Map<String, Value>,
#[cfg(feature = "KHR_texture_transform")]
#[serde(
default,
rename = "KHR_texture_transform",
skip_serializing_if = "Option::is_none"
)]
pub texture_transform: Option<crate::extensions::texture::TextureTransform>,
}

/// Defines the occlusion texture of a material.
Expand All @@ -148,6 +155,13 @@ pub struct OcclusionTexture {
#[cfg(feature = "extensions")]
#[serde(default, flatten)]
pub others: Map<String, Value>,
#[cfg(feature = "KHR_texture_transform")]
#[serde(
default,
rename = "KHR_texture_transform",
skip_serializing_if = "Option::is_none"
)]
pub texture_transform: Option<crate::extensions::texture::TextureTransform>,
}

/// The diffuse factor of a material.
Expand Down
24 changes: 24 additions & 0 deletions src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,18 @@ impl<'a> NormalTexture<'a> {
pub fn extras(&self) -> &'a json::Extras {
&self.json.extras
}

/// Returns texture transform information
#[cfg(feature = "KHR_texture_transform")]
#[cfg_attr(docsrs, doc(cfg(feature = "KHR_texture_transform")))]
pub fn texture_transform(&self) -> Option<texture::TextureTransform> {
self.json
.extensions
.as_ref()?
.texture_transform
.as_ref()
.map(texture::TextureTransform::new)
}
}

/// Defines the occlusion texture of a material.
Expand Down Expand Up @@ -685,6 +697,18 @@ impl<'a> OcclusionTexture<'a> {
pub fn extras(&self) -> &'a json::Extras {
&self.json.extras
}

/// Returns texture transform information
#[cfg(feature = "KHR_texture_transform")]
#[cfg_attr(docsrs, doc(cfg(feature = "KHR_texture_transform")))]
pub fn texture_transform(&self) -> Option<texture::TextureTransform> {
self.json
.extensions
.as_ref()?
.texture_transform
.as_ref()
.map(texture::TextureTransform::new)
}
}

impl<'a> AsRef<texture::Texture<'a>> for NormalTexture<'a> {
Expand Down