SHARE
TWEET

Untitled

a guest Sep 4th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn make_mesh(world: &mut World) -> Handle<Mesh>
  2. {
  3.     use amethyst::renderer::rendy::mesh::{MeshBuilder, Position, TexCoord};
  4.     use amethyst::renderer::types::MeshData;
  5.  
  6.     let loader = world.read_resource::<Loader>();
  7.  
  8.     let verts = vec![
  9.         Position([-1.0, -1.0, 0.0]),
  10.         Position([ 1.0, -1.0, 0.0]),
  11.         Position([ 1.0,  1.0, 0.0]),
  12.         Position([-1.0,  1.0, 0.0]),
  13.     ];
  14.  
  15.     let tex = vec![
  16.         TexCoord([0.0, 0.0]),
  17.         TexCoord([1.0, 0.0]),
  18.         TexCoord([1.0, 1.0]),
  19.         TexCoord([0.0, 1.0]),
  20.     ];
  21.  
  22.     let mesh_store = &world.read_resource();
  23.  
  24.     let m = MeshBuilder::new()
  25.         .with_vertices(verts)
  26.         .with_vertices(tex);
  27.  
  28.     loader.load_from_data(MeshData::from(m), (), mesh_store)
  29. }
  30.  
  31. fn make_texture(world: &mut World) -> Handle<Texture>
  32. {
  33.     use amethyst::renderer::types::TextureData;
  34.  
  35.     let loader = world.read_resource::<Loader>();
  36.  
  37.     let tex_store = &world.read_resource();
  38.  
  39.     let t = amethyst::renderer::loaders::load_from_linear_rgba(
  40.         amethyst::renderer::palette::Alpha
  41.         {
  42.             color: amethyst::renderer::palette::rgb::LinSrgb::new(1.0, 0.0, 0.0),
  43.             alpha: 1.0
  44.         }
  45.     );
  46.  
  47.     loader.load_from_data(t.into(), (), tex_store)
  48. }
  49.  
  50. fn make_material(world: &mut World, tex: Handle<Texture>) -> Handle<Material>
  51. {
  52.     use amethyst::renderer::MaterialDefaults;
  53.  
  54.     let loader = world.read_resource::<Loader>();
  55.  
  56.     let mat_store = &world.read_resource();
  57.  
  58.     let mat = Material
  59.     {
  60.         albedo: tex,
  61.         ..world.read_resource::<MaterialDefaults>().0.clone()
  62.     };
  63.  
  64.     loader.load_from_data(mat, (), mat_store)
  65. }
  66.  
  67. fn init_square(world: &mut World, mesh: Handle<Mesh>, mat: Handle<Material>)
  68. {
  69.     let mut transform = Transform::default();
  70.     transform.set_translation_xyz(WIDTH / 2.0, HEIGHT / 2.0, 0.0);
  71.  
  72.     world.create_entity()
  73.         .with(mesh)
  74.         .with(mat)
  75.         .with(transform)
  76.         .build();
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top