From fe1313c70f18f9260512f3a04f352bf39fb1410d Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 12 Mar 2024 21:51:28 -0700 Subject: [PATCH] holy smokes --- src/mesh.rs | 4 ++-- src/rbx.rs | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/mesh.rs b/src/mesh.rs index 8f08147..6e81d8a 100644 --- a/src/mesh.rs +++ b/src/mesh.rs @@ -150,13 +150,13 @@ pub fn convert(roblox_mesh_bytes:crate::data::RobloxMeshBytes)->Result{ let color_id=acquire_color_id([1.0f32;4]); polygon_groups.push(PolygonGroup::PolygonList(PolygonList::new(mesh.vertices.chunks_exact(3).map(|trip|{ - let mut ingest_vertex1=|vertex:rbx_mesh::mesh::Vertex1|Ok(acquire_vertex_id(IndexedVertex{ + let mut ingest_vertex1=|vertex:&rbx_mesh::mesh::Vertex1|Ok(acquire_vertex_id(IndexedVertex{ pos:acquire_pos_id(vertex.pos)?, tex:acquire_tex_id([vertex.tex[0],vertex.tex[1]]), normal:acquire_normal_id(vertex.norm)?, color:color_id, })); - Ok(vec![ingest_vertex1(trip[0])?,ingest_vertex1(trip[1])?,ingest_vertex1(trip[2])?]) + Ok(vec![ingest_vertex1(&trip[0])?,ingest_vertex1(&trip[1])?,ingest_vertex1(&trip[2])?]) }).collect::>()?))); }, rbx_mesh::mesh::VersionedMesh::Version2(mesh)=>{ diff --git a/src/rbx.rs b/src/rbx.rs index 89fe82c..41b3d7f 100644 --- a/src/rbx.rs +++ b/src/rbx.rs @@ -706,7 +706,7 @@ where transform:model_transform, color:glam::vec4(color3.r as f32/255f32, color3.g as f32/255f32, color3.b as f32/255f32, 1.0-*transparency), deferred_attributes:GetAttributesArgs{ - name:object.name.into(), + name:object.name.as_str().into(), can_collide:*can_collide, velocity:Planar64Vec3::try_from([velocity.x,velocity.y,velocity.z]).unwrap(), }, @@ -735,7 +735,7 @@ pub struct PartialMap1{ } impl PartialMap1{ pub fn add_meshpart_meshes_and_calculate_attributes( - self, + mut self, meshpart_meshes:impl IntoIterator, )->PartialMap2 where @@ -761,13 +761,31 @@ impl PartialMap1{ }, } ).collect(); + + let mut mesh_id_from_render_config_id=HashMap::new(); + let mut acquire_mesh_id_from_render_config_id=|old_mesh_id,render|{ + let mesh=&loaded_meshes[&old_mesh_id]; + *mesh_id_from_render_config_id.entry(old_mesh_id).or_insert_with(||HashMap::new()) + .entry(render).or_insert_with(||{ + let mesh_id=model::MeshId::new(self.primitive_meshes.len() as u32); + let mut mesh_clone=mesh.clone(); + //add a render group lool + mesh_clone.graphics_groups.push(model::IndexedGraphicsGroup{ + render, + //guess that highest lod is highest quality + groups:vec![model::PolygonGroupId::new(mesh_clone.polygon_groups.len() as u32)] + }); + self.primitive_meshes.push(mesh_clone); + mesh_id + }) + }; //now that the meshes are loaded, these models can be generated - let models_owned_attributes=self.deferred_models_deferred_attributes.into_iter().map(|deferred_model_deferred_attributes|{ - let render=deferred_model_deferred_attributes.render; + let models_owned_attributes:Vec= + self.deferred_models_deferred_attributes.into_iter().map(|deferred_model_deferred_attributes|{ //meshes need to be cloned from loaded_meshes with a new id when they are used with a new render_id //insert into primitive_meshes ModelDeferredAttributes{ - mesh:deferred_model_deferred_attributes.model.mesh, + mesh:acquire_mesh_id_from_render_config_id(deferred_model_deferred_attributes.model.mesh,deferred_model_deferred_attributes.render), deferred_attributes:deferred_model_deferred_attributes.model.deferred_attributes, color:deferred_model_deferred_attributes.model.color, transform:deferred_model_deferred_attributes.model.transform, @@ -797,7 +815,7 @@ impl PartialMap1{ //TODO: errors/prints if let Some(wormhole_id)=wormhole_in_model_to_id.get(&model_id){ if let Some(&wormhole_out_model_id)=wormhole_id_to_out_model.get(wormhole_id){ - match &mut model_owned_attributes.deferred_attributes{ + match &mut model_owned_attributes.attributes{ attr::CollisionAttributes::Contact{contacting:_,general} |attr::CollisionAttributes::Intersect{intersecting:_,general} =>general.wormhole=Some(attr::Wormhole{destination_model:wormhole_out_model_id}), @@ -807,12 +825,12 @@ impl PartialMap1{ } //index the attributes - let attributes_id=if let Some(&attributes_id)=attributes_id_from_attributes.get(&model_owned_attributes.deferred_attributes){ + let attributes_id=if let Some(&attributes_id)=attributes_id_from_attributes.get(&model_owned_attributes.attributes){ attributes_id }else{ let attributes_id=attr::CollisionAttributesId::new(unique_attributes.len() as u32); - attributes_id_from_attributes.insert(model_owned_attributes.deferred_attributes.clone(),attributes_id); - unique_attributes.push(model_owned_attributes.deferred_attributes); + attributes_id_from_attributes.insert(model_owned_attributes.attributes.clone(),attributes_id); + unique_attributes.push(model_owned_attributes.attributes); attributes_id }; model::Model{ @@ -823,7 +841,7 @@ impl PartialMap1{ } }).collect(); PartialMap2{ - meshes, + meshes:self.primitive_meshes, models, modes:modes_builder.build(), attributes:unique_attributes,