pub fn write<W : io::Write>(&self, output : &mut io::BufWriter<W>) -> Result<(),LoadingError> {
        // Write vertices
        for &(x,y,z,w) in &self.vertices {
            let line : String = format!("v {} {} {} {}\n",x,y,z,w);
            try!(output.write_all(line.as_bytes()));
        }

        // Write normals
        for &(x,y,z) in &self.normals {
            let line : String = format!("vn {} {} {}\n",x,y,z);
            try!(output.write_all(line.as_bytes()));
        }

        // Write texcoords
        for &(u,v,w) in &self.texcoords {
            let line : String = format!("vt {} {} {}\n",u,v,w);
            try!(output.write_all(line.as_bytes()));
        }

        // Write faces
        let mut actif_groups : Vec<usize> = Vec::new();
        for o in &self.objects {
            if o.name != String::new() {
                let line : String = format!("o {}\n",o.name);
                try!(output.write_all(line.as_bytes()));
            }
            for i in &o.primitives {
                let mut groups : Vec<usize> = Vec::new();
                for (j,g) in self.groups.iter().enumerate() {
                    if g.indexes.contains(i) {
                        groups.push(j);
                    }
                }
                if actif_groups != groups {
                    actif_groups = groups;
                    try!(output.write_all("g".as_bytes()));
                    for g in &actif_groups {
                        try!(output.write_all(" ".as_bytes()));
                        try!(output.write_all(&self.groups[*g].name.as_bytes()));
                    }
                    try!(output.write_all("\n".as_bytes()));
                }

                try!(output.write_all("f".as_bytes()));
                for &(v,vt,vn) in &self.faces[*i] {
                    let vt_str = match vt {
                        Some(val) => (val+1).to_string(),
                        None => "".to_string(),
                    };
                    let vn_str = match vn {
                        Some(val) => (val+1).to_string(),
                        None => "".to_string(),
                    };
                    let arg : String = format!(" {}/{}/{}",v+1,vt_str,vn_str);
                    try!(output.write_all(arg.as_bytes()));
                }
                try!(output.write_all("\n".as_bytes()));
            }
        }
        Ok(())
    }
/// Write in wavefront format in file.
///
/// # Examples
///
/// ```
/// use std::fs::File;
/// use std::io::BufWriter;
/// use std::io::BufReader;
/// use lwobj::ObjData;
///
/// let f1 = File::open("cube.obj").unwrap();
/// let mut input = BufReader::new(f1);
/// let data = ObjData::load(&mut input).ok().unwrap();
/// let f2 = File::create("tmp.obj").unwrap();
/// let mut output = BufWriter::new(f2);
/// assert!(data.write(&mut output).is_ok());
/// ```
Write in wavefront format in file.
Write in wavefront format in file .
pub fn write<W : io::Write>(&self, output : &mut io::BufWriter<W>) -> Result<(),LoadingError> {
        // Write vertices
        for &(x,y,z,w) in &self.vertices {
            let line : String = format!("v {} {} {} {}\n",x,y,z,w);
            try!(output.write_all(line.as_bytes()));
        }
        // Write normals
        for &(x,y,z) in &self.normals {
            let line : String = format!("vn {} {} {}\n",x,y,z);
            try!(output.write_all(line.as_bytes()));
        }
        // Write texcoords
        for &(u,v,w) in &self.texcoords {
            let line : String = format!("vt {} {} {}\n",u,v,w);
            try!(output.write_all(line.as_bytes()));
        }
        // Write faces
        let mut actif_groups : Vec<usize> = Vec::new();
        for o in &self.objects {
            if o.name != String::new() {
                let line : String = format!("o {}\n",o.name);
                try!(output.write_all(line.as_bytes()));
            }
            for i in &o.primitives {
                let mut groups : Vec<usize> = Vec::new();
                for (j,g) in self.groups.iter().enumerate() {
                    if g.indexes.contains(i) {
                        groups.push(j);
                    }
                }
                if actif_groups != groups {
                    actif_groups = groups;
                    try!(output.write_all("g".as_bytes()));
                    for g in &actif_groups {
                        try!(output.write_all(" ".as_bytes()));
                        try!(output.write_all(&self.groups[*g].name.as_bytes()));
                    }
                    try!(output.write_all("\n".as_bytes()));
                }
                try!(output.write_all("f".as_bytes()));
                for &(v,vt,vn) in &self.faces[*i] {
                    let vt_str = match vt {
                        Some(val) => (val+1).to_string(),
                        None => "".to_string(),
                    };
                    let vn_str = match vn {
                        Some(val) => (val+1).to_string(),
                        None => "".to_string(),
                    };
                    let arg : String = format!(" {}/{}/{}",v+1,vt_str,vn_str);
                    try!(output.write_all(arg.as_bytes()));
                }
                try!(output.write_all("\n".as_bytes()));
            }
        }
        Ok(())
    }
