Skip to content

Commit

Permalink
complete gltf structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Dec 10, 2020
1 parent 230ada7 commit c559126
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 106 deletions.
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ impl<'a> LoadContext<'a> {
self.labeled_assets.insert(None, asset);
}

pub fn set_labeled_asset(&mut self, label: &str, asset: LoadedAsset) {
pub fn set_labeled_asset<T: Asset>(&mut self, label: &str, asset: LoadedAsset) -> Handle<T> {
assert!(!label.is_empty());
self.labeled_assets.insert(Some(label.to_string()), asset);
self.get_handle(AssetPath::new_ref(self.path(), Some(label)))
}

pub fn get_handle<I: Into<HandleId>, T: Asset>(&self, id: I) -> Handle<T> {
Expand Down
33 changes: 25 additions & 8 deletions crates/bevy_gltf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ mod loader;
pub use loader::*;

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

/// Adds support for GLTF file loading to Apps
#[derive(Default)]
Expand All @@ -11,27 +15,40 @@ pub struct GltfPlugin;
impl Plugin for GltfPlugin {
fn build(&self, app: &mut AppBuilder) {
app.init_asset_loader::<GltfLoader>()
.add_asset::<Gltf>()
.add_asset::<GltfNode>()
.add_asset::<GltfPrimitive>()
.add_asset::<GltfMesh>();
}
}

#[derive(Debug, Clone, bevy_reflect::TypeUuid)]
#[derive(Debug, TypeUuid)]
#[uuid = "5c7d5f8a-f7b0-4e45-a09e-406c0372fea2"]
pub struct Gltf {
pub scenes: Vec<Handle<Scene>>,
pub meshes: Vec<Handle<GltfMesh>>,
pub materials: Vec<Handle<StandardMaterial>>,
pub nodes: Vec<Handle<GltfNode>>,
pub default_scene: Option<Handle<Scene>>,
}

#[derive(Debug, Clone, TypeUuid)]
#[uuid = "dad74750-1fd6-460f-ac51-0a7937563865"]
pub struct GltfNode {
pub children: Vec<usize>,
pub mesh: Option<usize>,
pub children: Vec<GltfNode>,
pub mesh: Option<Handle<GltfMesh>>,
pub transform: bevy_transform::prelude::Transform,
}

#[derive(Debug, Clone, bevy_reflect::TypeUuid)]
#[derive(Debug, Clone, TypeUuid)]
#[uuid = "8ceaec9a-926a-4f29-8ee3-578a69f42315"]
pub struct GltfMesh {
pub primitives: Vec<GltfPrimitive>,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, TypeUuid)]
#[uuid = "cbfca302-82fd-41cb-af77-cab6b3d50af1"]
pub struct GltfPrimitive {
index: usize,
material: Option<usize>,
pub mesh: Handle<Mesh>,
pub material: Option<Handle<StandardMaterial>>,
}
Loading

0 comments on commit c559126

Please sign in to comment.