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 a Lyon Path in a GeometryBuilder results in a panic #109

Open
db48x opened this issue Jul 27, 2021 · 3 comments
Open

using a Lyon Path in a GeometryBuilder results in a panic #109

db48x opened this issue Jul 27, 2021 · 3 comments

Comments

@db48x
Copy link

db48x commented Jul 27, 2021

The resulting Mesh has a Vertex_Position attribute, but not a Vertex_Position_2D attribute:

[src/main.rs:70] meshes.get(&trail.mesh).unwrap() = Mesh {
    primitive_topology: TriangleList,
    attributes: {
        "Vertex_Normal": Float3([ … ]),
        "Vertex_Position": Float3([ … ]),
        "Vertex_Uv": Float2([ … ]),
    }
    indices: Some(U32([ … ])),
}
thread 'Compute Task Pool (4)' panicked at 'Attribute Vertex_Position_2D is required by shader, but not supplied by mesh. Either remove the attribute from the shader or supply the attribute (Vertex_Position_2D) to the mesh.', /home/db48x/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_render-0.5.0/src/pipeline/pipeline_compiler.rs:231:17
@db48x
Copy link
Author

db48x commented Jul 27, 2021

Though I suppose I could be doing something wrong. Perhaps we could work on an example with a system that modifies the shape that gets drawn?

@Nilirad
Copy link
Owner

Nilirad commented Jul 28, 2021

bevy_prototype_lyon uses custom shaders with custom attributes. If you remove the Vertex_Normal attribute and change the Vertex_Position attribute with Vertex_Position_2D (it is a Float2) it may work. Also, the shader accepts also a Vertex_Color attribute.

You can also draw paths using the PathBuilder API or by implementing Geometry on a custom struct.

@db48x
Copy link
Author

db48x commented Jul 28, 2021

Yea, I was trying to use PathBuilder. However, I think the code was going wrong somehow. I think it was building the path correctly, but then retrieving the wrong mesh from somewhere and attempting to use it. Here’s the code I wrote:

fn trail_system(mut commands: Commands,
                mut meshes: ResMut<Assets<Mesh>>,
                mut q: Query<(Entity, &mut Trail, &mut Transform, &mut Handle<Mesh>)>) {
    for (e, mut tr, p, mut h) in q.iter_mut() {
        //dbg!(meshes.get_mut(&*h).unwrap());
        //dbg!(&h);
        //todo!();
        if tr.path.len() >= 32 {
            tr.path.resize(32, Vec3::new(f32::NAN, f32::NAN, f32::NAN));
        }
        tr.path.insert(0, p.translation);

        let mut geometry = GeometryBuilder::new();
        let mut path = PathBuilder::new();
        let points = tr.path.iter();
        path.move_to(Vec2::new(0.0, 0.0));
        for &p1 in points {
            let p1 = Vec2::from(p1 - p.translation);
            path.line_to(p1);
        }
        geometry.add(&path.build());
        geometry.add(&shapes::Circle {
            radius: 2.0,
            center: Vec2::ZERO,
        });
        let trail = geometry.build(
            ShapeColors::new(Color::RED),
            DrawMode::Fill(FillOptions::DEFAULT),
            *p,
        );
        //let mesh = meshes.get_mut(dbg!(&trail.mesh)).unwrap();
        //let vertices = mesh.attribute_mut(Mesh::ATTRIBUTE_POSITION);
        //if let Some(bevy::render::mesh::VertexAttributeValues::Float3(vs)) = vertices {
        //    let mut new_vs: Vec<[f32; 2]> = Vec::with_capacity(vs.len());
        //    let mut new_colors: Vec<[f32; 4]> = Vec::with_capacity(vs.len());
        //    for v in vs {
        //        new_vs.push(v[0..2].try_into().expect("!"));
        //        new_colors.push([1.0, 0.0, 1.0, 1.0]);
        //    }
        //    const ATTRIBUTE_POSITION_2D: &str = "Vertex_Position_2D";
        //    mesh.set_attribute(ATTRIBUTE_POSITION_2D, new_vs);
        //    mesh.set_attribute(Mesh::ATTRIBUTE_COLOR, new_colors);
        //}
        //dbg!(&mesh);
        *h = trail.mesh;
        //commands.entity(e).insert_bundle(trail);
        //todo!();
    }
}

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

2 participants