//! 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 Bevy [`GltfMaterial`](crate::GltfMaterial)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 Material65DefaultMaterial,66/// `Animation{}`: glTF Animation as Bevy [`AnimationClip`](bevy_animation::AnimationClip)67Animation(usize),68/// `Skin{}`: glTF mesh skin as [`GltfSkin`](crate::GltfSkin)69Skin(usize),70/// `Skin{}/InverseBindMatrices`: glTF mesh skin matrices as Bevy71/// [`SkinnedMeshInverseBindposes`](bevy_mesh::skinning::SkinnedMeshInverseBindposes)72InverseBindMatrices(usize),73}7475impl core::fmt::Display for GltfAssetLabel {76fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {77match self {78GltfAssetLabel::Scene(index) => f.write_str(&format!("Scene{index}")),79GltfAssetLabel::Node(index) => f.write_str(&format!("Node{index}")),80GltfAssetLabel::Mesh(index) => f.write_str(&format!("Mesh{index}")),81GltfAssetLabel::Primitive { mesh, primitive } => {82f.write_str(&format!("Mesh{mesh}/Primitive{primitive}"))83}84GltfAssetLabel::MorphTarget { mesh, primitive } => {85f.write_str(&format!("Mesh{mesh}/Primitive{primitive}/MorphTargets"))86}87GltfAssetLabel::Texture(index) => f.write_str(&format!("Texture{index}")),88GltfAssetLabel::Material {89index,90is_scale_inverted,91} => f.write_str(&format!(92"Material{index}{}",93if *is_scale_inverted {94" (inverted)"95} else {96""97}98)),99GltfAssetLabel::DefaultMaterial => f.write_str("DefaultMaterial"),100GltfAssetLabel::Animation(index) => f.write_str(&format!("Animation{index}")),101GltfAssetLabel::Skin(index) => f.write_str(&format!("Skin{index}")),102GltfAssetLabel::InverseBindMatrices(index) => {103f.write_str(&format!("Skin{index}/InverseBindMatrices"))104}105}106}107}108109impl GltfAssetLabel {110/// Add this label to an asset path111///112/// ```113/// # use bevy_ecs::prelude::*;114/// # use bevy_asset::prelude::*;115/// # use bevy_scene::prelude::*;116/// # use bevy_gltf::prelude::*;117///118/// fn load_gltf_scene(asset_server: Res<AssetServer>) {119/// let gltf_scene: Handle<Scene> = asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/FlightHelmet/FlightHelmet.gltf"));120/// }121/// ```122pub fn from_asset(&self, path: impl Into<AssetPath<'static>>) -> AssetPath<'static> {123path.into().with_label(self.to_string())124}125}126127128