Path: blob/main/crates/bevy_gltf/src/loader/gltf_ext/mod.rs
6598 views
//! Methods to access information from [`gltf`] types12pub mod material;3pub mod mesh;4pub mod scene;5pub mod texture;67use bevy_platform::collections::HashSet;89use fixedbitset::FixedBitSet;10use gltf::{Document, Gltf};1112use super::GltfError;1314use self::{material::extension_texture_index, scene::check_is_part_of_cycle};1516#[cfg_attr(17not(target_arch = "wasm32"),18expect(19clippy::result_large_err,20reason = "need to be signature compatible with `load_gltf`"21)22)]23/// Checks all glTF nodes for cycles, starting at the scene root.24pub(crate) fn check_for_cycles(gltf: &Gltf) -> Result<(), GltfError> {25// Initialize with the scene roots.26let mut roots = FixedBitSet::with_capacity(gltf.nodes().len());27for root in gltf.scenes().flat_map(|scene| scene.nodes()) {28roots.insert(root.index());29}3031// Check each one.32let mut visited = FixedBitSet::with_capacity(gltf.nodes().len());33for root in roots.ones() {34let Some(node) = gltf.nodes().nth(root) else {35unreachable!("Index of a root node should always exist.");36};37check_is_part_of_cycle(&node, &mut visited)?;38}3940Ok(())41}4243pub(crate) fn get_linear_textures(document: &Document) -> HashSet<usize> {44let mut linear_textures = HashSet::default();4546for material in document.materials() {47if let Some(texture) = material.normal_texture() {48linear_textures.insert(texture.texture().index());49}50if let Some(texture) = material.occlusion_texture() {51linear_textures.insert(texture.texture().index());52}53if let Some(texture) = material54.pbr_metallic_roughness()55.metallic_roughness_texture()56{57linear_textures.insert(texture.texture().index());58}59if let Some(texture_index) =60extension_texture_index(&material, "KHR_materials_anisotropy", "anisotropyTexture")61{62linear_textures.insert(texture_index);63}6465// None of the clearcoat maps should be loaded as sRGB.66#[cfg(feature = "pbr_multi_layer_material_textures")]67for texture_field_name in [68"clearcoatTexture",69"clearcoatRoughnessTexture",70"clearcoatNormalTexture",71] {72if let Some(texture_index) =73extension_texture_index(&material, "KHR_materials_clearcoat", texture_field_name)74{75linear_textures.insert(texture_index);76}77}78}7980linear_textures81}828384