pub fn from_obj<R: BufRead>(obj_data: R) -> Model {
        let mut obj_verts = Vec::new();
        let mut obj_uvs = Vec::new();
        let mut obj_norms = Vec::new();
        let mut obj_faces = Vec::new();
        for line in obj_data.lines() {
            let line = line.expect("line cannot be empty");
            let tokens = &mut line.split_whitespace();
            match tokens.next() {
                Some("v") => {
                    let (x, y, z) = parse_triplet(tokens);
                    obj_verts.push(Vec3f { x, y, z });
                }
                Some("vt") => {
                    // not all obj files have 3 dimensions for the uv coords
                    let (x, y, z) = (
                        parse_next(tokens),
                        parse_next(tokens),
                        parse_next_or(tokens, 0.),
                    );
                    obj_uvs.push(Vec3f { x, y, z });
                }
                Some("vn") => {
                    let (x, y, z) = parse_triplet(tokens);
                    obj_norms.push(Vec3f { x, y, z });
                }
                Some("f") => {
                    let (mut a, mut b, mut c) = (
                        tokens.next().expect("face missing v0").split('/'),
                        tokens.next().expect("face missing v1").split('/'),
                        tokens.next().expect("face missing v2").split('/'),
                    );

                    let (v0, uv0, n0): (usize, usize, usize) = parse_triplet(&mut a);
                    let (v1, uv1, n1): (usize, usize, usize) = parse_triplet(&mut b);
                    let (v2, uv2, n2): (usize, usize, usize) = parse_triplet(&mut c);

                    // in wavefront obj indices start at 1, not 0
                    let face = Face {
                        verts: Vec3::new(v0 - 1, v1 - 1, v2 - 1),
                        uvs: Vec3::new(uv0 - 1, uv1 - 1, uv2 - 1),
                        norms: Vec3::new(n0 - 1, n1 - 1, n2 - 1),
                    };
                    obj_faces.push(face);
                }
                _ => continue,
            }
        }
        Model {
            verts: obj_verts,
            uvs: obj_uvs,
            norms: obj_norms,
            faces: obj_faces,
        }
    }
/// Parse the given data as a Waveform .obj into a model
Parse the given data as a Waveform .obj into a model
Parse the given data as a Waveform . obj into a model
pub fn from_obj<R: BufRead>(obj_data: R) -> Model {
        let mut obj_verts = Vec::new();
        let mut obj_uvs = Vec::new();
        let mut obj_norms = Vec::new();
        let mut obj_faces = Vec::new();
        for line in obj_data.lines() {
            let line = line.expect("line cannot be empty");
            let tokens = &mut line.split_whitespace();
            match tokens.next() {
                Some("v") => {
                    let (x, y, z) = parse_triplet(tokens);
                    obj_verts.push(Vec3f { x, y, z });
                }
                Some("vt") => {
                    // not all obj files have 3 dimensions for the uv coords
                    let (x, y, z) = (
                        parse_next(tokens),
                        parse_next(tokens),
                        parse_next_or(tokens, 0.),
                    );
                    obj_uvs.push(Vec3f { x, y, z });
                }
                Some("vn") => {
                    let (x, y, z) = parse_triplet(tokens);
                    obj_norms.push(Vec3f { x, y, z });
                }
                Some("f") => {
                    let (mut a, mut b, mut c) = (
                        tokens.next().expect("face missing v0").split('/'),
                        tokens.next().expect("face missing v1").split('/'),
                        tokens.next().expect("face missing v2").split('/'),
                    );
                    let (v0, uv0, n0): (usize, usize, usize) = parse_triplet(&mut a);
                    let (v1, uv1, n1): (usize, usize, usize) = parse_triplet(&mut b);
                    let (v2, uv2, n2): (usize, usize, usize) = parse_triplet(&mut c);
                    // in wavefront obj indices start at 1, not 0
                    let face = Face {
                        verts: Vec3::new(v0 - 1, v1 - 1, v2 - 1),
                        uvs: Vec3::new(uv0 - 1, uv1 - 1, uv2 - 1),
                        norms: Vec3::new(n0 - 1, n1 - 1, n2 - 1),
                    };
                    obj_faces.push(face);
                }
                _ => continue,
            }
        }
        Model {
            verts: obj_verts,
            uvs: obj_uvs,
            norms: obj_norms,
            faces: obj_faces,
        }
    }
pub fn from_obj < R : BufRead > ( obj_data : R ) -> Model { let mut obj_verts = Vec :: new ( ) ; let mut obj_uvs = Vec :: new ( ) ; let mut obj_norms = Vec :: new ( ) ; let mut obj_faces = Vec :: new ( ) ; for line in obj_data . lines ( ) { let line = line . expect ( " " ) ; let tokens = & mut line . split_whitespace ( ) ; match tokens . next ( ) { Some ( " " ) => { let ( x , y , z ) = parse_triplet ( tokens ) ; obj_verts . push ( Vec3f { x , y , z } ) ; } Some ( " " ) => { // not all obj files have 3 dimensions for the uv coords let ( x , y , z ) = ( parse_next ( tokens ) , parse_next ( tokens ) , parse_next_or ( tokens , 0. ) , ) ; obj_uvs . push ( Vec3f { x , y , z } ) ; } Some ( " " ) => { let ( x , y , z ) = parse_triplet ( tokens ) ; obj_norms . push ( Vec3f { x , y , z } ) ; } Some ( " " ) => { let ( mut a , mut b , mut c ) = ( tokens . next ( ) . expect ( " " ) . split ( '/' ) , tokens . next ( ) . expect ( " " ) . split ( '/' ) , tokens . next ( ) . expect ( " " ) . split ( '/' ) , ) ; let ( v0 , uv0 , n0 ) : ( usize , usize , usize ) = parse_triplet ( & mut a ) ; let ( v1 , uv1 , n1 ) : ( usize , usize , usize ) = parse_triplet ( & mut b ) ; let ( v2 , uv2 , n2 ) : ( usize , usize , usize ) = parse_triplet ( & mut c ) ; // in wavefront obj indices start at 1, not 0 let face = Face { verts : Vec3 :: new ( v0 - 1 , v1 - 1 , v2 - 1 ) , uvs : Vec3 :: new ( uv0 - 1 , uv1 - 1 , uv2 - 1 ) , norms : Vec3 :: new ( n0 - 1 , n1 - 1 , n2 - 1 ) , } ; obj_faces . push ( face ) ; } _ => continue , } } Model { verts : obj_verts , uvs : obj_uvs , norms : obj_norms , faces : obj_faces , } }
Parse the given data as a Waveform .obj into a model
Parse the given data as a Waveform . obj into a model
obj_data
R