You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This was discussed on Zulip, but isn't being actively worked on at the moment, so opening a tracking issue with @leudz blessing. I have no idea how difficult it would be to add this, might be super hard!
Motivation:
Let's say we're building a renderer where we don't know all the possible variants of the meshes/materials, but we do know they satisfy a certain interface. It would be wonderful to do something like this:
pub fn render_sys(renderer: ViewMut<MyRenderer>, meshes: TraitView<&dyn Mesh>, materials: TraitView<&dyn Material>) {
for (mesh, material) in (&meshes, &materials).iter() {
// assume Mesh is a trait with a draw() method
// that takes a context like OpenGl / WebGPU /etc.
// and a &dyn Material
mesh.draw(&mut renderer.context, material);
}
}
This is doable without any heap allocation in an application by having the Mesh/Material be enums, though this requires all the variants be defined in a rigid manner.
If the above renderer were used as a library, then downstream code could merely add Mesh and Material components that satisfy the trait. Much more flexible!
This was discussed on Zulip, but isn't being actively worked on at the moment, so opening a tracking issue with @leudz blessing. I have no idea how difficult it would be to add this, might be super hard!
Motivation:
Let's say we're building a renderer where we don't know all the possible variants of the meshes/materials, but we do know they satisfy a certain interface. It would be wonderful to do something like this:
This is doable without any heap allocation in an application by having the Mesh/Material be enums, though this requires all the variants be defined in a rigid manner.
If the above renderer were used as a library, then downstream code could merely add Mesh and Material components that satisfy the trait. Much more flexible!
Prior art:
https://github.com/BoxyUwU/bevy_unofficial_trait_queries
The text was updated successfully, but these errors were encountered: