TEMP: teleport to spawn point

This commit is contained in:
Quaternions 2023-09-21 14:05:08 -07:00
parent 2af43480f1
commit 28cad39b10
3 changed files with 41 additions and 18 deletions

View File

@ -16,6 +16,8 @@ pub enum PhysicsInstruction {
// bool,//true = Trigger; false = teleport // bool,//true = Trigger; false = teleport
// bool,//true = Force // bool,//true = Force
// ) // )
//temp
SetPosition(glam::Vec3),
} }
pub struct Body { pub struct Body {
@ -756,6 +758,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
//selectively update body //selectively update body
match &ins.instruction { match &ins.instruction {
PhysicsInstruction::SetWalkTargetVelocity(_) PhysicsInstruction::SetWalkTargetVelocity(_)
|PhysicsInstruction::SetPosition(_)
|PhysicsInstruction::SetControlDir(_) => self.time=ins.time,//TODO: queue instructions |PhysicsInstruction::SetControlDir(_) => self.time=ins.time,//TODO: queue instructions
PhysicsInstruction::RefreshWalkTarget PhysicsInstruction::RefreshWalkTarget
|PhysicsInstruction::ReachWalkTargetVelocity |PhysicsInstruction::ReachWalkTargetVelocity
@ -765,6 +768,15 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|PhysicsInstruction::Jump => self.advance_time(ins.time), |PhysicsInstruction::Jump => self.advance_time(ins.time),
} }
match ins.instruction { match ins.instruction {
PhysicsInstruction::SetPosition(position)=>{
//temp
self.body.position=position;
//manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))}
self.contacts.clear();
self.body.acceleration=self.gravity;
self.walk.state=WalkEnum::Reached;
self.grounded=false;
}
PhysicsInstruction::CollisionStart(c) => { PhysicsInstruction::CollisionStart(c) => {
//check ground //check ground
match &c.face { match &c.face {
@ -854,4 +866,4 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
}, },
} }
} }
} }

View File

@ -53,6 +53,7 @@ impl std::str::FromStr for RobloxAssetId {
} }
pub fn generate_modeldatas_roblox(dom:&rbx_dom_weak::WeakDom) -> Result<(Vec<ModelData>,Vec<std::fs::File>), Box<dyn std::error::Error>>{ pub fn generate_modeldatas_roblox(dom:&rbx_dom_weak::WeakDom) -> Result<(Vec<ModelData>,Vec<std::fs::File>), Box<dyn std::error::Error>>{
//ModelData includes texture dds //ModelData includes texture dds
let mut spawn_point=glam::Vec3::ZERO;
//TODO: generate unit Block, Wedge, etc. after based on part shape lists //TODO: generate unit Block, Wedge, etc. after based on part shape lists
let mut modeldatas=crate::model::generate_modeldatas(primitives::the_unit_cube_lol(),ModelData::COLOR_FLOATS_WHITE); let mut modeldatas=crate::model::generate_modeldatas(primitives::the_unit_cube_lol(),ModelData::COLOR_FLOATS_WHITE);
@ -80,6 +81,26 @@ pub fn generate_modeldatas_roblox(dom:&rbx_dom_weak::WeakDom) -> Result<(Vec<Mod
object.properties.get("Shape"),//this will also skip unions object.properties.get("Shape"),//this will also skip unions
) )
{ {
let model_instance=ModelInstance {
transform:glam::Mat4::from_translation(
glam::Vec3::new(cf.position.x,cf.position.y,cf.position.z)
)
* glam::Mat4::from_mat3(
glam::Mat3::from_cols(
glam::Vec3::new(cf.orientation.x.x,cf.orientation.y.x,cf.orientation.z.x),
glam::Vec3::new(cf.orientation.x.y,cf.orientation.y.y,cf.orientation.z.y),
glam::Vec3::new(cf.orientation.x.z,cf.orientation.y.z,cf.orientation.z.z),
),
)
* glam::Mat4::from_scale(
glam::Vec3::new(size.x,size.y,size.z)/2.0
),
color: glam::vec4(color3.r as f32/255f32, color3.g as f32/255f32, color3.b as f32/255f32, 1.0-*transparency),
};
if object.name=="MapStart"{
spawn_point=glam::Vec4Swizzles::xyz(model_instance.transform*glam::Vec3::Y.extend(1.0))+glam::vec3(0.0,2.5,0.0);
println!("Found MapStart{:?}",spawn_point);
}
if *transparency==1.0||shape.to_u32()!=1 { if *transparency==1.0||shape.to_u32()!=1 {
continue; continue;
} }
@ -106,22 +127,6 @@ pub fn generate_modeldatas_roblox(dom:&rbx_dom_weak::WeakDom) -> Result<(Vec<Mod
} }
} }
} }
let model_instance=ModelInstance {
transform:glam::Mat4::from_translation(
glam::Vec3::new(cf.position.x,cf.position.y,cf.position.z)
)
* glam::Mat4::from_mat3(
glam::Mat3::from_cols(
glam::Vec3::new(cf.orientation.x.x,cf.orientation.y.x,cf.orientation.z.x),
glam::Vec3::new(cf.orientation.x.y,cf.orientation.y.y,cf.orientation.z.y),
glam::Vec3::new(cf.orientation.x.z,cf.orientation.y.z,cf.orientation.z.z),
),
)
* glam::Mat4::from_scale(
glam::Vec3::new(size.x,size.y,size.z)/2.0
),
color: glam::vec4(color3.r as f32/255f32, color3.g as f32/255f32, color3.b as f32/255f32, 1.0-*transparency),
};
match i_can_only_load_one_texture_per_model{ match i_can_only_load_one_texture_per_model{
//push to existing texture model //push to existing texture model
Some(texture_id)=>modeldatas[(texture_id+1) as usize].instances.push(model_instance), Some(texture_id)=>modeldatas[(texture_id+1) as usize].instances.push(model_instance),
@ -134,5 +139,5 @@ pub fn generate_modeldatas_roblox(dom:&rbx_dom_weak::WeakDom) -> Result<(Vec<Mod
let texture_files:Result<Vec<std::fs::File>,_>=asset_id_from_texture_id.iter().map(|asset_id|{ let texture_files:Result<Vec<std::fs::File>,_>=asset_id_from_texture_id.iter().map(|asset_id|{
std::fs::File::open(std::path::Path::new(&format!("textures/{}.dds",asset_id))) std::fs::File::open(std::path::Path::new(&format!("textures/{}.dds",asset_id)))
}).collect(); }).collect();
Ok((modeldatas,texture_files?)) Ok((modeldatas,texture_files?,spawn_point))
} }

View File

@ -760,6 +760,12 @@ impl framework::Example for GraphicsData {
//self.physics.models.clear(); //self.physics.models.clear();
//self.generate_model_physics(&modeldatas); //self.generate_model_physics(&modeldatas);
//self.generate_model_graphics(device,queue,modeldatas,textures); //self.generate_model_graphics(device,queue,modeldatas,textures);
//manual reset
//let time=self.physics.time;
//instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{
// time,
// instruction: body::PhysicsInstruction::SetPosition(spawn_point),
//})
}else{ }else{
println!("Could not open file"); println!("Could not open file");
} }