Last active
October 10, 2019 07:46
-
-
Save cyberj/932956a8fb7d69d43fac0c657cd195af to your computer and use it in GitHub Desktop.
Trying to make a transparent plane in amethyst
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
// .with_bundle( | |
// RenderingBundle::<DefaultBackend>::new() | |
// // The RenderToWindow plugin provides all the scaffolding for opening a window and drawing on it | |
// .with_plugin( | |
// RenderToWindow::from_config_path(display_config_path) | |
// .with_clear([0.0, 0.0, 0.0, 1.0]), | |
// ) // RenderFlat2D plugin is used to render entities with `SpriteRender` component. | |
// .with_plugin(RenderFlat2D::default()) | |
// .with_plugin(RenderUi::default()) | |
// .with_plugin(RenderDebugLines::default()) | |
// .with_plugin(RenderPbr3D::default()) | |
// .with_plugin(RenderImgui::<amethyst::input::StringBindings>::default()) | |
// )? | |
// Orthographic camera | |
fn make_plane(world: &mut World) -> Handle<Mesh> { | |
let loader = world.read_resource::<Loader>(); | |
let mesh_store = &world.read_resource(); | |
loader.load_from_data( | |
Shape::Plane(Some((16, 16))) | |
.generate::<(Vec<Position>, Vec<Normal>, Vec<Tangent>, Vec<TexCoord>)>(None) | |
.into(), | |
(), | |
mesh_store, | |
) | |
} | |
pub fn initialise_plane(world: &mut World) { | |
// Light | |
world.insert(AmbientColor(Srgba::new(1.0, 1.0, 1.0, 1.0))); | |
let mat_defaults = world.read_resource::<MaterialDefaults>().0.clone(); | |
// let my_mesh: Handle<Mesh> = make_plane(world); | |
let (mesh, mtl) = { | |
let my_mesh: Handle<Mesh> = make_plane(world); | |
let albedo = world.exec(|loader: AssetLoaderSystemData<'_, Texture>| { | |
loader.load_from_data( | |
// | |
// Trying to play with Material transparency here ... with no luck | |
// | |
load_from_linear_rgba(LinSrgba::new(0.1, 0.5, 0.3, 0.1)).into(), | |
(), | |
) | |
}); | |
let loader = world.read_resource::<Loader>(); | |
let materials = &world.read_resource(); | |
let mtl: Handle<Material> = loader.load_from_data( | |
Material { | |
albedo, | |
..mat_defaults | |
}, | |
(), | |
materials, | |
); | |
(my_mesh, mtl) | |
}; | |
let mut trans = Transform::default(); | |
trans.set_translation_xyz(32.0, 32.0, 5.0); | |
trans.set_scale(Vector3::new(32.0, 32.0, 1.0)); | |
world | |
.create_entity() | |
.with(mesh) | |
.with(mtl) | |
.with(trans) | |
.with(Transparent::default()) | |
.build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment