Path: blob/main/crates/bevy_gltf/src/loader/extensions/khr_materials_anisotropy.rs
9533 views
use bevy_asset::{AssetPath, Handle};1use bevy_image::Image;23use gltf::Material;45use serde_json::Value;67#[cfg(feature = "pbr_anisotropy_texture")]8use {crate::loader::gltf_ext::material::parse_material_extension_texture, bevy_mesh::UvChannel};910/// Parsed data from the `KHR_materials_anisotropy` extension.11///12/// See the specification:13/// <https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_anisotropy/README.md>14#[derive(Default)]15pub(crate) struct AnisotropyExtension {16pub(crate) anisotropy_strength: Option<f64>,17pub(crate) anisotropy_rotation: Option<f64>,18#[cfg(feature = "pbr_anisotropy_texture")]19pub(crate) anisotropy_channel: UvChannel,20#[cfg(feature = "pbr_anisotropy_texture")]21pub(crate) anisotropy_texture: Option<Handle<Image>>,22}2324impl AnisotropyExtension {25#[expect(26clippy::allow_attributes,27reason = "`unused_variables` is not always linted"28)]29#[allow(30unused_variables,31reason = "Depending on what features are used to compile this crate, certain parameters may end up unused."32)]33pub(crate) fn parse(34material: &Material,35textures: &[Handle<Image>],36asset_path: AssetPath<'_>,37) -> Option<AnisotropyExtension> {38let extension = material39.extensions()?40.get("KHR_materials_anisotropy")?41.as_object()?;4243#[cfg(feature = "pbr_anisotropy_texture")]44let (anisotropy_channel, anisotropy_texture) = parse_material_extension_texture(45material,46extension,47"anisotropyTexture",48"anisotropy",49textures,50asset_path,51);5253Some(AnisotropyExtension {54anisotropy_strength: extension.get("anisotropyStrength").and_then(Value::as_f64),55anisotropy_rotation: extension.get("anisotropyRotation").and_then(Value::as_f64),56#[cfg(feature = "pbr_anisotropy_texture")]57anisotropy_channel,58#[cfg(feature = "pbr_anisotropy_texture")]59anisotropy_texture,60})61}62}636465