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