mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 22:50:19 +00:00
a7b99f0500
# Objective Adds support for accessing raw extension data of loaded GLTF assets ## Solution Via the GLTF loader settings, you can specify whether or not to include the GLTF source. While not the ideal way of solving this problem, modeling all of GLTF within Bevy just for extensions adds a lot of complexity to the way Bevy handles GLTF currently. See the example GLTF meta file and code ``` ( meta_format_version: "1.0", asset: Load( loader: "bevy_gltf::loader::GltfLoader", settings: ( load_meshes: true, load_cameras: true, load_lights: true, include_source: true, ), ), ) ``` ```rs pub fn load_gltf(mut commands: Commands, assets: Res<AssetServer>) { let my_gltf = assets.load("test_platform.gltf"); commands.insert_resource(MyAssetPack { spawned: false, handle: my_gltf, }); } #[derive(Resource)] pub struct MyAssetPack { pub spawned: bool, pub handle: Handle<Gltf>, } pub fn spawn_gltf_objects( mut commands: Commands, mut my: ResMut<MyAssetPack>, assets_gltf: Res<Assets<Gltf>>, ) { // This flag is used to because this system has to be run until the asset is loaded. // If there's a better way of going about this I am unaware of it. if my.spawned { return; } if let Some(gltf) = assets_gltf.get(&my.handle) { info!("spawn"); my.spawned = true; // spawn the first scene in the file commands.spawn(SceneBundle { scene: gltf.scenes[0].clone(), ..Default::default() }); let source = gltf.source.as_ref().unwrap(); info!("materials count {}", &source.materials().size_hint().0); info!( "materials ext is some {}", &source.materials().next().unwrap().extensions().is_some() ); } } ``` --- ## Changelog Added support for GLTF extensions through including raw GLTF source via loader flag `GltfLoaderSettings::include_source == true`, stored in `Gltf::source: Option<gltf::Gltf>` ## Migration Guide This will have issues with "asset migrations", as there is currently no way for .meta files to be migrated. Attempting to migrate .meta files without the new flag will yield the following error: ``` bevy_asset::server: Failed to deserialize meta for asset test_platform.gltf: Failed to deserialize asset meta: SpannedError { code: MissingStructField { field: "include_source", outer: Some("GltfLoaderSettings") }, position: Position { line: 9, col: 9 } } ``` This means users who want to migrate their .meta files will have to add the `include_source: true,` setting to their meta files by hand.
57 lines
1.8 KiB
TOML
57 lines
1.8 KiB
TOML
[package]
|
|
name = "bevy_gltf"
|
|
version = "0.12.0"
|
|
edition = "2021"
|
|
description = "Bevy Engine GLTF loading"
|
|
homepage = "https://bevyengine.org"
|
|
repository = "https://github.com/bevyengine/bevy"
|
|
license = "MIT OR Apache-2.0"
|
|
keywords = ["bevy"]
|
|
|
|
[features]
|
|
pbr_transmission_textures = []
|
|
|
|
[dependencies]
|
|
# bevy
|
|
bevy_animation = { path = "../bevy_animation", version = "0.12.0", optional = true }
|
|
bevy_app = { path = "../bevy_app", version = "0.12.0" }
|
|
bevy_asset = { path = "../bevy_asset", version = "0.12.0" }
|
|
bevy_core = { path = "../bevy_core", version = "0.12.0" }
|
|
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.12.0" }
|
|
bevy_ecs = { path = "../bevy_ecs", version = "0.12.0" }
|
|
bevy_hierarchy = { path = "../bevy_hierarchy", version = "0.12.0" }
|
|
bevy_log = { path = "../bevy_log", version = "0.12.0" }
|
|
bevy_math = { path = "../bevy_math", version = "0.12.0" }
|
|
bevy_pbr = { path = "../bevy_pbr", version = "0.12.0" }
|
|
bevy_reflect = { path = "../bevy_reflect", version = "0.12.0", features = [
|
|
"bevy",
|
|
] }
|
|
bevy_render = { path = "../bevy_render", version = "0.12.0" }
|
|
bevy_scene = { path = "../bevy_scene", version = "0.12.0", features = [
|
|
"bevy_render",
|
|
] }
|
|
bevy_transform = { path = "../bevy_transform", version = "0.12.0" }
|
|
bevy_tasks = { path = "../bevy_tasks", version = "0.12.0" }
|
|
bevy_utils = { path = "../bevy_utils", version = "0.12.0" }
|
|
|
|
# other
|
|
gltf = { version = "1.4.0", default-features = false, features = [
|
|
"KHR_lights_punctual",
|
|
"KHR_materials_transmission",
|
|
"KHR_materials_ior",
|
|
"KHR_materials_volume",
|
|
"KHR_materials_unlit",
|
|
"KHR_materials_emissive_strength",
|
|
"extras",
|
|
"extensions",
|
|
"names",
|
|
"utils",
|
|
] }
|
|
thiserror = "1.0"
|
|
base64 = "0.21.5"
|
|
percent-encoding = "2.1"
|
|
serde = { version = "1.0", features = ["derive"] }
|
|
serde_json = "1"
|
|
|
|
[lints]
|
|
workspace = true
|