getting there

This commit is contained in:
Quaternions 2024-03-12 18:08:44 -07:00
parent 7dfb421016
commit f6d5972743
3 changed files with 105 additions and 21 deletions

View File

@ -1,8 +1,21 @@
use std::io::Read;
mod rbx;
mod mesh;
mod primitives;
pub mod data{
pub struct RobloxMeshBytes(Vec<u8>);
impl RobloxMeshBytes{
pub fn new(bytes:Vec<u8>)->Self{
Self(bytes)
}
pub fn cursor(self)->std::io::Cursor<Vec<u8>>{
std::io::Cursor::new(self.0)
}
}
}
pub struct Dom(rbx_dom_weak::WeakDom);
#[derive(Debug)]

4
src/mesh.rs Normal file
View File

@ -0,0 +1,4 @@
pub fn convert(roblox_mesh_bytes:crate::data::RobloxMeshBytes)->Result<strafesnet_common::model::Mesh,rbx_mesh::mesh::Error>{
let versioned_mesh=rbx_mesh::read_versioned(roblox_mesh_bytes.cursor())?;
//generate that mesh boi
}

View File

@ -396,11 +396,6 @@ type RobloxPartDescription=[Option<RobloxFaceTextureDescription>;6];
type RobloxWedgeDescription=[Option<RobloxFaceTextureDescription>;5];
type RobloxCornerWedgeDescription=[Option<RobloxFaceTextureDescription>;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<str>,
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<model::Mesh>,
primitive_models_deferred_attributes:Vec<ModelDeferredAttributes>,
deferred_models_deferred_attributes:Vec<DeferredModelDeferredAttributes>,
}
impl PartialMap1{
pub fn add_meshpart_meshes_and_calculate_attributes<AcquireRenderConfigId>(
self,
meshpart_meshes:impl IntoIterator<Item=(model::MeshId,crate::data::RobloxMeshBytes)>,
)->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<model::Mesh>,
models:Vec<model::Model>,
modes:gameplay_modes::Modes,
attributes:Vec<strafesnet_common::gameplay_attributes::CollisionAttributes>,
}
impl PartialMap1{
impl PartialMap2{
pub fn add_render_configs_and_textures(
self,
render_configs:impl IntoIterator<Item=(model::RenderConfigId,model::RenderConfig)>,