This commit is contained in:
Quaternions 2023-09-27 17:24:25 -07:00
parent 27c7b7b785
commit b233d497ad
3 changed files with 59 additions and 9 deletions

View File

@ -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<H: std::hash::Hasher>(&self, state: &mut H) {

View File

@ -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::<ModelData>::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.)),

View File

@ -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<glam::Affine2>;6])->obj::ObjData{
let default_polys=[
// right (1, 0, 0)
obj::SimplePolygon(vec![
@ -103,3 +102,55 @@ pub fn generate_partial_unit_cube(face_transforms:[Option<glam::Affine2>;6])->ob
material_libs: Vec::new(),
}
}
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<FaceDescription>;6],texture:Option<u32>) -> crate::model::ModelData{
let mut vertices = Vec::new();
let mut vertex_index = std::collections::HashMap::<obj::IndexTuple,u16>::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,
}
}