Giter Club home page Giter Club logo

bevy_pixel_buffer's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bevy_pixel_buffer's Issues

Unable to set Pixel without iterating over [Pixel]

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"

Mouse Position Example

Do you have an example using mouse coordinates to draw pixels? I am having issues mapping bevy cursor to position within the image

The pixel buffer with a attached compute shader is never rendered when setting pixel buffer size

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));
    });
}

fill_egui example not working

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<'_, '_>`

Adjust pixel size

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!

Fix `do_resize_sprite` test

// I can't figure it out, but I'm 90% sure it has something to do with the plugins
#[test]
fn do_resize_sprite() {
let mut app = App::new();
app.add_plugins(MinimalPlugins)
.add_plugins(bevy::asset::AssetPlugin::default())
.add_plugins(bevy::render::texture::ImagePlugin::default())
.add_plugins(bevy::window::WindowPlugin::default())
.add_plugins(bevy::sprite::SpritePlugin::default())
.add_plugins(bevy::render::RenderPlugin::default());
app.add_systems(Update, sprite_custom_size);
let set_size = UVec2::new(10, 10);
let mut images = app.world.resource_mut::<Assets<Image>>();
let image = images.add(create_image(set_size.into()));
let pb_id = app
.world
.spawn(PixelBufferSpriteBundle {
pixel_buffer: PixelBuffer {
size: PixelBufferSize::size(set_size),
fill: Fill::none(),
},
sprite_bundle: SpriteBundle {
sprite: Sprite {
custom_size: None,
..Default::default()
},
texture: image,
..Default::default()
},
})
.id();
app.update();
let size = app.world.get::<PixelBuffer>(pb_id).unwrap().size;
let sprite = app.world.get::<Sprite>(pb_id).unwrap();
assert!(sprite.custom_size.is_some());
assert_eq!(size.screen_size(), sprite.custom_size.unwrap().as_uvec2());
}

Ability to customize underlying components during setup

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()
});

Benchmarks

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 :)

Update to bevy 0.10

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 ๐Ÿ˜„

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.