diff --git a/src/load_roblox.rs b/src/load_roblox.rs index a441c07..669b6a5 100644 --- a/src/load_roblox.rs +++ b/src/load_roblox.rs @@ -105,12 +105,12 @@ struct RobloxUnitCubeGenerationData{ } impl std::cmp::Eq for RobloxUnitCubeGenerationData{}//???? impl std::default::Default for RobloxUnitCubeGenerationData{ - fn default() -> Self { - Self{ + fn default() -> Self { + Self{ texture:None, faces:[Some(RobloxColorAndTextureTransform::default());6], } - } + } } impl std::hash::Hash for RobloxUnitCubeGenerationData { fn hash(&self, state: &mut H) { diff --git a/src/main.rs b/src/main.rs index 337a4aa..f640d62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -253,12 +253,11 @@ impl framework::Example for GraphicsData { device: &wgpu::Device, queue: &wgpu::Queue, ) -> Self { - let unit_cube=primitives::the_unit_cube_lol(); let mut modeldatas = Vec::::new(); modeldatas.append(&mut model::generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teslacyberv3.0.obj")[..]).unwrap(),ModelData::COLOR_FLOATS_WHITE)); modeldatas.append(&mut model::generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/suzanne.obj")[..]).unwrap(),ModelData::COLOR_FLOATS_WHITE)); modeldatas.append(&mut model::generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teapot.obj")[..]).unwrap(),ModelData::COLOR_FLOATS_WHITE)); - modeldatas.append(&mut model::generate_modeldatas(unit_cube.clone(),ModelData::COLOR_FLOATS_WHITE)); + modeldatas.push(primitives::the_unit_cube_lol()); println!("models.len = {:?}", modeldatas.len()); modeldatas[0].instances.push(ModelInstance{ model_transform:glam::Affine3A::from_translation(glam::vec3(10.,0.,-10.)), diff --git a/src/primitives.rs b/src/primitives.rs index 146d404..b68c7d1 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -1,7 +1,6 @@ -pub fn the_unit_cube_lol() -> obj::ObjData{ - generate_partial_unit_cube([Some(glam::Affine2::IDENTITY);6]) +pub fn the_unit_cube_lol() -> crate::model::ModelData{ + generate_partial_unit_cube([Some(FaceDescription::default());6],None) } -pub fn generate_partial_unit_cube(face_transforms:[Option;6])->obj::ObjData{ let default_polys=[ // right (1, 0, 0) obj::SimplePolygon(vec![ @@ -102,4 +101,56 @@ pub fn generate_partial_unit_cube(face_transforms:[Option;6])->ob }], material_libs: Vec::new(), } -} \ No newline at end of file +} +pub struct FaceDescription{ + transform:glam::Affine2, + color:glam::Vec4, +} +impl std::default::Default for FaceDescription{ + fn default() -> Self { + Self{ + transform:glam::Affine2::IDENTITY, + color:glam::Vec4::ONE, + } + } +} +impl FaceDescription{ + pub fn new(transform:glam::Affine2,color:glam::Vec4)->Self{ + Self{transform,color} + } +} +pub fn generate_partial_unit_cube(face_transforms:[Option;6],texture:Option) -> crate::model::ModelData{ + let mut vertices = Vec::new(); + let mut vertex_index = std::collections::HashMap::::new(); + let mut entities = Vec::new(); + for group in object.groups { + let mut indices = Vec::new(); + for poly in group.polys { + for end_index in 2..poly.0.len() { + for &index in &[0, end_index - 1, end_index] { + let vert = poly.0[index]; + if let Some(&i)=vertex_index.get(&vert){ + indices.push(i); + }else{ + let i=vertices.len() as u16; + vertices.push(Vertex { + pos: data.position[vert.0], + texture: data.texture[vert.1.unwrap()], + normal: data.normal[vert.2.unwrap()], + color, + }); + vertex_index.insert(vert,i); + indices.push(i); + } + } + } + } + entities.push(indices); + } + ModelData { + instances: Vec::new(), + vertices, + entities, + texture, + } +}