Skip to content
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

feature request: TraitView #145

Open
dakom opened this issue Jul 24, 2022 · 0 comments
Open

feature request: TraitView #145

dakom opened this issue Jul 24, 2022 · 0 comments

Comments

@dakom
Copy link
Contributor

dakom commented Jul 24, 2022

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!

Prior art:

https://github.com/BoxyUwU/bevy_unofficial_trait_queries

@dakom dakom changed the title feature request: TraitVIew feature request: TraitView Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant