SHARE
TWEET

greaewfdashgjryyter

a guest Jan 20th, 2020 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::fs::File;
  2. use std::io::{BufWriter, BufReader};
  3. use byteorder::{LittleEndian, WriteBytesExt};
  4.  
  5. use obj::{load_obj, Obj};
  6.  
  7. fn main() {
  8.     let input = BufReader::new(File::open("../dragon.obj").unwrap());
  9.     let mesh: Obj<obj::Vertex, u32> = load_obj(input).unwrap();
  10.  
  11.     let mut output = BufWriter::new(File::create("../dragon.mesh").unwrap());
  12.  
  13.     output.write_u24::<LittleEndian>(0x55DABA).unwrap();
  14.     output.write_u32::<LittleEndian>(mesh.vertices.len() as _).unwrap();
  15.     for v in &mesh.vertices {
  16.         output.write_f32::<LittleEndian>(v.position[0]).unwrap();
  17.         output.write_f32::<LittleEndian>(v.position[1]).unwrap();
  18.         output.write_f32::<LittleEndian>(v.position[2]).unwrap();
  19.         output.write_f32::<LittleEndian>(v.normal[0]).unwrap();
  20.         output.write_f32::<LittleEndian>(v.normal[1]).unwrap();
  21.         output.write_f32::<LittleEndian>(v.normal[2]).unwrap();
  22.     }
  23.  
  24.     output.write_u32::<LittleEndian>(mesh.indices.len() as _).unwrap();
  25.     for i in &mesh.indices {
  26.         output.write_u32::<LittleEndian>(*i).unwrap();
  27.     }
  28. }
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