diff --git a/src/lib.rs b/src/lib.rs index bd50f4b..c932c58 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,21 @@ use std::io::Read; mod rbx; +mod mesh; mod primitives; +pub mod data{ + pub struct RobloxMeshBytes(Vec); + impl RobloxMeshBytes{ + pub fn new(bytes:Vec)->Self{ + Self(bytes) + } + pub fn cursor(self)->std::io::Cursor>{ + std::io::Cursor::new(self.0) + } + } +} + pub struct Dom(rbx_dom_weak::WeakDom); #[derive(Debug)] diff --git a/src/mesh.rs b/src/mesh.rs new file mode 100644 index 0000000..c6a2196 --- /dev/null +++ b/src/mesh.rs @@ -0,0 +1,4 @@ +pub fn convert(roblox_mesh_bytes:crate::data::RobloxMeshBytes)->Result{ + let versioned_mesh=rbx_mesh::read_versioned(roblox_mesh_bytes.cursor())?; + //generate that mesh boi +} \ No newline at end of file diff --git a/src/rbx.rs b/src/rbx.rs index 1961f43..4086555 100644 --- a/src/rbx.rs +++ b/src/rbx.rs @@ -396,11 +396,6 @@ type RobloxPartDescription=[Option;6]; type RobloxWedgeDescription=[Option;5]; type RobloxCornerWedgeDescription=[Option;5]; #[derive(Clone,Eq,Hash,PartialEq)] -struct RobloxMeshPartDescription{ - render:RenderConfigId, - mesh:model::MeshId, -} -#[derive(Clone,Eq,Hash,PartialEq)] enum RobloxBasePartDescription{ Sphere(RobloxPartDescription), Part(RobloxPartDescription), @@ -414,7 +409,11 @@ enum Shape{ } enum MeshAvailability{ Immediate, - Deferred, + Deferred(RenderConfigId), +} +struct DeferredModelDeferredAttributes{ + render:RenderConfigId, + model:ModelDeferredAttributes, } struct ModelDeferredAttributes{ mesh:model::MeshId, @@ -422,6 +421,12 @@ struct ModelDeferredAttributes{ color:model::Color4,//transparency is in here transform:Planar64Affine3, } +struct ModelOwnedAttributes{ + mesh:model::MeshId, + attributes:attr::CollisionAttributes, + color:model::Color4,//transparency is in here + transform:Planar64Affine3, +} struct GetAttributesArgs{ name:Box, can_collide:bool, @@ -436,19 +441,12 @@ where AcquireRenderConfigId:FnMut(Option<&str>)->model::RenderConfigId, AcquireMeshId:FnMut(&str)->model::MeshId, { - let mut modes_builder=ModesBuilder::default(); let mut deferred_models_deferred_attributes=Vec::new(); let mut primitive_models_deferred_attributes=Vec::new(); let mut primitive_meshes=Vec::new(); let mut mesh_id_from_description=HashMap::new(); - let mut unique_attributes=Vec::new(); - let mut attributes_id_from_attributes=HashMap::new(); - - let mut wormhole_in_model_to_id=HashMap::new(); - let mut wormhole_id_to_out_model=HashMap::new(); - //just going to leave it like this for now instead of reworking the data structures for this whole thing let textureless_render_group=acquire_render_config_id(None); @@ -516,6 +514,7 @@ where let (availability,mesh_id)=match shape{ Shape::Primitive(primitive_shape)=>{ + //TODO: TAB TAB //use the biggest one and cut it down later... let mut part_texture_description:RobloxPartDescription=[None,None,None,None,None,None]; temp_objects.clear(); @@ -694,7 +693,10 @@ where object.properties.get("MeshId"), object.properties.get("TextureID"), ){ - (MeshAvailability::Deferred,acquire_mesh_id(mesh_asset_id.as_ref())) + ( + MeshAvailability::Deferred(acquire_render_config_id(Some(texture_asset_id.as_ref()))), + acquire_mesh_id(mesh_asset_id.as_ref()), + ) }else{ panic!("Mesh has no Mesh or Texture"); }, @@ -711,12 +713,76 @@ where }; match availability{ MeshAvailability::Immediate=>primitive_models_deferred_attributes.push(model_deferred_attributes), - MeshAvailability::Deferred=>deferred_models_deferred_attributes.push(model_deferred_attributes), + MeshAvailability::Deferred(render)=>deferred_models_deferred_attributes.push(DeferredModelDeferredAttributes{ + render, + model:model_deferred_attributes + }), } } } } - let primitive_models=primitive_models_deferred_attributes.into_iter().enumerate().map(|(model_id,mut model_owned_attributes)|{ + PartialMap1{ + primitive_meshes, + primitive_models_deferred_attributes, + deferred_models_deferred_attributes, + } +} + +pub struct PartialMap1{ + primitive_meshes:Vec, + primitive_models_deferred_attributes:Vec, + deferred_models_deferred_attributes:Vec, +} +impl PartialMap1{ + pub fn add_meshpart_meshes_and_calculate_attributes( + self, + meshpart_meshes:impl IntoIterator, + )->PartialMap2 + where + AcquireRenderConfigId:FnMut(Option<&str>)->model::RenderConfigId, + { + //calculate attributes + let mut modes_builder=ModesBuilder::default(); + let mut unique_attributes=Vec::new(); + let mut attributes_id_from_attributes=HashMap::new(); + + let mut wormhole_in_model_to_id=HashMap::new(); + let mut wormhole_id_to_out_model=HashMap::new(); + + //decode roblox meshes + //generate mesh_id map based on meshes that failed to load + let mut meshes=meshpart_meshes.into_iter().flat_map(|(old_mesh_id,roblox_mesh_bytes)|{ + Ok((old_mesh_id,crate::mesh::convert(roblox_mesh_bytes)?)) + }).collect(); + //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;//what does this do? + ModelDeferredAttributes{ + mesh:deferred_model_deferred_attributes.model.mesh, + deferred_attributes:deferred_model_deferred_attributes.model.deferred_attributes, + color:deferred_model_deferred_attributes.model.color, + transform:deferred_model_deferred_attributes.model.transform, + } + }).chain(self.primitive_models_deferred_attributes.into_iter()) + .enumerate().map(|(model_id,model_deferred_attributes)|{ + let model_id=model::ModelId::new(model_id as u32); + ModelOwnedAttributes{ + mesh:model_deferred_attributes.mesh, + attributes:get_attributes( + &model_deferred_attributes.deferred_attributes.name, + model_deferred_attributes.deferred_attributes.can_collide, + model_deferred_attributes.deferred_attributes.velocity, + model_id, + &mut modes_builder, + &mut wormhole_in_model_to_id, + &mut wormhole_id_to_out_model, + ), + color:model_deferred_attributes.color, + transform:model_deferred_attributes.transform, + } + }).collect(); + let models=models_owned_attributes.into_iter().enumerate().map(|(model_id,mut model_owned_attributes)|{ + //TODO: TAB let model_id=model::ModelId::new(model_id as u32); //update attributes with wormhole id //TODO: errors/prints @@ -747,21 +813,22 @@ where attributes:attributes_id, } }).collect(); - PartialMap1{ - meshes:primitive_meshes, - models:primitive_models, + PartialMap2{ + meshes, + models, modes:modes_builder.build(), attributes:unique_attributes, } + } } -pub struct PartialMap1{ +pub struct PartialMap2{ meshes:Vec, models:Vec, modes:gameplay_modes::Modes, attributes:Vec, } -impl PartialMap1{ +impl PartialMap2{ pub fn add_render_configs_and_textures( self, render_configs:impl IntoIterator,