Skip to content

Commit d54e44f

Browse files
authored
gltf: let extension handle late-added materials (#22858)
# Objective - #22569 broke some examples, some materials are not displayed ## Solution - Some materials are added late because we modify them depending on how they're used (for example, with an inverted scale). Also triggers extensions on those ## Testing examples `light_probe_blending`, `irradiance_volumes`, `pccm`, `pcss` are now fixed
1 parent dea15b6 commit d54e44f

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

  • crates/bevy_gltf/src/loader

crates/bevy_gltf/src/loader/mod.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,21 +1600,30 @@ fn load_node(
16001600
let mat_label = material_label(&material, is_scale_inverted);
16011601
let material_label = mat_label.to_string();
16021602

1603-
// This will make sure we load the default material now since it would not have been
1604-
// added when iterating over all the gltf materials (since the default material is
1605-
// not explicitly listed in the gltf).
1606-
// It also ensures an inverted scale copy is instantiated if required.
1603+
// This adds materials that Bevy modifies depending on how they're used, like those with inverted scale.
16071604
if !root_load_context.has_labeled_asset(&material_label)
16081605
&& !load_context.has_labeled_asset(&material_label)
16091606
{
1610-
let (label, material) = load_material(
1607+
let (label, gltf_material) = load_material(
16111608
&material,
16121609
textures,
16131610
is_scale_inverted,
16141611
load_context.path().clone(),
16151612
);
16161613
// TODO: maybe move this into `load_material` ?
1617-
load_context.add_labeled_asset(label, material);
1614+
let handle =
1615+
load_context.add_labeled_asset(label.clone(), gltf_material.clone());
1616+
1617+
// let extensions handle material data
1618+
for extension in extensions.iter_mut() {
1619+
extension.on_material(
1620+
load_context,
1621+
&material,
1622+
handle.clone(),
1623+
&gltf_material,
1624+
&label.clone(),
1625+
);
1626+
}
16181627
}
16191628

16201629
let primitive_label = GltfAssetLabel::Primitive {

0 commit comments

Comments
 (0)