zheoni / bevy_pixel_buffer Goto Github PK
View Code? Open in Web Editor NEWA library to draw pixels in bevy
License: MIT License
A library to draw pixels in bevy
License: MIT License
I have mostly finished the update, just waiting for bevy_egui
to update.
Perhaps I'm misunderstanding how some of these functions work, but it's hard to tell. Every example uses Frame::per_pixel().
None of these approaches work to set a single Pixel, and I'm not sure why.
fn update(mut pb: QueryPixelBuffer) {
let mut frame = pb.frame();
let pixels = frame.raw_mut();
pixels[12] = Pixel::WHITE;
}
fn update(mut pb: QueryPixelBuffer) {
let mut frame = pb.frame();
frame.set(UVec2::new(3, 2), Pixel::WHITE)
.expect("Error!");
}
fn update(mut pb: QueryPixelBuffer) {
let mut frame = pb.frame();
let pixels = frame.raw_mut();
let pixel = &mut pixels[13];
*pixel = Pixel::WHITE;
}
The only possible way I can find to set pixels without using Frame::per_pixel()
is like this
fn update(mut pb: QueryPixelBuffer) {
let mut frame = pb.frame();
let pixels = frame.raw_mut();
for pixel in pixels {
// we can also do pixels.iter().enumerate() and make sure enumeration is some number
*pixel = Pixel::WHITE;
}
}
I include this, because it is very similar to my third code block above. In both of those, we are dereferencing a &mut Pixel
, yet only the case inside of the loop works.
Testing on EndeavourOS, updated Rust version with
bevy = "0.12.0"
bevy_pixel_buffer = "0.6.0"
Do you have an example using mouse coordinates to draw pixels? I am having issues mapping bevy cursor to position within the image
Code like this leads to this problem:
fn update(
mut pb: QueryPixelBuffer,
mut egui_context: EguiContexts,
) {
egui::CentralPanel::default().show(egui_context.ctx_mut(), |ui| {
pb.update_fill_egui(ui.available_size());
// or even this: pb.update_fill_egui(egui::Vec2::new(512.0, 512.0));
let texture = pb.egui_texture();
ui.image(egui::load::SizedTexture::new(texture.id, texture.size));
});
}
I'm trying to run the example with bevy 0.12.1, bevy_pixel_buffer 0.6.1 and bevy_egui 0.24.
This is the error i get:
error[E0599]: no method named `update_fill_egui` found for struct `bevy_pixel_buffer::query::QueryPixelBuffer<'_, '_>` in the current scope
--> src\main.rs:32:12
|
32 | pb.update_fill_egui(ui.available_size());
| ^^^^^^^^^^^^^^^^ method not found in `QueryPixelBuffer<'_, '_>`
Hi! I'm opening an issue as i can't find a way to open a discussion.
Is there a way to manually adjust the PixelBufferSize
from one of the bevy systems?
I tried fiddling with QueryPixelBuffer
but i cannot seem to find a way to do it except for .update_fill_egui()
which, from my understanding, also adds new pixels to the pixel buffer (something i don't want to do).
Thank you in advance!
bevy_pixel_buffer/src/pixel_buffer.rs
Lines 439 to 483 in 398c3c6
It would be great to be able to modify things like the transform and sprite components when the PixelBuffer is created. What if instead of using SpriteBundle
, there's PixelBufferBundle
that replaces the current tuple bundle and surfaces components users are likely to want to customize. An example is the ShapeBundle
in bevy_prototype_lyon
: https://github.com/Nilirad/bevy_prototype_lyon/blob/master/src/entity.rs#L23
That way sensible defaults can still be provided and there can still be a builder API, but if you still have access to all of the components that are currently hidden in SpriteBundle
.
The exposed API could look something like this:
let size = PixelBufferSize::size((100, 100));
let image = PixelBuffer::create_image(size, |frame| { frame.per_pixel(|_, _| Pixel::RED) });
commands.spawn_bundle(PixelBufferBundle {
size,
texture: images.add(image),
transform: Transform::from_xyz(10., 10., 0.),
sprite: Sprite {
anchor: Anchor::BottomLeft,
..default()
},
..default()
});
Awesome library! I was searching for ways to integrated the pixels library into bevy https://github.com/parasyte/pixels
Was curious how this compared to pixels. This library seems to do the same thing pixels does, just with bevy :)
I currently don't have time to do this. Maybe in a couple of weeks. So if any one needs it and want to, PRs welcome ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.