Skip to content

Commit

Permalink
update example for new renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Feb 4, 2022
1 parent 4319101 commit d847c07
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions examples/asset/asset_transformation.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use bevy::prelude::*;
use bevy::{prelude::*, render::texture::TextureFormatPixelInfo};

fn main() {
App::build()
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.run();
}

fn filter_pixels(filter: usize, texture: &Texture) -> Vec<u8> {
texture
fn filter_pixels(filter: usize, image: &Image) -> Vec<u8> {
image
.data
.iter()
.enumerate()
.map(|(i, v)| {
if i / texture.format.pixel_size() % filter == 0 {
if i / image.texture_descriptor.format.pixel_size() % filter == 0 {
0
} else {
*v
Expand All @@ -22,42 +22,38 @@ fn filter_pixels(filter: usize, texture: &Texture) -> Vec<u8> {
.collect()
}

fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
let texture_handle = asset_server.load("branding/icon.png");

// new texture with every third pixel removed
let texture_handle_1 = asset_server.create_from(texture_handle.clone(), |texture: &Texture| {
Some(Texture {
let texture_handle_1 = asset_server.create_from(texture_handle.clone(), |texture: &Image| {
Some(Image {
data: filter_pixels(3, texture),
..*texture
..texture.clone()
})
});

// new texture with every second pixel removed
let texture_handle_2 = asset_server.create_from(texture_handle.clone(), |texture: &Texture| {
Some(Texture {
let texture_handle_2 = asset_server.create_from(texture_handle.clone(), |texture: &Image| {
Some(Image {
data: filter_pixels(2, texture),
..*texture
..texture.clone()
})
});

commands.spawn_bundle(OrthographicCameraBundle::new_2d());

commands.spawn_bundle(SpriteBundle {
material: materials.add(texture_handle.into()),
texture: texture_handle,
transform: Transform::from_xyz(-300.0, 0.0, 0.0),
..Default::default()
});
commands.spawn_bundle(SpriteBundle {
material: materials.add(texture_handle_1.into()),
texture: texture_handle_1,
..Default::default()
});
commands.spawn_bundle(SpriteBundle {
material: materials.add(texture_handle_2.into()),
texture: texture_handle_2,
transform: Transform::from_xyz(300.0, 0.0, 0.0),
..Default::default()
});
Expand Down

0 comments on commit d847c07

Please sign in to comment.