Repository navigation
Is there an idiomatic way to get a specific StandardMaterial from a given gltf/glb file by name? What about index? #26224
Replies: 2 comments 1 reply
|
Would something like the following work in general? Does calling let Some(inner_gltf) = &gltf.source else {
return;
};
let mut materials_by_name = HashMap::new();
for material in inner_gltf.materials() {
let Some(index) = material.index() else {
continue; // is the DefaultMaterial
};
let Some(name) = material.name() else {
continue; // only looking at named materials
};
let asset_path = format!("{asset_path}#Material{index}/std"); // Seems to be "Material{index}/std" as the label regardless of the material name
let std_material = asset_server.load::<StandardMaterial>(asset_path);
materials_by_name.insert(name, std_material);
} |
|
You don't need the raw let gltf = gltf_assets.get(&gltf_handle).unwrap();
let mat = gltf.named_materials.get("MyMaterial").unwrap();
let index = gltf.materials.iter().position(|h| h == mat).unwrap();
let std_mat = asset_server.load::<StandardMaterial>(format!("{path}#Material{index}/std"));The On 0.20 there is also @hannesojala: yes — |
Uh oh!
There was an error while loading. Please reload this page.
I see there is a vec
materialsand a mapnamed_materialsonGltf, but there does not seem to be a way to convert the resultingGltfMaterialinto aStandardMaterial.I see it is possible to get a material (by what I assume is the index) by doing:
I can't find a way to map that material to a name except by manually inspecting the inner
gltf::Gltf(from the gltf crate).I might just be missing something obvious!
All reactions