Advertisement
Voodlaz

Untitled

Jun 19th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 2.26 KB | None | 0 0
  1. use amethyst::{
  2.     assets::{Format as AssetFormat, Handle, Loader},
  3.     core::{math::Vector3, Transform, TransformBundle},
  4.     ecs::{World, WorldExt},
  5.     error::Error,
  6.     input::{InputBundle, StringBindings},
  7.     prelude::*,
  8.     renderer::{
  9.         camera::Camera,
  10.         light::{Light, PointLight},
  11.         mtl::{Material, MaterialDefaults},
  12.         palette::{Srgb, Srgba},
  13.         plugins::{RenderShaded3D, RenderSkybox, RenderToWindow},
  14.         rendy::{
  15.             mesh::{MeshBuilder, Normal, Position, TexCoord},
  16.             texture::palette::load_from_srgba,
  17.         },
  18.         types::{DefaultBackend, Mesh, MeshData},
  19.         RenderingBundle,
  20.     },
  21.     utils::application_root_dir,
  22. };
  23.  
  24. use std::fs::File;
  25. use std::io::BufReader;
  26. use obj::{load_obj, Obj};
  27.  
  28. mod objects;
  29. use crate::objects::{camera, sphere};
  30.  
  31. struct MyState;
  32.  
  33. #[derive(Clone, Debug)]
  34. struct Custom;
  35.  
  36. impl AssetFormat for Custom {
  37.     fn name(&self) -> &'static str {
  38.        "CUSTOM"
  39.    }
  40.  
  41.    fn import_simple() -> Result<MeshData, Error> {
  42.        let sphere_obj = BufReader::new(File::open("assets/sphere_mesh.obj")?);
  43.        let sphere: Obj = load_obj(sphere_obj)?;
  44.  
  45.        Ok(MeshBuilder::new()
  46.            .with_vertices(sphere.vertices)
  47.            .into())
  48.    }
  49. }
  50.  
  51. impl SimpleState for MyState {
  52.    fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) {
  53.         camera::init_camera(world);
  54.  
  55.         // what I should put here
  56. }
  57.  
  58. fn main() -> amethyst::Result<()> {
  59.     amethyst::start_logger(Default::default());
  60.  
  61.     let app_root = application_root_dir()?;
  62.  
  63.     let assets_dir = app_root.join("assets");
  64.     let config_dir = app_root.join("config");
  65.     let display_config_path = config_dir.join("display.ron");
  66.  
  67.     let game_data = GameDataBuilder::default()
  68.         .with_bundle(
  69.             RenderingBundle::<DefaultBackend>::new()
  70.                 .with_plugin(
  71.                     RenderToWindow::from_config_path(display_config_path)?
  72.                         .with_clear([1.0, 1.0, 1.0, 1.0]),
  73.                 )
  74.                 .with_plugin(RenderShaded3D::default()),
  75.         )?
  76.         .with_bundle(TransformBundle::new())?;
  77.  
  78.     let mut game = Application::new(assets_dir, MyState, game_data)?;
  79.     game.run();
  80.  
  81.     Ok(())
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement