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