feat(gltf): add name component to gltf mesh primitive#13912
feat(gltf): add name component to gltf mesh primitive#13912alice-i-cecile merged 6 commits intobevyengine:mainfrom
Conversation
|
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
b4270d9 to
d3cbf42
Compare
alice-i-cecile
left a comment
There was a problem hiding this comment.
Useful, but I this should just use the standard Bevy Name component. That reduces the code that we have to maintain, and will play nicer with various tooling like bevy_inspector_egui.
I'm also having a hard time figuring out how the example demonstrates the added functionality. Can you explain what you were after? I may be able to suggest how to make things clearer.
Hi Alice, I apologize for the confusion caused by the buggy example {
"meshes": [
{
"name": "Cube",
"primitives": [
{
"attributes": { "POSITION": 0, "NORMAL": 1, "TEXCOORD_0": 2 },
"indices": 3,
"material": 0
},
{
"attributes": { "POSITION": 4, "NORMAL": 5, "TEXCOORD_0": 6 },
"indices": 7,
"material": 1
},
{
"attributes": { "POSITION": 8, "NORMAL": 9, "TEXCOORD_0": 10 },
"indices": 11,
"material": 2
},
{
"attributes": { "POSITION": 12, "NORMAL": 13, "TEXCOORD_0": 14 },
"indices": 15,
"material": 3
}
]
}
]
}
In bevy, each primitive is named according to its index. // crates/bevy_gltf/src/loader.rs
fn primitive_name(mesh: &gltf::Mesh, primitive: &Primitive) -> String {
let mesh_name = mesh.name().unwrap_or("Mesh");
if mesh.primitives().len() > 1 {
format!("{}.{}", mesh_name, primitive.index())
} else {
mesh_name.to_string()
}
}This causes a problem, which is addressed by @MatrixDev in the above issue:
So it appears useful to name each primitive according to its associated material, given that primitives are distinguished based on the number of materials assigned to a single mesh. However, since some may rely on the indexed names stored in the |
|
I think using 'Name' for everything is not enough. Entity can have a GLTF node/primitive name/index and material name/index all at the same time. We should be able to query using any of those at any time. Sometimes I want to query for all entities with a specific material, other times I'd like to query for all entities with a specific primitive. Names of materials and primitives might be different. I'm not even talking about bevy generating names for entites when nodes contain multiple primitives. |
|
Right 🤔 Okay, I see your point. Thank you for explaining! |
alice-i-cecile
left a comment
There was a problem hiding this comment.
I think I'm on board now, but there's some work to be done to make this clearer and more beginner friendly.
|
I have improved the documentation, corrected capitalization errors, and optimized the code of the |
|
Fantastic, thank you! |
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
# Objective - fixes bevyengine#13473 ## Solution - When a single mesh is assigned multiple materials, it is divided into several primitive nodes, with each primitive assigned a unique material. Presently, these primitives are named using the format Mesh.index, which complicates querying. To improve this, we can assign a specific name to each primitive based on the material’s name, since each primitive corresponds to one material exclusively. ## Testing - I have included a simple example which shows how to query a material and mesh part based on the new name component. ## Changelog - adds `GltfMaterialName` component to the mesh entity of the gltf primitive node. --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
|
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1703 if you'd like to help out. |
Objective
Solution
Testing
Changelog
GltfMaterialNamecomponent to the mesh entity of the gltf primitive node.