Crates.io | bevy_ambient_cg |
lib.rs | bevy_ambient_cg |
version | |
source | src |
created_at | 2024-12-10 16:37:32.576365 |
updated_at | 2024-12-10 18:50:53.748743 |
description | Bevy Plugin for importing materials from https://ambientcg.com/ |
homepage | |
repository | https://github.com/sollambert/bevy_ambient_cg.git |
max_upload_size | |
id | 1478704 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
This plugin allows you to easily import Ambient CG materials into Bevy with only a few lines of code.
Roughness/Metallic maps are automatically constructed with roughness data and metallic data going in the green and blue channels respectively of a generated map during runtime. No manual file conversions!
As of now, only JPEG format images are implemented and will require enabling the bevy jpg feature.
cargo add bevy -F jpg
Constructing an ambient CG material resource
pub const EXAMPLE_000: AmbientCGMaterial = AmbientCGMaterial {
name: "Example000",
subfolder: Some("some/path/to/resource"),
resolution: AmbientCGResolution::OneK,
// this is the uv scale you want to render at, materials are generated to repeat
// if uv_scale is None asset server will use default Affine value when loading
uv_scale: Some(Vec2::new(8., 8.))
};
pub const EXAMPLE_001: AmbientCGMaterial = AmbientCGMaterial {
name: "Example001",
subfolder: Some("some/path/to/resource"),
// Resolution will auto negotiate to a smaller resolution if 16K is not found.
// This will allow you to selectively bundle textures and not have to determine resolution that is currently loaded if so desired
resolution: AmbientCGResolution::SixteenK,
uv_scale: None,
};
Initializing plugin
fn main() {
app.add_plugins(DefaultPlugins)
// by default this will look for materials in assets/materials
.add_plugins(AmbientCGPlugin::default())
.run()
}
Load a material and apply to mesh
fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>
) {
commands.spawn((
PbrBundle {
mesh: meshes.add(Cylinder::new(200.0, 0.1)),
material: EXAMPLE_000.load(&asset_server, &mut materials),
transform: Transform::from_xyz(0.0, -0.05, 0.0),
..default()
},
));
// This will override the UV Scale defined in the const
commands.spawn((
PbrBundle {
mesh: meshes.add(Cylinder::new(200.0, 0.1)),
// Here we define UV scale on the fly to override the value from defined AmbientCGMaterial
material: EXAMPLE_001.load_with_uv_scale(&asset_server, &mut materials, Vec2::(2.0, 2.0)),
transform: Transform::from_xyz(0.0, -0.05, 0.0),
..default()
},
));
}