pub fn with_obj(mut self, source: String) -> Self
    {
        let mut positions = Vec::new();
        let mut indices = Vec::new();

        let objs = wavefront_obj::obj::parse(source).unwrap().objects;
        for obj in objs.iter()
        {
            let start_index = positions.len()/3;
            for vertex in obj.vertices.iter() {
                positions.push(vertex.x);
                positions.push(vertex.y);
                positions.push(vertex.z);
            }

            for shape in obj.geometry.first().unwrap().shapes.iter() {
                match shape.primitive {
                    wavefront_obj::obj::Primitive::Triangle((i0, ..), (i1, ..), (i2, ..)) => {
                        indices.push((start_index + i0) as u32);
                        indices.push((start_index + i1) as u32);
                        indices.push((start_index + i2) as u32);
                    },
                    _ => {}
                }
            }
        }
        self.positions = Some(positions);
        self.indices = Some(indices);
        self
    }
///
/// Parses the .obj file and extracts the connectivity information (indices) and positions which is used to construct a mesh when the `build` method is called.
/// If the .obj file contains multiple objects, all objects are added to the mesh, but they will not be connected.
///
/// # Examples
///
/// ```no_run
/// # fn main() -> Result<(), Box<tri_mesh::mesh_builder::Error>> {
///     let obj_source = std::fs::read_to_string("foo.obj").expect("Something went wrong reading the file");
///     let mesh = tri_mesh::mesh_builder::MeshBuilder::new().with_obj(obj_source).build()?;
/// #    Ok(())
/// # }
/// ```
Parses the .obj file and extracts the connectivity information (indices) and positions which is used to construct a mesh when the `build` method is called.
If the .obj file contains multiple objects, all objects are added to the mesh, but they will not be connected.
Parses the . obj file and extracts the connectivity information ( indices ) and positions which is used to construct a mesh when the ` build ` method is called . If the . obj file contains multiple objects all objects are added to the mesh but they will not be connected .
pub fn with_obj(mut self, source: String) -> Self
    {
        let mut positions = Vec::new();
        let mut indices = Vec::new();
        let objs = wavefront_obj::obj::parse(source).unwrap().objects;
        for obj in objs.iter()
        {
            let start_index = positions.len()/3;
            for vertex in obj.vertices.iter() {
                positions.push(vertex.x);
                positions.push(vertex.y);
                positions.push(vertex.z);
            }
            for shape in obj.geometry.first().unwrap().shapes.iter() {
                match shape.primitive {
                    wavefront_obj::obj::Primitive::Triangle((i0, ..), (i1, ..), (i2, ..)) => {
                        indices.push((start_index + i0) as u32);
                        indices.push((start_index + i1) as u32);
                        indices.push((start_index + i2) as u32);
                    },
                    _ => {}
                }
            }
        }
        self.positions = Some(positions);
        self.indices = Some(indices);
        self
    }
pub fn with_obj ( mut self , source : String ) -> Self { let mut positions = Vec :: new ( ) ; let mut indices = Vec :: new ( ) ; let objs = wavefront_obj :: obj :: parse ( source ) . unwrap ( ) . objects ; for obj in objs . iter ( ) { let start_index = positions . len ( ) / 3 ; for vertex in obj . vertices . iter ( ) { positions . push ( vertex . x ) ; positions . push ( vertex . y ) ; positions . push ( vertex . z ) ; } for shape in obj . geometry . first ( ) . unwrap ( ) . shapes . iter ( ) { match shape . primitive { wavefront_obj :: obj :: Primitive :: Triangle ( ( i0 , .. ) , ( i1 , .. ) , ( i2 , .. ) ) => { indices . push ( ( start_index + i0 ) as u32 ) ; indices . push ( ( start_index + i1 ) as u32 ) ; indices . push ( ( start_index + i2 ) as u32 ) ; } , _ => { } } } } self . positions = Some ( positions ) ; self . indices = Some ( indices ) ; self }
Parses the .obj file and extracts the connectivity information (indices) and positions which is used to construct a mesh when the `build` method is called.
Parses the . obj file and extracts the connectivity information ( indices ) and positions which is used to construct a mesh when the ` build ` method is called .
mut self
source
String
mut self
source
String
examples
None
fn main() -> result<(), box<tri_mesh::mesh_builder::error>> {
let obj_source = std::fs::read_to_string("foo.obj").expect("Something went wrong reading the file");
let mesh = tri_mesh::mesh_builder::MeshBuilder::new().with_obj(obj_source).build()?.
let obj_source = std :: fs :: read_to_string ( " foo . obj " ) . expect ( " Something went wrong reading the file " ) ; let mesh = tri_mesh :: mesh_builder :: MeshBuilder :: new () . with_obj ( obj_source ) . build () ? .
ok(())
None
}
None