Skip to content

Commit

Permalink
Add extras to node, mesh and primitive
Browse files Browse the repository at this point in the history
  • Loading branch information
alradish committed Jan 22, 2023
1 parent 12fbea3 commit 0598aad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
11 changes: 7 additions & 4 deletions crates/bevy_gltf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub struct Gltf {
pub named_animations: HashMap<String, Handle<AnimationClip>>,
}

/// A glTF node with all of its child nodes, its [`GltfMesh`] and
/// [`Transform`](bevy_transform::prelude::Transform).
/// A glTF node with all of its child nodes, its [`GltfMesh`],
/// [`Transform`](bevy_transform::prelude::Transform) and an optional [`GltfExtras`].
#[derive(Debug, Clone, TypeUuid)]
#[uuid = "dad74750-1fd6-460f-ac51-0a7937563865"]
pub struct GltfNode {
Expand All @@ -58,19 +58,22 @@ pub struct GltfNode {
pub extras: Option<GltfExtras>,
}

/// A glTF mesh, which may consist of multiple [`GltfPrimitives`](GltfPrimitive).
/// A glTF mesh, which may consist of multiple [`GltfPrimitives`](GltfPrimitive)
/// and an optional [`GltfExtras`].
#[derive(Debug, Clone, TypeUuid)]
#[uuid = "8ceaec9a-926a-4f29-8ee3-578a69f42315"]
pub struct GltfMesh {
pub primitives: Vec<GltfPrimitive>,
pub extras: Option<GltfExtras>,
}

/// Part of a [`GltfMesh`] that consists of a [`Mesh`] and an optional [`StandardMaterial`].
/// Part of a [`GltfMesh`] that consists of a [`Mesh`], an optional [`StandardMaterial`] and [`GltfExtras`].
#[derive(Debug, Clone, TypeUuid)]
#[uuid = "cbfca302-82fd-41cb-af77-cab6b3d50af1"]
pub struct GltfPrimitive {
pub mesh: Handle<Mesh>,
pub material: Option<Handle<StandardMaterial>>,
pub material_extras: Option<GltfExtras>,
}

#[derive(Clone, Debug, Reflect, Default, Component)]
Expand Down
19 changes: 12 additions & 7 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,20 @@ async fn load_gltf<'a, 'b>(
.material()
.index()
.and_then(|i| materials.get(i).cloned()),
material_extras: primitive.extras().as_ref().map(|extras| super::GltfExtras {
value: extras.get().to_string(),
}),
});
}

let handle = load_context.set_labeled_asset(
&mesh_label(&mesh),
LoadedAsset::new(super::GltfMesh { primitives }),
LoadedAsset::new(super::GltfMesh {
primitives,
extras: mesh.extras().as_ref().map(|extras| super::GltfExtras {
value: extras.get().to_string(),
}),
}),
);
if let Some(name) = mesh.name() {
named_meshes.insert(name.to_string(), handle.clone());
Expand Down Expand Up @@ -368,12 +376,9 @@ async fn load_gltf<'a, 'b>(
scale: bevy_math::Vec3::from(scale),
},
},
extras: node
.mesh()
.and_then(|mesh| mesh.extras().as_ref())
.map(|extras| super::GltfExtras {
value: extras.get().to_string(),
}),
extras: node.extras().as_ref().map(|extras| super::GltfExtras {
value: extras.get().to_string(),
}),
},
node.children()
.map(|child| child.index())
Expand Down

0 comments on commit 0598aad

Please sign in to comment.