Comments (8)
I have the same issue. I found that Z ordering is arbitrary with these shapes. I ran the same program several times without any changes and the ordering changed.
from bevy_prototype_lyon.
In my experience this is not true. With this little system I can always make sure the orange line is drawn over the blue line.
fn setup_paint(mut cmd: Commands) {
cmd.spawn_bundle(Camera2dBundle::default());
let options = StrokeOptions::default().with_line_width(LINE_WIDTH);
let mut path_builder = PathBuilder::new();
path_builder.move_to(Vec2::ZERO);
path_builder.line_to(100.0 * Vec2::ONE);
let line = path_builder.build();
cmd.spawn_bundle(GeometryBuilder::build_as(&line, DrawMode::Stroke(StrokeMode{color:Color::BLUE, options}), Transform::from_translation(Vec3::new(0.0, 0.0, 1.0))));
cmd.spawn_bundle(GeometryBuilder::build_as(&line, DrawMode::Stroke(StrokeMode{color:Color::ORANGE, options}), Transform::from_translation(Vec3::new(0.0, 0.0, 4.0))));
}
Also from reading the code in src/rendering/mod.rs
it states that it does:
transparent_phase.add(Transparent2d {
entity: *visible_entity,
draw_function: draw_shape,
pipeline: pipeline_id,
// The 2d render items are sorted according to their z value before rendering,
// in order to get correct transparency
sort_key: FloatOrd(mesh_z),
// This material is not batched
batch_range: None,
});
and the vertex shader just uses the z position of the clip_position
.
I was confused myself about this because I was trying negative values for z which don't show at all. I think this is confusion between how z buffer and depth buffer work.
Please feel free to create an example if you see other behaviour.
from bevy_prototype_lyon.
I've also got this same problem. In the game I'm working on I've got 2 entities, one for the player and another for the base station (spawn point essentially). The ordering of these being drawn is non deterministic and the z-index seems to be disregarded. My repository https://github.com/andrewexton373/geometry-wars is an example of this problem occurring, and the gif in the README shows the non deterministic ordering results when the player is over the base.
let base_station = commands.spawn()
.insert_bundle(lyon::GeometryBuilder::build_as(
&base_shape,
lyon::DrawMode::Outlined {
fill_mode: lyon::FillMode::color(Color::MIDNIGHT_BLUE),
outline_mode: lyon::StrokeMode::new(Color::WHITE, 5.0),
},
Transform { translation: Vec3::new(0.0, 0.0, -100.0), ..Default::default() }
))
let player = commands.spawn()
.insert(Player::new())
.insert_bundle(lyon::GeometryBuilder::build_as(
&player_shape,
lyon::DrawMode::Outlined {
fill_mode: lyon::FillMode::color(Color::CYAN),
outline_mode: lyon::StrokeMode::new(Color::WHITE, 2.0),
},
Transform {
translation: Vec3::new(0.0, 0.0, 100.0),
..Default::default()
}
))
from bevy_prototype_lyon.
Interesting, I remember playing around with the depth/z value and I found/(remember) that negative values don't work.
Could you try with only positive values.
from bevy_prototype_lyon.
Just tried it with 10.0 for the player and 100.0 for the base. Still have the issue with these z values.
from bevy_prototype_lyon.
I saw this snippet in the code, so it seems like the z-index should already be taken into account for rendering:
transparent_phase.add(Transparent2d {
entity: *visible_entity,
draw_function: draw_shape,
pipeline: pipeline_id,
// The 2d render items are sorted according to their z value before rendering,
// in order to get correct transparency
sort_key: FloatOrd(mesh_z),
// This material is not batched
batch_range: None,
});
I'm not sure if there's a bug here or somewhere related. I'll try and reproduce the issue in a simpler project.
from bevy_prototype_lyon.
I wasn't able to reproduce the issue by modifying your dynamic shape example to have 2 overlapping shapes, so now I'm beginning to think it might have something to do with my use of rapier2d in conjunction with this project that's introducing the issue?
from bevy_prototype_lyon.
I'm not entirely sure here, but I was able to solve this in a hacky way by making a system to force set the player Transform's Z to be above the shape I was clipping with. I think rapier2d may have been setting the Transform's Z unknowingly and I discovered that with the bevy_inspector_egui. Here's the system I used:
// FIXME: is this really the only way? I feel like rapier2d is messing with the z-value...
fn keep_player_on_top(
mut player_query: Query<(&mut Player, &mut Transform), (With<Player>, Without<Crosshair>)>
) {
for (player, mut transform) in player_query.iter_mut() {
transform.translation.z = 100.0;
}
}
from bevy_prototype_lyon.
Related Issues (20)
- Can't draw paths or polygons HOT 1
- Using images or materials for shape fill HOT 8
- Rough curves with fixed camera scaling mode HOT 2
- More const support
- Support for rounded polygons HOT 4
- Dyanmic shapes example does not compile HOT 5
- Docs.rs still shows 0.7.2 as latest version HOT 2
- Why aren't `Fill` and `Stroke` housed in `ShapeBundle`? HOT 2
- WebGL: INVALID_OPERATION on entity despawn on wasm target HOT 4
- Changing the Path does not redraw the mesh
- Expected bevy_render::color::Color, found bevy::prelude::Color HOT 2
- How do I use this with UI? HOT 1
- Difference between `ShapePath` and `GeometryBuilder`?
- Apply transformation to individual shape
- Bevy tracking link in README badge is broken HOT 1
- How to draw with Hatching for dashed/dotted lines?
- Way to draw gradient colors
- Apply initial geometry transform HOT 1
- Bevy 0.13 HOT 1
- RegularPolygon into Polygon to access Vertices
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bevy_prototype_lyon.