From 0fbac1582829f1aea99a0c1a3ea117a3bcb47617 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 13 Feb 2024 23:56:24 -0800 Subject: [PATCH] obj --- src/obj.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/obj.rs diff --git a/src/obj.rs b/src/obj.rs new file mode 100644 index 0000000..ddb59fb --- /dev/null +++ b/src/obj.rs @@ -0,0 +1,41 @@ + +pub fn generate_indexed_model_list_from_obj(data:obj::ObjData,color:Color4)->Vec{ + let mut unique_vertex_index = std::collections::HashMap::::new(); + return data.objects.iter().map(|object|{ + unique_vertex_index.clear(); + let mut unique_vertices = Vec::new(); + let groups = object.groups.iter().map(|group|{ + IndexedGroup{ + texture:None, + polys:group.polys.iter().map(|poly|{ + IndexedPolygon{ + vertices:poly.0.iter().map(|&tup|{ + if let Some(&i)=unique_vertex_index.get(&tup){ + i + }else{ + let i=unique_vertices.len() as u32; + unique_vertices.push(IndexedVertex{ + pos: tup.0 as u32, + tex: tup.1.unwrap() as u32, + normal: tup.2.unwrap() as u32, + color: 0, + }); + unique_vertex_index.insert(tup,i); + i + } + }).collect() + } + }).collect() + } + }).collect(); + IndexedModel{ + unique_pos: data.position.iter().map(|&v|Planar64Vec3::try_from(v).unwrap()).collect(), + unique_tex: data.texture.iter().map(|&v|TextureCoordinate::from_array(v)).collect(), + unique_normal: data.normal.iter().map(|&v|Planar64Vec3::try_from(v).unwrap()).collect(), + unique_color: vec![color], + unique_vertices, + groups, + instances:Vec::new(), + } + }).collect() +} \ No newline at end of file