pub fn write < W : io :: Write > ( & self , output : & mut io :: BufWriter < W > ) -> Result < ( ) , LoadingError > { // Write vertices for & ( x , y , z , w ) in & self . vertices { let line : String = format ! ( " \n " x y z w ) ; try ! ( output write_all ( line as_bytes ( ) ) ) ; } // Write normals for & ( x , y , z ) in & self . normals { let line : String = format ! ( " \n " x y z ) ; try ! ( output write_all ( line as_bytes ( ) ) ) ; } // Write texcoords for & ( u , v , w ) in & self . texcoords { let line : String = format ! ( " \n " u v w ) ; try ! ( output write_all ( line as_bytes ( ) ) ) ; } // Write faces let mut actif_groups : Vec < usize > = Vec :: new ( ) ; for o in & self . objects { if o . name != String :: new ( ) { let line : String = format ! ( " \n " o name ) ; try ! ( output write_all ( line as_bytes ( ) ) ) ; } for i in & o . primitives { let mut groups : Vec < usize > = Vec :: new ( ) ; for ( j , g ) in self . groups . iter ( ) . enumerate ( ) { if g . indexes . contains ( i ) { groups . push ( j ) ; } } if actif_groups != groups { actif_groups = groups ; try ! ( output write_all ( " " as_bytes ( ) ) ) ; for g in & actif_groups { try ! ( output write_all ( " " as_bytes ( ) ) ) ; try ! ( output write_all ( self groups [ g ] name as_bytes ( ) ) ) ; } try ! ( output write_all ( " \n " as_bytes ( ) ) ) ; } try ! ( output write_all ( " " as_bytes ( ) ) ) ; for & ( v , vt , vn ) in & self . faces [ * i ] { let vt_str = match vt { Some ( val ) => ( val + 1 ) . to_string ( ) , None => " " . to_string ( ) , } ; let vn_str = match vn { Some ( val ) => ( val + 1 ) . to_string ( ) , None => " " . to_string ( ) , } ; let arg : String = format ! ( " " v 1 vt_str vn_str ) ; try ! ( output write_all ( arg as_bytes ( ) ) ) ; } try ! ( output write_all ( " \n " as_bytes ( ) ) ) ; } } Ok ( ( ) ) }
Write in wavefront format in file.
Write in wavefront format in file .
&self
output
&mut io::BufWriter<W>
&self
output
&mut io::BufWriter<W>
examples
```
use std::fs::File;
use std::io::BufWriter;
use std::io::BufReader;
use lwobj::ObjData.

let f1 = File::open("cube.obj").unwrap();
let mut input = BufReader::new(f1);
let data = ObjData::load(&mut input).ok().unwrap();
let f2 = File::create("tmp.obj").unwrap();
let mut output = BufWriter::new(f2);
assert!(data.write(&mut output).is_ok());
```
` ` ` use std :: fs :: File ; use std :: io :: BufWriter ; use std :: io :: BufReader ; use lwobj :: ObjData . let f1 = File :: open ( " cube . obj " ) . unwrap () ; let mut input = BufReader :: new ( f1 ) ; let data = ObjData :: load ( &mut input ) . ok () . unwrap () ; let f2 = File :: create ( " tmp . obj " ) . unwrap () ; let mut output = BufWriter :: new ( f2 ) ; assert! ( data . write ( &mut output ) . is_ok () ) ; ` ` `