Skip to content

Commit

Permalink
Change as_gltf_extras to be a implementation of from on `GltfExtras…
Browse files Browse the repository at this point in the history
…` of `bevy_gltf`
  • Loading branch information
hukasu committed Feb 26, 2025
1 parent 51db9ed commit bc3ec3e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
8 changes: 8 additions & 0 deletions crates/bevy_gltf/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ pub struct GltfExtras {
pub value: String,
}

impl From<&serde_json::value::RawValue> for GltfExtras {
fn from(value: &serde_json::value::RawValue) -> Self {
GltfExtras {
value: value.get().to_string(),
}
}
}

/// Additional untyped data that can be present on most glTF types at the scene level.
///
/// See [the relevant glTF specification section](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-extras).
Expand Down
9 changes: 0 additions & 9 deletions crates/bevy_gltf/src/loader/gltf_ext/extras.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/bevy_gltf/src/loader/gltf_ext/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Methods to access information from [`gltf`] types
pub mod extras;
pub mod material;
pub mod mesh;
pub mod scene;
Expand Down
22 changes: 14 additions & 8 deletions crates/bevy_gltf/src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ use crate::{
use self::{
extensions::{AnisotropyExtension, ClearcoatExtension, SpecularExtension},
gltf_ext::{
check_for_cycles,
extras::as_gltf_extras,
get_linear_textures,
check_for_cycles, get_linear_textures,
material::{
alpha_mode, material_label, needs_tangents, uv_channel,
warn_on_differing_texture_transforms,
Expand Down Expand Up @@ -710,12 +708,20 @@ async fn load_gltf<'a, 'b, 'c>(
.material()
.index()
.and_then(|i| materials.get(i).cloned()),
as_gltf_extras(primitive.extras()),
as_gltf_extras(primitive.material().extras()),
primitive.extras().as_deref().map(GltfExtras::from),
primitive
.material()
.extras()
.as_deref()
.map(GltfExtras::from),
));
}

let mesh = super::GltfMesh::new(&gltf_mesh, primitives, as_gltf_extras(gltf_mesh.extras()));
let mesh = super::GltfMesh::new(
&gltf_mesh,
primitives,
gltf_mesh.extras().as_deref().map(GltfExtras::from),
);

let handle = load_context
.add_labeled_asset(mesh.asset_label().to_string(), mesh)
Expand Down Expand Up @@ -786,7 +792,7 @@ async fn load_gltf<'a, 'b, 'c>(
&skin,
joints,
skinned_mesh_inverse_bindposes[skin.index()].clone(),
as_gltf_extras(skin.extras()),
skin.extras().as_deref().map(GltfExtras::from),
);

let handle = load_context
Expand Down Expand Up @@ -818,7 +824,7 @@ async fn load_gltf<'a, 'b, 'c>(
mesh,
node_transform(&node),
skin,
as_gltf_extras(node.extras()),
node.extras().as_deref().map(GltfExtras::from),
);

#[cfg(feature = "bevy_animation")]
Expand Down

0 comments on commit bc3ec3e

Please sign in to comment.