From 153fd3f86a28b0f6fad6d0e0c4badfb43b094611 Mon Sep 17 00:00:00 2001 From: abdo1504-HULK Date: Tue, 13 Dec 2022 13:36:01 +0100 Subject: [PATCH 01/12] added support for EXT_texture_webp --- Cargo.toml | 1 + gltf-json/Cargo.toml | 1 + gltf-json/src/extensions/mod.rs | 3 +++ gltf-json/src/extensions/texture.rs | 23 ++++++++++++++++++++++- gltf-json/src/image.rs | 7 ++++++- src/import.rs | 12 ++++++++++++ 6 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f0462205..209108a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,7 @@ 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"] +EXT_texture_webp = ["gltf-json/EXT_texture_webp", "image/webp"] image_jpeg_rayon = ["image/jpeg_rayon"] guess_mime_type = [] diff --git a/gltf-json/Cargo.toml b/gltf-json/Cargo.toml index 5775dd24..c24d524d 100644 --- a/gltf-json/Cargo.toml +++ b/gltf-json/Cargo.toml @@ -26,3 +26,4 @@ KHR_materials_unlit = [] KHR_materials_variants = [] KHR_materials_volume = [] KHR_texture_transform = [] +EXT_texture_webp = [] diff --git a/gltf-json/src/extensions/mod.rs b/gltf-json/src/extensions/mod.rs index ac2f128e..68a60bd8 100644 --- a/gltf-json/src/extensions/mod.rs +++ b/gltf-json/src/extensions/mod.rs @@ -50,6 +50,8 @@ pub const ENABLED_EXTENSIONS: &[&str] = &[ "KHR_materials_transmission", #[cfg(feature = "KHR_materials_ior")] "KHR_materials_ior", + #[cfg(feature = "EXT_texture_webp")] + "EXT_texture_webp", ]; /// Names of glTF 2.0 extensions supported by the library. @@ -60,4 +62,5 @@ pub const SUPPORTED_EXTENSIONS: &[&str] = &[ "KHR_texture_transform", "KHR_materials_transmission", "KHR_materials_ior", + "EXT_texture_webp", ]; diff --git a/gltf-json/src/extensions/texture.rs b/gltf-json/src/extensions/texture.rs index 35b590cc..ff7cc9e2 100644 --- a/gltf-json/src/extensions/texture.rs +++ b/gltf-json/src/extensions/texture.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "EXT_texture_webp")] +use crate::{extras::Extras, image, validation::Validate, Index}; #[cfg(feature = "KHR_texture_transform")] use crate::{extras::Extras, validation::Validate}; use gltf_derive::Validate; @@ -9,7 +11,26 @@ pub struct Sampler {} /// A texture and its sampler. #[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)] -pub struct Texture {} +pub struct Texture { + #[cfg(feature = "EXT_texture_webp")] + #[serde( + default, + rename = "EXT_texture_webp", + skip_serializing_if = "Option::is_none" + )] + pub texture_webp: Option, +} + +#[cfg(feature = "EXT_texture_webp")] +#[derive(Clone, Debug, Deserialize, Serialize, Validate)] +pub struct TextureWebp { + /// The index of the image used by this texture. + pub source: Index, + + #[cfg_attr(feature = "extras", serde(skip_serializing_if = "Option::is_none"))] + #[cfg_attr(not(feature = "extras"), serde(skip_serializing))] + pub extras: Extras, +} #[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)] /// Reference to a `Texture`. diff --git a/gltf-json/src/image.rs b/gltf-json/src/image.rs index 2ee1b62a..a13fb90f 100644 --- a/gltf-json/src/image.rs +++ b/gltf-json/src/image.rs @@ -4,7 +4,12 @@ use gltf_derive::Validate; use serde_derive::{Deserialize, Serialize}; /// All valid MIME types. -pub const VALID_MIME_TYPES: &[&str] = &["image/jpeg", "image/png"]; +pub const VALID_MIME_TYPES: &[&str] = &[ + "image/jpeg", + "image/png", + #[cfg(feature = "EXT_texture_webp")] + "image/webp", +]; /// Image data used to create a texture. #[derive(Clone, Debug, Deserialize, Serialize, Validate)] diff --git a/src/import.rs b/src/import.rs index 1fbfe90d..d0fd81ff 100644 --- a/src/import.rs +++ b/src/import.rs @@ -4,6 +4,8 @@ use std::borrow::Cow; use std::{fs, io}; use crate::{Document, Error, Gltf, Result}; +#[cfg(feature = "EXT_texture_webp")] +use image_crate::ImageFormat::WebP; use image_crate::ImageFormat::{Jpeg, Png}; use std::path::Path; @@ -118,6 +120,8 @@ pub fn import_image_data( let guess_format = |encoded_image: &[u8]| match image_crate::guess_format(encoded_image) { Ok(image_crate::ImageFormat::Png) => Some(Png), Ok(image_crate::ImageFormat::Jpeg) => Some(Jpeg), + #[cfg(feature = "EXT_texture_webp")] + Ok(image_crate::ImageFormat::WebP) => Some(WebP), _ => None, }; #[cfg(not(feature = "guess_mime_type"))] @@ -130,6 +134,8 @@ pub fn import_image_data( let encoded_format = match annoying_case { "image/png" => Png, "image/jpeg" => Jpeg, + #[cfg(feature = "EXT_texture_webp")] + "image/webp" => WebP, _ => match guess_format(&encoded_image) { Some(format) => format, None => return Err(Error::UnsupportedImageEncoding), @@ -144,6 +150,8 @@ pub fn import_image_data( let encoded_format = match mime_type { Some("image/png") => Png, Some("image/jpeg") => Jpeg, + #[cfg(feature = "EXT_texture_webp")] + Some("image/webp") => WebP, Some(_) => match guess_format(&encoded_image) { Some(format) => format, None => return Err(Error::UnsupportedImageEncoding), @@ -151,6 +159,8 @@ pub fn import_image_data( None => match uri.rsplit('.').next() { Some("png") => Png, Some("jpg") | Some("jpeg") => Jpeg, + #[cfg(feature = "EXT_texture_webp")] + Some("webp") => WebP, _ => match guess_format(&encoded_image) { Some(format) => format, None => return Err(Error::UnsupportedImageEncoding), @@ -168,6 +178,8 @@ pub fn import_image_data( let encoded_format = match mime_type { "image/png" => Png, "image/jpeg" => Jpeg, + #[cfg(feature = "EXT_texture_webp")] + "image/webp" => WebP, _ => match guess_format(encoded_image) { Some(format) => format, None => return Err(Error::UnsupportedImageEncoding), From edf25099f431cf928750f6440c20db23f80495ea Mon Sep 17 00:00:00 2001 From: abdo1504-HULK Date: Tue, 13 Dec 2022 13:45:30 +0100 Subject: [PATCH 02/12] fixed import to prevent collision --- gltf-json/src/extensions/texture.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gltf-json/src/extensions/texture.rs b/gltf-json/src/extensions/texture.rs index ff7cc9e2..33ec3d93 100644 --- a/gltf-json/src/extensions/texture.rs +++ b/gltf-json/src/extensions/texture.rs @@ -1,7 +1,8 @@ -#[cfg(feature = "EXT_texture_webp")] -use crate::{extras::Extras, image, validation::Validate, Index}; -#[cfg(feature = "KHR_texture_transform")] +#[cfg(any(feature = "KHR_texture_transform", feature = "EXT_texture_webp"))] use crate::{extras::Extras, validation::Validate}; +#[cfg(feature = "EXT_texture_webp")] +use crate::{image, Index}; + use gltf_derive::Validate; use serde_derive::{Deserialize, Serialize}; From 73b68dc7ba63a1a3676eddd9298431a215d7b614 Mon Sep 17 00:00:00 2001 From: abdo1504-HULK Date: Tue, 13 Dec 2022 14:34:37 +0100 Subject: [PATCH 03/12] added automatically retrieving the webp source --- src/texture.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/texture.rs b/src/texture.rs index 14e49a43..b9b1f0ad 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -144,6 +144,7 @@ impl<'a> Texture<'a> { .unwrap_or_else(|| Sampler::default(self.document)) } + #[cfg(not(feature = "EXT_texture_webp"))] /// Returns the image used by this texture. pub fn source(&self) -> image::Image<'a> { self.document @@ -152,6 +153,24 @@ impl<'a> Texture<'a> { .unwrap() } + #[cfg(feature = "EXT_texture_webp")] + pub fn source(&self) -> image::Image<'a> { + let extensions = self.json.extensions; + let required_extensions = self.document.extensions_required(); + + let source_index = match required_extensions + .any(|required_extension| required_extension == "EXT_texture_webp") + { + true => extensions.unwrap().texture_webp.unwrap().source.value(), + false => match extensions.and_then(|extensions| extensions.texture_webp) { + Some(webp) => webp.source.value(), + None => self.json.source.value(), + }, + }; + + self.document.images().nth(source_index).unwrap() + } + /// Optional application specific data. pub fn extras(&self) -> &json::Extras { &self.json.extras From f9b7626901fea2f6afb5c06f2868bea4857370f6 Mon Sep 17 00:00:00 2001 From: abdo1504-HULK Date: Tue, 13 Dec 2022 14:49:08 +0100 Subject: [PATCH 04/12] removed unnessecary duplication --- gltf-json/src/extensions/texture.rs | 2 +- src/texture.rs | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/gltf-json/src/extensions/texture.rs b/gltf-json/src/extensions/texture.rs index 33ec3d93..fe69edd9 100644 --- a/gltf-json/src/extensions/texture.rs +++ b/gltf-json/src/extensions/texture.rs @@ -25,7 +25,7 @@ pub struct Texture { #[cfg(feature = "EXT_texture_webp")] #[derive(Clone, Debug, Deserialize, Serialize, Validate)] pub struct TextureWebp { - /// The index of the image used by this texture. + /// The index of the webp image used by the texture. pub source: Index, #[cfg_attr(feature = "extras", serde(skip_serializing_if = "Option::is_none"))] diff --git a/src/texture.rs b/src/texture.rs index b9b1f0ad..3bd2aa99 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -158,17 +158,16 @@ impl<'a> Texture<'a> { let extensions = self.json.extensions; let required_extensions = self.document.extensions_required(); - let source_index = match required_extensions + let source = match required_extensions .any(|required_extension| required_extension == "EXT_texture_webp") { - true => extensions.unwrap().texture_webp.unwrap().source.value(), - false => match extensions.and_then(|extensions| extensions.texture_webp) { - Some(webp) => webp.source.value(), - None => self.json.source.value(), - }, + true => extensions.unwrap().texture_webp.unwrap().source, + false => extensions + .and_then(|extensions| Some(extensions.texture_webp?.source)) + .unwrap_or(self.json.source), }; - self.document.images().nth(source_index).unwrap() + self.document.images().nth(source.value()).unwrap() } /// Optional application specific data. From 58d7f954c6ce9b6a9e50e370759142c9c41d9212 Mon Sep 17 00:00:00 2001 From: abdo1504-HULK Date: Sat, 31 Dec 2022 10:17:17 +0100 Subject: [PATCH 05/12] removed unessecary match and matched spec --- gltf-json/src/extensions/texture.rs | 2 +- src/texture.rs | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/gltf-json/src/extensions/texture.rs b/gltf-json/src/extensions/texture.rs index fe69edd9..11b11269 100644 --- a/gltf-json/src/extensions/texture.rs +++ b/gltf-json/src/extensions/texture.rs @@ -26,7 +26,7 @@ pub struct Texture { #[derive(Clone, Debug, Deserialize, Serialize, Validate)] pub struct TextureWebp { /// The index of the webp image used by the texture. - pub source: Index, + pub source: Option>, #[cfg_attr(feature = "extras", serde(skip_serializing_if = "Option::is_none"))] #[cfg_attr(not(feature = "extras"), serde(skip_serializing))] diff --git a/src/texture.rs b/src/texture.rs index 3bd2aa99..71aadd96 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -155,17 +155,11 @@ impl<'a> Texture<'a> { #[cfg(feature = "EXT_texture_webp")] pub fn source(&self) -> image::Image<'a> { - let extensions = self.json.extensions; - let required_extensions = self.document.extensions_required(); - - let source = match required_extensions - .any(|required_extension| required_extension == "EXT_texture_webp") - { - true => extensions.unwrap().texture_webp.unwrap().source, - false => extensions - .and_then(|extensions| Some(extensions.texture_webp?.source)) - .unwrap_or(self.json.source), - }; + let source = self + .json + .extensions + .and_then(|extensions| extensions.texture_webp?.source) + .unwrap_or(self.json.source); self.document.images().nth(source.value()).unwrap() } From b3ec175926248b9d2af1d50ff0f921078ad4036c Mon Sep 17 00:00:00 2001 From: abdo1504-HULK Date: Sat, 31 Dec 2022 10:42:14 +0100 Subject: [PATCH 06/12] bug fix --- src/texture.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/texture.rs b/src/texture.rs index 71aadd96..7e20a6a7 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -154,11 +154,13 @@ impl<'a> Texture<'a> { } #[cfg(feature = "EXT_texture_webp")] + /// Returns the image used by this texture. pub fn source(&self) -> image::Image<'a> { let source = self .json .extensions - .and_then(|extensions| extensions.texture_webp?.source) + .as_ref() + .and_then(|extensions| extensions.texture_webp.as_ref()?.source) .unwrap_or(self.json.source); self.document.images().nth(source.value()).unwrap() From 53aa398b9ead0ebdd35bc883dfe280b8a35c198e Mon Sep 17 00:00:00 2001 From: Marios Staikopoulos Date: Thu, 30 May 2024 13:47:57 -0700 Subject: [PATCH 07/12] fix webp --- gltf-json/src/extensions/texture.rs | 19 +++++++++++++++++++ src/texture.rs | 28 +++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/gltf-json/src/extensions/texture.rs b/gltf-json/src/extensions/texture.rs index 5433cf23..f88b6a1a 100644 --- a/gltf-json/src/extensions/texture.rs +++ b/gltf-json/src/extensions/texture.rs @@ -22,6 +22,25 @@ pub struct Texture { #[cfg(feature = "extensions")] #[serde(default, flatten)] pub others: Map, + + #[cfg(feature = "EXT_texture_webp")] + #[serde( + default, + rename = "EXT_texture_webp", + skip_serializing_if = "Option::is_none" + )] + pub texture_webp: Option, +} + +#[cfg(feature = "EXT_texture_webp")] +#[derive(Clone, Debug, Deserialize, Serialize, Validate)] +pub struct TextureWebP { + /// The index of the webp image used by the texture. + pub source: Index, + + #[cfg_attr(feature = "extras", serde(skip_serializing_if = "Option::is_none"))] + #[cfg_attr(not(feature = "extras"), serde(skip_serializing))] + pub extras: Extras, } #[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)] diff --git a/src/texture.rs b/src/texture.rs index bd99b024..aa62a0b6 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -1,3 +1,5 @@ +use std::error::Error; + use crate::{image, Document}; pub use json::texture::{MagFilter, MinFilter, WrappingMode}; @@ -157,10 +159,29 @@ impl<'a> Texture<'a> { .unwrap_or_else(|| Sampler::default(self.document)) } + fn source_index(&self) -> usize { + let default = self.json.source.value(); + + #[cfg(feature = "EXT_texture_webp")] + { + let opt_texture_webp = self + .json + .extensions + .as_ref() + .and_then(|ext| ext.texture_webp.as_ref()); + + if let Some(texture_webp) = opt_texture_webp { + return texture_webp.source.value(); + } + } + + return default; + } + /// Returns the image used by this texture. #[cfg(feature = "allow_empty_texture")] pub fn source(&self) -> Option> { - let index = self.json.source.value(); + let index = self.source_index(); if index == u32::MAX as usize { None } else { @@ -171,10 +192,7 @@ impl<'a> Texture<'a> { /// Returns the image used by this texture. #[cfg(not(feature = "allow_empty_texture"))] pub fn source(&self) -> image::Image<'a> { - self.document - .images() - .nth(self.json.source.value()) - .unwrap() + self.document.images().nth(self.source_index()).unwrap() } /// Returns extension data unknown to this crate version. From d424adb94eff1def62db8afd9d64fd4a3c0d4829 Mon Sep 17 00:00:00 2001 From: Marios Staikopoulos Date: Thu, 30 May 2024 13:55:16 -0700 Subject: [PATCH 08/12] rename and remove extras --- gltf-json/src/extensions/texture.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/gltf-json/src/extensions/texture.rs b/gltf-json/src/extensions/texture.rs index f88b6a1a..010cc761 100644 --- a/gltf-json/src/extensions/texture.rs +++ b/gltf-json/src/extensions/texture.rs @@ -29,18 +29,14 @@ pub struct Texture { rename = "EXT_texture_webp", skip_serializing_if = "Option::is_none" )] - pub texture_webp: Option, + pub texture_webp: Option, } #[cfg(feature = "EXT_texture_webp")] #[derive(Clone, Debug, Deserialize, Serialize, Validate)] -pub struct TextureWebP { +pub struct TextureWebp { /// The index of the webp image used by the texture. pub source: Index, - - #[cfg_attr(feature = "extras", serde(skip_serializing_if = "Option::is_none"))] - #[cfg_attr(not(feature = "extras"), serde(skip_serializing))] - pub extras: Extras, } #[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)] From 306c2b0eb5ffd9477a3a08a9953070d4f5eafaee Mon Sep 17 00:00:00 2001 From: Marios Staikopoulos Date: Thu, 30 May 2024 13:59:35 -0700 Subject: [PATCH 09/12] allow empty texture on webp --- gltf-json/src/texture.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gltf-json/src/texture.rs b/gltf-json/src/texture.rs index c232f908..acccd2f3 100644 --- a/gltf-json/src/texture.rs +++ b/gltf-json/src/texture.rs @@ -179,7 +179,10 @@ where P: Fn() -> crate::Path, R: FnMut(&dyn Fn() -> crate::Path, crate::validation::Error), { - if cfg!(feature = "allow_empty_texture") { + if cfg!(any( + feature = "allow_empty_texture", + feature = "EXT_texture_webp" + )) { if !source_is_empty(source) { source.validate(root, path, report); } From fca3dda98ed782fac8fd2e1cbe99975fbb99459a Mon Sep 17 00:00:00 2001 From: Marios Staikopoulos Date: Tue, 18 Jun 2024 16:56:04 -0700 Subject: [PATCH 10/12] add webp fallback support at the gltf json level --- gltf-json/src/texture.rs | 32 ++++++++++++++++++++++++++------ src/texture.rs | 28 +++++----------------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/gltf-json/src/texture.rs b/gltf-json/src/texture.rs index acccd2f3..365fd089 100644 --- a/gltf-json/src/texture.rs +++ b/gltf-json/src/texture.rs @@ -1,3 +1,4 @@ +use crate::extensions::texture; use crate::validation::{Checked, Validate}; use crate::{extensions, image, Extras, Index}; use gltf_derive::Validate; @@ -179,10 +180,7 @@ where P: Fn() -> crate::Path, R: FnMut(&dyn Fn() -> crate::Path, crate::validation::Error), { - if cfg!(any( - feature = "allow_empty_texture", - feature = "EXT_texture_webp" - )) { + if cfg!(any(feature = "allow_empty_texture",)) { if !source_is_empty(source) { source.validate(root, path, report); } @@ -207,7 +205,7 @@ pub struct Texture { /// The index of the image used by this texture. #[serde(default = "source_default", skip_serializing_if = "source_is_empty")] - pub source: Index, + source: Index, /// Extension specific data. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -220,6 +218,27 @@ pub struct Texture { pub extras: Extras, } +impl Texture { + /// The index of the image used by this texture. + pub fn source(&self) -> Index { + #[allow(unused_mut)] + let mut source = self.source; + #[cfg(feature = "EXT_texture_webp")] + { + if let Some(texture_webp) = &self.extensions { + if let Some(texture_webp) = &texture_webp.texture_webp { + // Only use the webp source if the source is not empty + // Otherwise, fallback to whatever was there originally + if !source_is_empty(&texture_webp.source) { + source = texture_webp.source; + } + } + } + } + source + } +} + impl Validate for Texture { fn validate(&self, root: &crate::Root, path: P, report: &mut R) where @@ -230,7 +249,8 @@ impl Validate for Texture { .validate(root, || path().field("sampler"), report); self.extensions .validate(root, || path().field("extensions"), report); - source_validate(&self.source, root, || path().field("source"), report); + + source_validate(&self.source(), root, || path().field("source"), report); } } diff --git a/src/texture.rs b/src/texture.rs index aa62a0b6..0de41a8b 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -1,5 +1,3 @@ -use std::error::Error; - use crate::{image, Document}; pub use json::texture::{MagFilter, MinFilter, WrappingMode}; @@ -159,29 +157,10 @@ impl<'a> Texture<'a> { .unwrap_or_else(|| Sampler::default(self.document)) } - fn source_index(&self) -> usize { - let default = self.json.source.value(); - - #[cfg(feature = "EXT_texture_webp")] - { - let opt_texture_webp = self - .json - .extensions - .as_ref() - .and_then(|ext| ext.texture_webp.as_ref()); - - if let Some(texture_webp) = opt_texture_webp { - return texture_webp.source.value(); - } - } - - return default; - } - /// Returns the image used by this texture. #[cfg(feature = "allow_empty_texture")] pub fn source(&self) -> Option> { - let index = self.source_index(); + let index = self.json.source().value(); if index == u32::MAX as usize { None } else { @@ -192,7 +171,10 @@ impl<'a> Texture<'a> { /// Returns the image used by this texture. #[cfg(not(feature = "allow_empty_texture"))] pub fn source(&self) -> image::Image<'a> { - self.document.images().nth(self.source_index()).unwrap() + self.document + .images() + .nth(self.json.source().value()) + .unwrap() } /// Returns extension data unknown to this crate version. From 5465423aa46a2b82e24c9630f95890a10e6e6f83 Mon Sep 17 00:00:00 2001 From: Marios Staikopoulos Date: Tue, 18 Jun 2024 17:00:23 -0700 Subject: [PATCH 11/12] rename to primary_source --- gltf-json/src/texture.rs | 6 +++--- src/texture.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gltf-json/src/texture.rs b/gltf-json/src/texture.rs index 365fd089..8f156f7e 100644 --- a/gltf-json/src/texture.rs +++ b/gltf-json/src/texture.rs @@ -205,7 +205,7 @@ pub struct Texture { /// The index of the image used by this texture. #[serde(default = "source_default", skip_serializing_if = "source_is_empty")] - source: Index, + pub source: Index, /// Extension specific data. #[serde(default, skip_serializing_if = "Option::is_none")] @@ -220,7 +220,7 @@ pub struct Texture { impl Texture { /// The index of the image used by this texture. - pub fn source(&self) -> Index { + pub fn primary_source(&self) -> Index { #[allow(unused_mut)] let mut source = self.source; #[cfg(feature = "EXT_texture_webp")] @@ -250,7 +250,7 @@ impl Validate for Texture { self.extensions .validate(root, || path().field("extensions"), report); - source_validate(&self.source(), root, || path().field("source"), report); + source_validate(&self.primary_source(), root, || path().field("source"), report); } } diff --git a/src/texture.rs b/src/texture.rs index 0de41a8b..4af15165 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -160,7 +160,7 @@ impl<'a> Texture<'a> { /// Returns the image used by this texture. #[cfg(feature = "allow_empty_texture")] pub fn source(&self) -> Option> { - let index = self.json.source().value(); + let index = self.json.primary_source().value(); if index == u32::MAX as usize { None } else { @@ -173,7 +173,7 @@ impl<'a> Texture<'a> { pub fn source(&self) -> image::Image<'a> { self.document .images() - .nth(self.json.source().value()) + .nth(self.json.primary_source().value()) .unwrap() } From 8baf835f8273f741c9753312977471d8082263aa Mon Sep 17 00:00:00 2001 From: Marios Staikopoulos Date: Thu, 27 Jun 2024 15:07:39 -0700 Subject: [PATCH 12/12] formatting --- gltf-json/src/texture.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gltf-json/src/texture.rs b/gltf-json/src/texture.rs index 8f156f7e..01aea1c3 100644 --- a/gltf-json/src/texture.rs +++ b/gltf-json/src/texture.rs @@ -250,7 +250,12 @@ impl Validate for Texture { self.extensions .validate(root, || path().field("extensions"), report); - source_validate(&self.primary_source(), root, || path().field("source"), report); + source_validate( + &self.primary_source(), + root, + || path().field("source"), + report, + ); } }