Nilirad / bevy_prototype_lyon

Draw 2D shapes in Bevy
Apache License 2.0
702 stars 87 forks source link

Rough curves with fixed camera scaling mode #192

Closed Pascualex closed 1 year ago

Pascualex commented 1 year ago

I'm currently configuring my camera with ScalingMode::FixedVertical, like so:

commands.spawn(Camera2dBundle {
    projection: OrthographicProjection {
        scaling_mode: ScalingMode::FixedVertical(20.0),
        ..default()
    },
    ..default()
});

I do this because I want to use distance units for my transforms and not pixels. It also makes the experience more consistent between screens with different pixel densities.

The problem is that bevy_prototype_lyon doesn't seem to support this configuration. Now, when I spawn a circle with radius 1 the edges are so rough that I can even count the number of edges (8).

let shape = shapes::Circle {
    radius: 1.0,
    ..default()
};
commands.spawn(GeometryBuilder::build_as(
    &shape,
    DrawMode::Fill(FillMode::color(Color::BLACK)),
    Transform::default(),
));
rparrett commented 1 year ago

You can configure lyon to work better with your scale with FillOptions and StrokeOptions.

let shape = shapes::Circle {
    radius: 1.0,
    ..default()
};
commands.spawn(GeometryBuilder::build_as(
    &shape,
    DrawMode::Fill(FillMode {
        options: FillOptions::tolerance(0.01),
        color: Color::BLACK,
    }),
    Transform::default(),
));
Pascualex commented 1 year ago

Sounds great, thanks for the pointer.

The ideal solution would be dynamic based on the viewport size. But my understanding is that the path generated by the circle is defined at creation and static.

At least this will mitigate the issue.