//! Labels that can be used to load part of a glTF12use bevy_asset::AssetPath;34/// Labels that can be used to load part of a glTF5///6/// You can use [`GltfAssetLabel::from_asset`] to add it to an asset path7///8/// ```9/// # use bevy_ecs::prelude::*;10/// # use bevy_asset::prelude::*;11/// # use bevy_scene::prelude::*;12/// # use bevy_gltf::prelude::*;13///14/// fn load_gltf_scene(asset_server: Res<AssetServer>) {15/// let gltf_scene: Handle<Scene> = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/FlightHelmet/FlightHelmet.gltf"));16/// }17/// ```18///19/// Or when formatting a string for the path20///21/// ```22/// # use bevy_ecs::prelude::*;23/// # use bevy_asset::prelude::*;24/// # use bevy_scene::prelude::*;25/// # use bevy_gltf::prelude::*;26///27/// fn load_gltf_scene(asset_server: Res<AssetServer>) {28/// let gltf_scene: Handle<Scene> = asset_server.load(format!("models/FlightHelmet/FlightHelmet.gltf#{}", GltfAssetLabel::Scene(0)));29/// }30/// ```31#[derive(Debug, Clone, Copy, PartialEq, Eq)]32pub enum GltfAssetLabel {33/// `Scene{}`: glTF Scene as a Bevy [`Scene`](bevy_scene::Scene)34Scene(usize),35/// `Node{}`: glTF Node as a [`GltfNode`](crate::GltfNode)36Node(usize),37/// `Mesh{}`: glTF Mesh as a [`GltfMesh`](crate::GltfMesh)38Mesh(usize),39/// `Mesh{}/Primitive{}`: glTF Primitive as a Bevy [`Mesh`](bevy_mesh::Mesh)40Primitive {41/// Index of the mesh for this primitive42mesh: usize,43/// Index of this primitive in its parent mesh44primitive: usize,45},46/// `Mesh{}/Primitive{}/MorphTargets`: Morph target animation data for a glTF Primitive47/// as a Bevy [`Image`](bevy_image::prelude::Image)48MorphTarget {49/// Index of the mesh for this primitive50mesh: usize,51/// Index of this primitive in its parent mesh52primitive: usize,53},54/// `Texture{}`: glTF Texture as a Bevy [`Image`](bevy_image::prelude::Image)55Texture(usize),56/// `Material{}`: glTF Material as a Bevy [`StandardMaterial`](bevy_pbr::StandardMaterial)57Material {58/// Index of this material59index: usize,60/// Used to set the [`Face`](bevy_render::render_resource::Face) of the material,61/// useful if it is used with negative scale62is_scale_inverted: bool,63},64/// `DefaultMaterial`: glTF's default Material as a65/// Bevy [`StandardMaterial`](bevy_pbr::StandardMaterial)66DefaultMaterial,67/// `Animation{}`: glTF Animation as Bevy [`AnimationClip`](bevy_animation::AnimationClip)68Animation(usize),69/// `Skin{}`: glTF mesh skin as [`GltfSkin`](crate::GltfSkin)70Skin(usize),71/// `Skin{}/InverseBindMatrices`: glTF mesh skin matrices as Bevy72/// [`SkinnedMeshInverseBindposes`](bevy_mesh::skinning::SkinnedMeshInverseBindposes)73InverseBindMatrices(usize),74}7576impl core::fmt::Display for GltfAssetLabel {77fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {78match self {79GltfAssetLabel::Scene(index) => f.write_str(&format!("Scene{index}")),80GltfAssetLabel::Node(index) => f.write_str(&format!("Node{index}")),81GltfAssetLabel::Mesh(index) => f.write_str(&format!("Mesh{index}")),82GltfAssetLabel::Primitive { mesh, primitive } => {83f.write_str(&format!("Mesh{mesh}/Primitive{primitive}"))84}85GltfAssetLabel::MorphTarget { mesh, primitive } => {86f.write_str(&format!("Mesh{mesh}/Primitive{primitive}/MorphTargets"))87}88GltfAssetLabel::Texture(index) => f.write_str(&format!("Texture{index}")),89GltfAssetLabel::Material {90index,91is_scale_inverted,92} => f.write_str(&format!(93"Material{index}{}",94if *is_scale_inverted {95" (inverted)"96} else {97""98}99)),100GltfAssetLabel::DefaultMaterial => f.write_str("DefaultMaterial"),101GltfAssetLabel::Animation(index) => f.write_str(&format!("Animation{index}")),102GltfAssetLabel::Skin(index) => f.write_str(&format!("Skin{index}")),103GltfAssetLabel::InverseBindMatrices(index) => {104f.write_str(&format!("Skin{index}/InverseBindMatrices"))105}106}107}108}109110impl GltfAssetLabel {111/// Add this label to an asset path112///113/// ```114/// # use bevy_ecs::prelude::*;115/// # use bevy_asset::prelude::*;116/// # use bevy_scene::prelude::*;117/// # use bevy_gltf::prelude::*;118///119/// fn load_gltf_scene(asset_server: Res<AssetServer>) {120/// let gltf_scene: Handle<Scene> = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/FlightHelmet/FlightHelmet.gltf"));121/// }122/// ```123pub fn from_asset(&self, path: impl Into<AssetPath<'static>>) -> AssetPath<'static> {124path.into().with_label(self.to_string())125}126}127128129