Skip to content

Commit

Permalink
expose extras from gltf nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Jul 3, 2021
1 parent b52edc1 commit 5d72d2a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bevy_scene = { path = "../bevy_scene", version = "0.5.0" }
bevy_log = { path = "../bevy_log", version = "0.5.0" }

# other
gltf = { version = "0.16.0", default-features = false, features = ["utils", "names", "KHR_materials_unlit"] }
gltf = { version = "0.16.0", default-features = false, features = ["utils", "names", "KHR_materials_unlit", "extras"] }
thiserror = "1.0"
anyhow = "1.0"
base64 = "0.13.0"
Expand Down
10 changes: 9 additions & 1 deletion crates/bevy_gltf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ pub use loader::*;

use bevy_app::prelude::*;
use bevy_asset::{AddAsset, Handle};
use bevy_ecs::reflect::ReflectComponent;
use bevy_pbr::prelude::StandardMaterial;
use bevy_reflect::TypeUuid;
use bevy_reflect::{Reflect, TypeUuid};
use bevy_render::mesh::Mesh;
use bevy_scene::Scene;

Expand All @@ -17,6 +18,7 @@ pub struct GltfPlugin;
impl Plugin for GltfPlugin {
fn build(&self, app: &mut AppBuilder) {
app.init_asset_loader::<GltfLoader>()
.register_type::<GltfExtras>()
.add_asset::<Gltf>()
.add_asset::<GltfNode>()
.add_asset::<GltfPrimitive>()
Expand Down Expand Up @@ -58,3 +60,9 @@ pub struct GltfPrimitive {
pub mesh: Handle<Mesh>,
pub material: Option<Handle<StandardMaterial>>,
}

#[derive(Debug, Reflect, Default)]
#[reflect(Component)]
pub struct GltfExtras {
pub value: String,
}
6 changes: 6 additions & 0 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ fn load_node(
node.insert(Name::new(name.to_string()));
}

if let Some(extras) = gltf_node.extras() {
node.insert(super::GltfExtras {
value: extras.get().to_string(),
});
}

// create camera node
if let Some(camera) = gltf_node.camera() {
node.insert(VisibleEntities {
Expand Down

0 comments on commit 5d72d2a

Please sign in to comment.