Nilirad/bevy_prototype_lyon

Using images or materials for shape fill

rockerBOO opened this issue · 8 comments

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!

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.

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!

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.

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!

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.

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

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.

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.