-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a method on AssetServer
to create an asset from an existing one
#1665
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fcac6d6
renaming channel to better express their purpose
mockersf 192fe8e
can create a new asset from an existing one
mockersf 827db05
typo and add comments
mockersf 21c2c14
typo
mockersf 9a46535
remove a box
mockersf 67e606b
add type for easier reading
mockersf 897e1b7
work between different types
mockersf 9b74dba
small renaming
mockersf 3ff89d8
improve usability, error handling and comments
mockersf 4fdf02c
renaming
mockersf 3fe8c16
improve comments/logs
mockersf 481298d
type parameter names
mockersf 41fb26f
fix doc comment
mockersf 4319101
update for new commands api
mockersf d847c07
update example for new renderer
mockersf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use bevy::{prelude::*, render::texture::TextureFormatPixelInfo}; | ||
|
||
fn main() { | ||
App::new() | ||
.add_plugins(DefaultPlugins) | ||
.add_startup_system(setup.system()) | ||
.run(); | ||
} | ||
|
||
fn filter_pixels(filter: usize, image: &Image) -> Vec<u8> { | ||
image | ||
.data | ||
.iter() | ||
.enumerate() | ||
.map(|(i, v)| { | ||
if i / image.texture_descriptor.format.pixel_size() % filter == 0 { | ||
0 | ||
} else { | ||
*v | ||
} | ||
}) | ||
.collect() | ||
} | ||
|
||
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: &Image| { | ||
Some(Image { | ||
data: filter_pixels(3, texture), | ||
..texture.clone() | ||
}) | ||
}); | ||
|
||
// new texture with every second pixel removed | ||
let texture_handle_2 = asset_server.create_from(texture_handle.clone(), |texture: &Image| { | ||
Some(Image { | ||
data: filter_pixels(2, texture), | ||
..texture.clone() | ||
}) | ||
}); | ||
|
||
commands.spawn_bundle(OrthographicCameraBundle::new_2d()); | ||
|
||
commands.spawn_bundle(SpriteBundle { | ||
texture: texture_handle, | ||
transform: Transform::from_xyz(-300.0, 0.0, 0.0), | ||
..Default::default() | ||
}); | ||
commands.spawn_bundle(SpriteBundle { | ||
texture: texture_handle_1, | ||
..Default::default() | ||
}); | ||
commands.spawn_bundle(SpriteBundle { | ||
texture: texture_handle_2, | ||
transform: Transform::from_xyz(300.0, 0.0, 0.0), | ||
..Default::default() | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When reading through this I stumbled on the name
to_system
several times because it seems like it must be connected to the IntoSystem but that doesn't make sense in context. I think I actually prefer the originalsender
andreceiver
, they're slightly more cryptic but they're conventional which makes them instantly recognizable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree on that, but I guess it's a taste/habit situation. Plus I don't like having a variable named after its type.
I'm open to changing it back if others feel the same way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your reason for making the change is good, I don't object to keeping it.