fn load_model(&mut self, path: &str) {
        let path = Path::new(path);

        // retrieve the directory path of the filepath
        self.directory = path.parent().unwrap_or_else(|| Path::new("")).to_str().unwrap().into();
        let obj = tobj::load_obj(path, false);

        let (models, materials) = obj.unwrap();
        for model in models {
            let mesh = &model.mesh;
            let num_vertices = mesh.positions.len() / 3;

            // data to fill
            let mut vertices: Vec<Vertex> = Vec::with_capacity(num_vertices);
            let indices = mesh.indices.clone();

            let (p, n, t) = (&mesh.positions, &mesh.normals, &mesh.texcoords);
            for i in 0..num_vertices {
                vertices.push(Vertex {
                    position: vec3(p[i * 3], p[i * 3 + 1], p[i * 3 + 2]),
                    normal: vec3(n[i * 3], n[i * 3 + 1], n[i * 3 + 2]),
                    tex_coords: vec2(t[i * 2], t[i * 2 + 1]),
                    ..Vertex::default()
                })
            }

            // process material
            let mut textures = Vec::new();
            if let Some(material_id) = mesh.material_id {
                let material = &materials[material_id];

                // 1. diffuse map
                if !material.diffuse_texture.is_empty() {
                    let texture = self.load_material_texture(&material.diffuse_texture, "texture_diffuse");
                    textures.push(texture);
                }
                // 2. specular map
                if !material.specular_texture.is_empty() {
                    let texture = self.load_material_texture(&material.specular_texture, "texture_specular");
                    textures.push(texture);
                }
                // 3. normal map
                if !material.normal_texture.is_empty() {
                    let texture = self.load_material_texture(&material.normal_texture, "texture_normal");
                    textures.push(texture);
                }
                // NOTE: no height maps
            }

            self.meshes.push(Mesh::new(vertices, indices, textures));
        }
    }
// loads a model from file and stores the resulting meshes in the meshes vector.
loads a model from file and stores the resulting meshes in the meshes vector.
loads a model from file and stores the resulting meshes in the meshes vector .
fn load_model(&mut self, path: &str) {
        let path = Path::new(path);
        // retrieve the directory path of the filepath
        self.directory = path.parent().unwrap_or_else(|| Path::new("")).to_str().unwrap().into();
        let obj = tobj::load_obj(path, false);
        let (models, materials) = obj.unwrap();
        for model in models {
            let mesh = &model.mesh;
            let num_vertices = mesh.positions.len() / 3;
            // data to fill
            let mut vertices: Vec<Vertex> = Vec::with_capacity(num_vertices);
            let indices = mesh.indices.clone();
            let (p, n, t) = (&mesh.positions, &mesh.normals, &mesh.texcoords);
            for i in 0..num_vertices {
                vertices.push(Vertex {
                    position: vec3(p[i * 3], p[i * 3 + 1], p[i * 3 + 2]),
                    normal: vec3(n[i * 3], n[i * 3 + 1], n[i * 3 + 2]),
                    tex_coords: vec2(t[i * 2], t[i * 2 + 1]),
                    ..Vertex::default()
                })
            }
            // process material
            let mut textures = Vec::new();
            if let Some(material_id) = mesh.material_id {
                let material = &materials[material_id];
                // 1. diffuse map
                if !material.diffuse_texture.is_empty() {
                    let texture = self.load_material_texture(&material.diffuse_texture, "texture_diffuse");
                    textures.push(texture);
                }
                // 2. specular map
                if !material.specular_texture.is_empty() {
                    let texture = self.load_material_texture(&material.specular_texture, "texture_specular");
                    textures.push(texture);
                }
                // 3. normal map
                if !material.normal_texture.is_empty() {
                    let texture = self.load_material_texture(&material.normal_texture, "texture_normal");
                    textures.push(texture);
                }
                // NOTE: no height maps
            }
            self.meshes.push(Mesh::new(vertices, indices, textures));
        }
    }
fn load_model ( & mut self , path : & str ) { let path = Path :: new ( path ) ; // retrieve the directory path of the filepath self . directory = path . parent ( ) . unwrap_or_else ( | | Path :: new ( " " ) ) . to_str ( ) . unwrap ( ) . into ( ) ; let obj = tobj :: load_obj ( path , false ) ; let ( models , materials ) = obj . unwrap ( ) ; for model in models { let mesh = & model . mesh ; let num_vertices = mesh . positions . len ( ) / 3 ; // data to fill let mut vertices : Vec < Vertex > = Vec :: with_capacity ( num_vertices ) ; let indices = mesh . indices . clone ( ) ; let ( p , n , t ) = ( & mesh . positions , & mesh . normals , & mesh . texcoords ) ; for i in 0 .. num_vertices { vertices . push ( Vertex { position : vec3 ( p [ i * 3 ] , p [ i * 3 + 1 ] , p [ i * 3 + 2 ] ) , normal : vec3 ( n [ i * 3 ] , n [ i * 3 + 1 ] , n [ i * 3 + 2 ] ) , tex_coords : vec2 ( t [ i * 2 ] , t [ i * 2 + 1 ] ) , .. Vertex :: default ( ) } ) } // process material let mut textures = Vec :: new ( ) ; if let Some ( material_id ) = mesh . material_id { let material = & materials [ material_id ] ; // 1. diffuse map if ! material . diffuse_texture . is_empty ( ) { let texture = self . load_material_texture ( & material . diffuse_texture , " " ) ; textures . push ( texture ) ; } // 2. specular map if ! material . specular_texture . is_empty ( ) { let texture = self . load_material_texture ( & material . specular_texture , " " ) ; textures . push ( texture ) ; } // 3. normal map if ! material . normal_texture . is_empty ( ) { let texture = self . load_material_texture ( & material . normal_texture , " " ) ; textures . push ( texture ) ; } // NOTE: no height maps } self . meshes . push ( Mesh :: new ( vertices , indices , textures ) ) ; } }
loads a model from file and stores the resulting meshes in the meshes vector.
loads a model from file and stores the resulting meshes in the meshes vector .
&mut self
path
&str
&mut self
path
&str