insanity
This commit is contained in:
parent
118ce9b239
commit
7dfb421016
131
src/rbx.rs
131
src/rbx.rs
@ -134,8 +134,7 @@ impl ModesBuilder{
|
||||
self.stage_updates.push((mode_id,stage_id,stage_update));
|
||||
}
|
||||
}
|
||||
fn get_attributes(object:&rbx_dom_weak::Instance,can_collide:bool,velocity:Planar64Vec3,model_id:model::ModelId,modes_builder:&mut ModesBuilder,wormhole_in_model_to_id:&mut HashMap<model::ModelId,u32>,wormhole_id_to_out_model:&mut HashMap<u32,model::ModelId>)->attr::CollisionAttributes{
|
||||
let name=object.name.as_str();
|
||||
fn get_attributes(name:&str,can_collide:bool,velocity:Planar64Vec3,model_id:model::ModelId,modes_builder:&mut ModesBuilder,wormhole_in_model_to_id:&mut HashMap<model::ModelId,u32>,wormhole_id_to_out_model:&mut HashMap<u32,model::ModelId>)->attr::CollisionAttributes{
|
||||
let mut general=attr::GeneralAttributes::default();
|
||||
let mut intersecting=attr::IntersectingAttributes::default();
|
||||
let mut contacting=attr::ContactingAttributes::default();
|
||||
@ -408,18 +407,26 @@ enum RobloxBasePartDescription{
|
||||
Cylinder(RobloxPartDescription),
|
||||
Wedge(RobloxWedgeDescription),
|
||||
CornerWedge(RobloxCornerWedgeDescription),
|
||||
MeshPart(RobloxMeshPartDescription)
|
||||
}
|
||||
enum Shape{
|
||||
Primitive(primitives::Primitives),
|
||||
MeshPart,
|
||||
}
|
||||
struct ModelOwnedAttributes{
|
||||
enum MeshAvailability{
|
||||
Immediate,
|
||||
Deferred,
|
||||
}
|
||||
struct ModelDeferredAttributes{
|
||||
mesh:model::MeshId,
|
||||
attributes:attr::CollisionAttributes,
|
||||
deferred_attributes:GetAttributesArgs,
|
||||
color:model::Color4,//transparency is in here
|
||||
transform:Planar64Affine3,
|
||||
}
|
||||
struct GetAttributesArgs{
|
||||
name:Box<str>,
|
||||
can_collide:bool,
|
||||
velocity:Planar64Vec3,
|
||||
}
|
||||
pub fn convert<AcquireRenderConfigId,AcquireMeshId>(
|
||||
dom:&rbx_dom_weak::WeakDom,
|
||||
mut acquire_render_config_id:AcquireRenderConfigId,
|
||||
@ -431,9 +438,10 @@ where
|
||||
{
|
||||
let mut modes_builder=ModesBuilder::default();
|
||||
|
||||
let mut models1=Vec::new();
|
||||
let mut meshes=Vec::new();
|
||||
let mut indexed_model_id_from_description=HashMap::new();
|
||||
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();
|
||||
@ -480,7 +488,7 @@ where
|
||||
}
|
||||
|
||||
//at this point a new model is going to be generated for sure.
|
||||
let model_id=model::ModelId::new(models1.len() as u32);
|
||||
let model_id=model::ModelId::new(primitive_models_deferred_attributes.len() as u32);
|
||||
|
||||
//TODO: also detect "CylinderMesh" etc here
|
||||
let shape=match object.class.as_str(){
|
||||
@ -506,7 +514,7 @@ where
|
||||
}
|
||||
};
|
||||
|
||||
let basepart_description=match shape{
|
||||
let (availability,mesh_id)=match shape{
|
||||
Shape::Primitive(primitive_shape)=>{
|
||||
//use the biggest one and cut it down later...
|
||||
let mut part_texture_description:RobloxPartDescription=[None,None,None,None,None,None];
|
||||
@ -584,7 +592,7 @@ where
|
||||
f4,//Cube::Bottom
|
||||
f5,//Cube::Front
|
||||
]=part_texture_description;
|
||||
match primitive_shape{
|
||||
let basepart_description=match primitive_shape{
|
||||
primitives::Primitives::Sphere=>RobloxBasePartDescription::Sphere([f0,f1,f2,f3,f4,f5]),
|
||||
primitives::Primitives::Cube=>RobloxBasePartDescription::Part([f0,f1,f2,f3,f4,f5]),
|
||||
primitives::Primitives::Cylinder=>RobloxBasePartDescription::Cylinder([f0,f1,f2,f3,f4,f5]),
|
||||
@ -604,31 +612,15 @@ where
|
||||
f4,//Cube::Bottom->CornerWedge::Bottom
|
||||
f5,//Cube::Front->CornerWedge::Front
|
||||
]),
|
||||
}
|
||||
},
|
||||
Shape::MeshPart=>if let (
|
||||
Some(rbx_dom_weak::types::Variant::Content(mesh_asset_id)),
|
||||
Some(rbx_dom_weak::types::Variant::Content(texture_asset_id)),
|
||||
)=(
|
||||
object.properties.get("MeshId"),
|
||||
object.properties.get("TextureID"),
|
||||
){
|
||||
RobloxBasePartDescription::MeshPart(RobloxMeshPartDescription{
|
||||
render:acquire_render_config_id(Some(texture_asset_id.as_ref())),
|
||||
mesh:acquire_mesh_id(mesh_asset_id.as_ref()),
|
||||
})
|
||||
}else{
|
||||
panic!("Mesh has no Mesh or Texture");
|
||||
},
|
||||
};
|
||||
//make new model if unit cube has not been created before
|
||||
let indexed_model_id=if let Some(&indexed_model_id)=indexed_model_id_from_description.get(&basepart_description){
|
||||
let mesh_id=if let Some(&mesh_id)=mesh_id_from_description.get(&basepart_description){
|
||||
//push to existing texture model
|
||||
indexed_model_id
|
||||
mesh_id
|
||||
}else{
|
||||
let indexed_model_id=model::MeshId::new(meshes.len() as u32);
|
||||
indexed_model_id_from_description.insert(basepart_description.clone(),indexed_model_id);//borrow checker going crazy
|
||||
let mesh_option=match basepart_description{
|
||||
let mesh_id=model::MeshId::new(primitive_meshes.len() as u32);
|
||||
mesh_id_from_description.insert(basepart_description.clone(),mesh_id);//borrow checker going crazy
|
||||
let mesh=match basepart_description{
|
||||
RobloxBasePartDescription::Sphere(part_texture_description)
|
||||
|RobloxBasePartDescription::Cylinder(part_texture_description)
|
||||
|RobloxBasePartDescription::Part(part_texture_description)=>{
|
||||
@ -649,7 +641,7 @@ where
|
||||
None=>primitives::FaceDescription::new_with_render_id(textureless_render_group),
|
||||
});
|
||||
}
|
||||
Some(primitives::generate_partial_unit_cube(cube_face_description))
|
||||
primitives::generate_partial_unit_cube(cube_face_description)
|
||||
},
|
||||
RobloxBasePartDescription::Wedge(wedge_texture_description)=>{
|
||||
let mut wedge_face_description=primitives::WedgeFaceDescription::default();
|
||||
@ -668,7 +660,7 @@ where
|
||||
None=>primitives::FaceDescription::new_with_render_id(textureless_render_group),
|
||||
});
|
||||
}
|
||||
Some(primitives::generate_partial_unit_wedge(wedge_face_description))
|
||||
primitives::generate_partial_unit_wedge(wedge_face_description)
|
||||
},
|
||||
RobloxBasePartDescription::CornerWedge(cornerwedge_texture_description)=>{
|
||||
let mut cornerwedge_face_description=primitives::CornerWedgeFaceDescription::default();
|
||||
@ -687,45 +679,50 @@ where
|
||||
None=>primitives::FaceDescription::new_with_render_id(textureless_render_group),
|
||||
});
|
||||
}
|
||||
Some(primitives::generate_partial_unit_cornerwedge(cornerwedge_face_description))
|
||||
primitives::generate_partial_unit_cornerwedge(cornerwedge_face_description)
|
||||
},
|
||||
RobloxBasePartDescription::MeshPart(meshpart)=>{
|
||||
//meshpart.mesh
|
||||
}
|
||||
};
|
||||
if let Some(mesh)=mesh_option{
|
||||
meshes.push(mesh);
|
||||
indexed_model_id
|
||||
primitive_meshes.push(mesh);
|
||||
mesh_id
|
||||
};
|
||||
(MeshAvailability::Immediate,mesh_id)
|
||||
},
|
||||
Shape::MeshPart=>if let (
|
||||
Some(rbx_dom_weak::types::Variant::Content(mesh_asset_id)),
|
||||
Some(rbx_dom_weak::types::Variant::Content(texture_asset_id)),
|
||||
)=(
|
||||
object.properties.get("MeshId"),
|
||||
object.properties.get("TextureID"),
|
||||
){
|
||||
(MeshAvailability::Deferred,acquire_mesh_id(mesh_asset_id.as_ref()))
|
||||
}else{
|
||||
//somehow ??
|
||||
//copy bsp_loader strat
|
||||
}
|
||||
panic!("Mesh has no Mesh or Texture");
|
||||
},
|
||||
};
|
||||
let attributes=get_attributes(
|
||||
&object,
|
||||
*can_collide,
|
||||
Planar64Vec3::try_from([velocity.x,velocity.y,velocity.z]).unwrap(),
|
||||
model_id,
|
||||
&mut modes_builder,
|
||||
&mut wormhole_in_model_to_id,
|
||||
&mut wormhole_id_to_out_model,
|
||||
);
|
||||
models1.push(ModelOwnedAttributes{
|
||||
mesh:indexed_model_id,
|
||||
let model_deferred_attributes=ModelDeferredAttributes{
|
||||
mesh:mesh_id,
|
||||
transform:model_transform,
|
||||
color:glam::vec4(color3.r as f32/255f32, color3.g as f32/255f32, color3.b as f32/255f32, 1.0-*transparency),
|
||||
attributes,
|
||||
});
|
||||
deferred_attributes:GetAttributesArgs{
|
||||
name:object.name.into(),
|
||||
can_collide:*can_collide,
|
||||
velocity:Planar64Vec3::try_from([velocity.x,velocity.y,velocity.z]).unwrap(),
|
||||
},
|
||||
};
|
||||
match availability{
|
||||
MeshAvailability::Immediate=>primitive_models_deferred_attributes.push(model_deferred_attributes),
|
||||
MeshAvailability::Deferred=>deferred_models_deferred_attributes.push(model_deferred_attributes),
|
||||
}
|
||||
}
|
||||
}
|
||||
let models=models1.into_iter().enumerate().map(|(model_id,mut model1)|{
|
||||
}
|
||||
let primitive_models=primitive_models_deferred_attributes.into_iter().enumerate().map(|(model_id,mut model_owned_attributes)|{
|
||||
let model_id=model::ModelId::new(model_id as u32);
|
||||
//update attributes with wormhole id
|
||||
//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 model1.attributes{
|
||||
match &mut model_owned_attributes.deferred_attributes{
|
||||
attr::CollisionAttributes::Contact{contacting:_,general}
|
||||
|attr::CollisionAttributes::Intersect{intersecting:_,general}
|
||||
=>general.wormhole=Some(attr::Wormhole{destination_model:wormhole_out_model_id}),
|
||||
@ -735,24 +732,24 @@ where
|
||||
}
|
||||
|
||||
//index the attributes
|
||||
let attributes_id=if let Some(&attributes_id)=attributes_id_from_attributes.get(&model1.attributes){
|
||||
let attributes_id=if let Some(&attributes_id)=attributes_id_from_attributes.get(&model_owned_attributes.deferred_attributes){
|
||||
attributes_id
|
||||
}else{
|
||||
let attributes_id=attr::CollisionAttributesId::new(unique_attributes.len() as u32);
|
||||
attributes_id_from_attributes.insert(model1.attributes.clone(),attributes_id);
|
||||
unique_attributes.push(model1.attributes);
|
||||
attributes_id_from_attributes.insert(model_owned_attributes.deferred_attributes.clone(),attributes_id);
|
||||
unique_attributes.push(model_owned_attributes.deferred_attributes);
|
||||
attributes_id
|
||||
};
|
||||
model::Model{
|
||||
mesh:model1.mesh,
|
||||
transform:model1.transform,
|
||||
color:model1.color,
|
||||
mesh:model_owned_attributes.mesh,
|
||||
transform:model_owned_attributes.transform,
|
||||
color:model_owned_attributes.color,
|
||||
attributes:attributes_id,
|
||||
}
|
||||
}).collect();
|
||||
PartialMap1{
|
||||
meshes,
|
||||
models,
|
||||
meshes:primitive_meshes,
|
||||
models:primitive_models,
|
||||
modes:modes_builder.build(),
|
||||
attributes:unique_attributes,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user