Skip to content

Instantly share code, notes, and snippets.

@cyberj cyberj/mesh.rs
Last active Oct 10, 2019

Embed
What would you like to do?
Trying to make a transparent plane in amethyst
// .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
You can’t perform that action at this time.