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

Using images or materials for shape fill #190

Open
rockerBOO opened this issue Dec 4, 2022 · 9 comments
Open

Using images or materials for shape fill #190

rockerBOO opened this issue Dec 4, 2022 · 9 comments

Comments

@rockerBOO
Copy link

rockerBOO commented Dec 4, 2022

I am wanting to use an image as a fill for polygons and paths. I can't seem to pin down how I would apply this to results from GeometryBuilder::build_as or using ShapeBundle {} struct

    let shape = shapes::Polygon {
        points: options.points.to_vec(),
        closed: true,
    };

    commands
        .spawn_bundle(GeometryBuilder::build_as(
            &shape,
            DrawMode::Outlined {
                // Would expect I could use a FillMode::image(Handle<Image>) for the fill mode 
                // or FillMode::material(
                //     materials.add(CustomMaterial {
                //       color: Color::RED,
                //       color_texture: asset_server.load("some_image.png"),
                //     })
                // )
                fill_mode: FillMode::color(Color::CYAN),
                outline_mode: StrokeMode::new(Color::BLACK, 0.0),
            },
            Transform::default(),
        ))

Is this possible currently?

Thank you!

@Nilirad
Copy link
Owner

Nilirad commented Dec 5, 2022

It's one of those features that I wanted to implement, but currently I don't want to commit much time into developing new features.

If anybody wants to tackle this, feel free to do it. This issue can also be used to discuss a potential solution.

@rockerBOO
Copy link
Author

Thank you Nilirad! Is this something that lyon can do in its library, or is it something specific that will need to be added to bevy_prototype_lyon to have an image fill? Or is this something with adding the image to the geometry inside bevy_prototype_lyon? The GeometryBuilder makes me think it creates a mesh, so we can apply the material to the mesh?

I wouldn't mind looking into it, but I'm newer to rust/bevy and this library. Need some pointing to areas of interest, if possible.

For instance, I think this is the closest example of a struct that has a material and a mesh2d, MaterialMesh2dBundle. So do we need to add a material to this struct? I can look into this option later.

Thank you!

@Vixeliz
Copy link

Vixeliz commented Jan 28, 2023

Hello I am also interested in this. I'm curious if in the meantime if it would be possible to use the existing mesh2d handle from the created shape in the materialmesh2d bundle. I'm gonna do some testing on how to do this without modifying the library cause I am not at the skill level to do that but I will update here if i find a temporary solutions.

@Vixeliz
Copy link

Vixeliz commented Jan 28, 2023

So after messing around for a bit it seems one of the limiting things is the lack of vertices having uv's but I may be wrong i'm very tired. I'm mildly curious why you use a custom render pipeline? Out of wanting to legitimately learn why wouldn't bevy's default pipeline work? It would probably make it easier to do stuff like materials as well. Just curious honestly same with the custom shader. Either way awesome library!

@Nilirad
Copy link
Owner

Nilirad commented Jan 28, 2023

I don't exactly remember why I initially chose to use a custom render pipeline. Also, a lot of the new rendering code was made by @rparrett after the initial release.

A lot of things have changed, both on bevy and lyon, since I created this crate, so it may be possible that a simpler solution would work.

@Vixeliz
Copy link

Vixeliz commented Jan 28, 2023

Maybe I will mess around trying to use the standard bevy pipeline in a fork.

@Vixeliz
Copy link

Vixeliz commented Jan 28, 2023

I have been messing for a few hours and I don't think I'm familiar enough with bevys render pipeline yet to do this myself but I may tackle it again in the future.

@rparrett
Copy link
Contributor

I don't exactly remember why I initially chose to use a custom render pipeline. Also, a lot of the new rendering code was made by rparrett after the initial release.

I think it may have been necessary at some point in the past in order to use vertex colors. I'd guess that it's not necessary anymore and you could just use a MaterialMesh2d.

Another obstacle might be supporting DrawMode::Outlined properly, since both the fill and stroke share the same mesh/entity.

@robert-e-davidson3
Copy link

Any chance of this happening? It would solve my current problem very nicely.

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

5 participants