-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use material name for mesh entity's Name when available #19287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It looks like your PR is a breaking change, but you didn't provide a migration guide. Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes. |
I've tagged this as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL that we're spawning the materials as their own entities 🤔 Given that, this is reasonable behavior. Migration guide needs a bit of an editing pass; I'll do my best to fix it in suggestions.
release-content/release-notes/rename_spawn_gltf_material_name.md
Outdated
Show resolved
Hide resolved
release-content/release-notes/rename_spawn_gltf_material_name.md
Outdated
Show resolved
Hide resolved
I would also prefer if we had some sort of marker like |
Co-authored-by: Alice Cecile <[email protected]>
This might be a misunderstanding? At least there's no entity that contains a material on its own. The entity named in this PR corresponds to a gltTF primitive, so it contains This situation is always going to be a bit confusing because the Bevy notion of "mesh" doesn't match glTF's. I suspect a longer term improvement is to have a distinct |
When generating gltf in bevy, each material will have its own entity, and different mesh parts only belong to this material entity. According to the current situation, I think it is reasonable to display the material name. I think this might improve once we have our own editor, maybe in the bevy editor gltf will have its own display? |
I'd agree that displaying the material name in inspectors is reasonable, particularly when a mesh has multiple materials. But after looking at this some more I think it's likely to break users who are using the name to find entities in code. But maybe that can be fixed by adding some more data. Say there's a glTF that has a node named "fox", which has a mesh named "fox_mesh", which is a single primitive with a material named "fox_material". That gets turned into two entities:
Before this PR the primitive entity would have been named "fox_mesh". After this PR, it will be named "fox_material". There won't be anything named "fox_mesh". I don't think there's a simple and intuitive solution to this as Bevy's entity structure just doesn't match the glTF hierarchy. The least worst solution might be to add a new component to the primitive entity: struct GltfPrimitiveComponent {
mesh_name: String,
index: usize
} That way this PR can stay the same - the Name component can still change to be the material name. But the migration guide is "if you were searching for the mesh by If this PR lands as-is then I can do a follow up PR to pitch adding |
After digging a bit more I think Related: #13473, which has some more background and originally pitched |
I think the name can be changed to MeshName.MaterialName |
I also need to test the results in different situations |
MeshName.MaterialName makes sense to me as an inspection friendly name. |
Could also consider MeshName.MaterialName if a mesh has multiple primitives, and MeshName if it only has a single primitive. That keeps some backwards compatibility. |
Use both mesh name and material name in the entity name component instead of just using material name or primitive index. This makes entities more identifiable in inspector tools with format "MeshName.MaterialName".
If there is no material, it will keep MeshName. If there is a material, it will still use MeshName.MaterialName |
Thanks for your review, showing MeshName.MaterialName is definitely a better choice than just showing MaterialName |
release-content/migration-guides/rename_spawn_gltf_material_name.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me once the markdown passes CI.
I'll look into following up with a PR that adds GltfMeshName
. This will affect the migration guide as users should probably prefer that component - Name
would be just for debugging/inspection.
I think the usage rate of GltfMeshName should not be very high. Users usually don't modify Mesh, but the probability of modifying Material is still quite high. Usually there is no need to check the name of Mesh, because there is only one Mesh name in Gltf. Even if you want to modify Mesh, you have to look for it according to the name of GltfMaterialName. |
My guess is that some users with single primitive meshes will have been using the mesh name to find the material. While they could switch to using GltfMaterialName, adding a distinct mesh name would make upgrading easier for them. |
Side effects appeared haha, now I think what you said makes a lot of sense, I decided to add GltfMeshNam |
Stores mesh names from glTF files in GltfMeshName component rather than Name component, making both GltfMeshName and GltfMaterialName behave like strings via Deref. # Objective Fixed the side effects of #19287 Fixes Examples that modify gltf materials are broken #19322 ## Solution Add GltfMeshName component and Deref implementations Stores mesh names from glTF files in GltfMeshName component rather than Name component, making both GltfMeshName and GltfMaterialName behave like strings via Deref. ## Testing cargo run --example depth_of_field cargo run --example lightmaps cargo run --example mixed_lighting They are consistent with the situation before the error occurred. --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Rob Parrett <[email protected]>
Objective
Fixes #19286
Solution
Use material name for mesh entity's Name when available
Testing
Test code, modified from examples/load_gltf.rs
Showcase
Run log:
