Compare commits
13 Commits
load-roblo
...
load-roblo
| Author | SHA1 | Date | |
|---|---|---|---|
| f42b1669db | |||
| 00f9afbedb | |||
| 4388f66995 | |||
| f7e48be228 | |||
| 1b646bbb4b | |||
| eeb9623985 | |||
| 99e917a567 | |||
| 34ca5c58be | |||
| a5152052a8 | |||
| 3e18284594 | |||
| cc71162f1c | |||
| a0d4cf2d92 | |||
| c139ff1a13 |
BIN
maps/bhop_easyhop.rbxm
Normal file
BIN
maps/bhop_easyhop.rbxm
Normal file
Binary file not shown.
@@ -51,7 +51,7 @@ pub trait Example: 'static + Sized {
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
);
|
||||
fn update(&mut self, device: &wgpu::Device, event: WindowEvent);
|
||||
fn update(&mut self, event: WindowEvent);
|
||||
fn device_event(&mut self, event: DeviceEvent);
|
||||
fn render(
|
||||
&mut self,
|
||||
@@ -344,7 +344,7 @@ fn start<E: Example>(
|
||||
println!("{:#?}", instance.generate_report());
|
||||
}
|
||||
_ => {
|
||||
example.update(&device,event);
|
||||
example.update(event);
|
||||
}
|
||||
},
|
||||
event::Event::DeviceEvent {
|
||||
|
||||
@@ -10,7 +10,8 @@ fn class_is_a(class: &str, superclass: &str) -> bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
pub fn get_objects<R: std::io::Read>(buf_thing: R, superclass: &str) -> Result<std::vec::Vec<rbx_dom_weak::Instance>, Box<dyn std::error::Error>> {
|
||||
|
||||
pub fn get_objects(buf_thing: std::io::BufReader<&[u8]>, superclass: &str) -> Result<std::vec::Vec<rbx_dom_weak::Instance>, Box<dyn std::error::Error>> {
|
||||
// Using buffered I/O is recommended with rbx_binary
|
||||
let dom = rbx_binary::from_reader(buf_thing)?;
|
||||
|
||||
|
||||
181
src/main.rs
181
src/main.rs
@@ -31,15 +31,6 @@ struct ModelGraphics {
|
||||
bind_group: wgpu::BindGroup,
|
||||
model_buf: wgpu::Buffer,
|
||||
}
|
||||
|
||||
pub struct GraphicsSamplers{
|
||||
repeat: wgpu::Sampler,
|
||||
}
|
||||
|
||||
pub struct GraphicsBindGroupLayouts{
|
||||
model: wgpu::BindGroupLayout,
|
||||
}
|
||||
|
||||
pub struct GraphicsBindGroups {
|
||||
camera: wgpu::BindGroup,
|
||||
skybox_texture: wgpu::BindGroup,
|
||||
@@ -56,9 +47,6 @@ pub struct GraphicsData {
|
||||
physics: strafe_client::body::PhysicsState,
|
||||
pipelines: GraphicsPipelines,
|
||||
bind_groups: GraphicsBindGroups,
|
||||
bind_group_layouts: GraphicsBindGroupLayouts,
|
||||
samplers: GraphicsSamplers,
|
||||
temp_squid_texture_view: wgpu::TextureView,
|
||||
camera_buf: wgpu::Buffer,
|
||||
models: Vec<ModelGraphics>,
|
||||
depth_view: wgpu::TextureView,
|
||||
@@ -91,8 +79,8 @@ impl GraphicsData {
|
||||
depth_texture.create_view(&wgpu::TextureViewDescriptor::default())
|
||||
}
|
||||
|
||||
fn generate_modeldatas_roblox<R: std::io::Read>(&self,input:R) -> Vec<ModelData>{
|
||||
let mut modeldatas=generate_modeldatas(self.handy_unit_cube.clone());
|
||||
fn generate_modeldatas_roblox(&self,input:std::io::BufReader<&[u8]>) -> Vec<ModelData>{
|
||||
let mut modeldata=generate_modeldatas(self.handy_unit_cube.clone())[0];
|
||||
match strafe_client::load_roblox::get_objects(input, "BasePart") {
|
||||
Ok(objects)=>{
|
||||
for object in objects.iter() {
|
||||
@@ -100,16 +88,18 @@ impl GraphicsData {
|
||||
Some(rbx_dom_weak::types::Variant::CFrame(cf)),
|
||||
Some(rbx_dom_weak::types::Variant::Vector3(size)),
|
||||
Some(rbx_dom_weak::types::Variant::Float32(transparency)),
|
||||
Some(rbx_dom_weak::types::Variant::Color3(color3)),
|
||||
) = (
|
||||
object.properties.get("CFrame"),
|
||||
object.properties.get("Size"),
|
||||
object.properties.get("Transparency"),
|
||||
object.properties.get("Color"),
|
||||
)
|
||||
{
|
||||
if *transparency==1.0 {
|
||||
continue;
|
||||
}
|
||||
modeldatas[0].transforms.push(
|
||||
modeldata.transforms.push(
|
||||
glam::Mat4::from_translation(
|
||||
glam::Vec3::new(cf.position.x,cf.position.y,cf.position.z)
|
||||
)
|
||||
@@ -129,60 +119,10 @@ impl GraphicsData {
|
||||
},
|
||||
Err(e) => println!("lmao err {:?}", e),
|
||||
}
|
||||
modeldatas
|
||||
vec![modeldata]
|
||||
}
|
||||
fn generate_model_graphics(&mut self,device:&wgpu::Device,mut modeldatas:Vec<ModelData>){
|
||||
//drain the modeldata vec so entities can be /moved/ to models.entities
|
||||
self.models.reserve(modeldatas.len());
|
||||
for (i,modeldata) in modeldatas.drain(..).enumerate() {
|
||||
let model_uniforms = get_transform_uniform_data(&modeldata.transforms);
|
||||
let model_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some(format!("ModelGraphics{}",i).as_str()),
|
||||
contents: bytemuck::cast_slice(&model_uniforms),
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
let model_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &self.bind_group_layouts.model,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: model_buf.as_entire_binding(),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::TextureView(&self.temp_squid_texture_view),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::Sampler(&self.samplers.repeat),
|
||||
},
|
||||
],
|
||||
label: Some(format!("ModelGraphics{}",i).as_str()),
|
||||
});
|
||||
let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Vertex"),
|
||||
contents: bytemuck::cast_slice(&modeldata.vertices),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
//all of these are being moved here
|
||||
self.models.push(ModelGraphics{
|
||||
transforms:modeldata.transforms,
|
||||
vertex_buf,
|
||||
entities: modeldata.entities.iter().map(|indices|{
|
||||
let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Index"),
|
||||
contents: bytemuck::cast_slice(&indices),
|
||||
usage: wgpu::BufferUsages::INDEX,
|
||||
});
|
||||
Entity {
|
||||
index_buf,
|
||||
index_count: indices.len() as u32,
|
||||
}
|
||||
}).collect(),
|
||||
bind_group: model_bind_group,
|
||||
model_buf,
|
||||
})
|
||||
}
|
||||
fn generate_model_graphics(&mut self,modeldatas:Vec<ModelData>){
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,13 +136,11 @@ fn get_transform_uniform_data(transforms:&Vec<glam::Mat4>) -> Vec<f32> {
|
||||
raw
|
||||
}
|
||||
|
||||
fn generate_modeldatas(data:obj::ObjData) -> Vec<ModelData>{
|
||||
fn generate_modeldatas<'a>(data:obj::ObjData) -> &'a mut Vec<ModelData>{
|
||||
let mut modeldatas=Vec::new();
|
||||
let mut vertices = Vec::new();
|
||||
let mut vertex_index = std::collections::HashMap::<obj::IndexTuple,u16>::new();
|
||||
for object in data.objects {
|
||||
vertices.clear();
|
||||
vertex_index.clear();
|
||||
let mut entities = Vec::new();
|
||||
for group in object.groups {
|
||||
let mut indices = Vec::new();
|
||||
@@ -229,11 +167,11 @@ fn generate_modeldatas(data:obj::ObjData) -> Vec<ModelData>{
|
||||
}
|
||||
modeldatas.push(ModelData {
|
||||
transforms: vec![],
|
||||
vertices:vertices.clone(),
|
||||
vertices,
|
||||
entities,
|
||||
});
|
||||
}
|
||||
modeldatas
|
||||
&mut modeldatas
|
||||
}
|
||||
|
||||
|
||||
@@ -339,21 +277,21 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
material_libs: Vec::new(),
|
||||
};
|
||||
let mut modeldatas = Vec::<ModelData>::new();
|
||||
modeldatas.append(&mut generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teslacyberv3.0.obj")[..]).unwrap()));
|
||||
modeldatas.append(&mut generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/suzanne.obj")[..]).unwrap()));
|
||||
modeldatas.append(&mut generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teapot.obj")[..]).unwrap()));
|
||||
modeldatas.append(&mut generate_modeldatas(unit_cube.clone()));
|
||||
modeldatas.append(generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teslacyberv3.0.obj")[..]).unwrap()));
|
||||
modeldatas.append(generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/suzanne.obj")[..]).unwrap()));
|
||||
modeldatas.append(generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teapot.obj")[..]).unwrap()));
|
||||
modeldatas.append(generate_modeldatas(unit_cube.clone()));
|
||||
println!("models.len = {:?}", modeldatas.len());
|
||||
modeldatas[0].transforms.push(glam::Mat4::from_translation(glam::vec3(10.,0.,-10.)));
|
||||
modeldatas[0].transforms[0]=glam::Mat4::from_translation(glam::vec3(10.,0.,-10.));
|
||||
//quad monkeys
|
||||
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(10.,5.,10.)));
|
||||
modeldatas[1].transforms[0]=glam::Mat4::from_translation(glam::vec3(10.,5.,10.));
|
||||
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(20.,5.,10.)));
|
||||
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(10.,5.,20.)));
|
||||
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(20.,5.,20.)));
|
||||
//teapot
|
||||
modeldatas[2].transforms.push(glam::Mat4::from_translation(glam::vec3(-10.,5.,10.)));
|
||||
modeldatas[2].transforms[0]=glam::Mat4::from_translation(glam::vec3(-10.,5.,10.));
|
||||
//ground
|
||||
modeldatas[3].transforms.push(glam::Mat4::from_translation(glam::vec3(0.,0.,0.))*glam::Mat4::from_scale(glam::vec3(160.0, 1.0, 160.0)));
|
||||
modeldatas[3].transforms[0]=glam::Mat4::from_translation(glam::vec3(0.,0.,0.))*glam::Mat4::from_scale(glam::vec3(160.0, 1.0, 160.0));
|
||||
|
||||
let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
@@ -587,6 +525,58 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
})
|
||||
};
|
||||
|
||||
//drain the modeldata vec so entities can be /moved/ to models.entities
|
||||
let mut models = Vec::<ModelGraphics>::with_capacity(modeldatas.len());
|
||||
for (i,modeldata) in modeldatas.drain(..).enumerate() {
|
||||
let model_uniforms = get_transform_uniform_data(&modeldata.transforms);
|
||||
let model_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some(format!("ModelGraphics{}",i).as_str()),
|
||||
contents: bytemuck::cast_slice(&model_uniforms),
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
let model_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &model_bind_group_layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: model_buf.as_entire_binding(),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::TextureView(&squid_texture_view),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::Sampler(&repeat_sampler),
|
||||
},
|
||||
],
|
||||
label: Some(format!("ModelGraphics{}",i).as_str()),
|
||||
});
|
||||
let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Vertex"),
|
||||
contents: bytemuck::cast_slice(&modeldata.vertices),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
//all of these are being moved here
|
||||
models.push(ModelGraphics{
|
||||
transforms:modeldata.transforms,
|
||||
vertex_buf,
|
||||
entities: modeldata.entities.iter().map(|indices|{
|
||||
let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Index"),
|
||||
contents: bytemuck::cast_slice(&indices),
|
||||
usage: wgpu::BufferUsages::INDEX,
|
||||
});
|
||||
Entity {
|
||||
index_buf,
|
||||
index_count: indices.len() as u32,
|
||||
}
|
||||
}).collect(),
|
||||
bind_group: model_bind_group,
|
||||
model_buf,
|
||||
})
|
||||
}
|
||||
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: None,
|
||||
bind_group_layouts: &[
|
||||
@@ -690,7 +680,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
|
||||
let depth_view = Self::create_depth_texture(config, device);
|
||||
|
||||
let mut graphics=GraphicsData {
|
||||
GraphicsData {
|
||||
handy_unit_cube:unit_cube,
|
||||
start_time: Instant::now(),
|
||||
screen_size: (config.width,config.height),
|
||||
@@ -704,34 +694,23 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
skybox_texture:skybox_texture_bind_group,
|
||||
},
|
||||
camera_buf,
|
||||
models: Vec::new(),
|
||||
models,
|
||||
depth_view,
|
||||
staging_belt: wgpu::util::StagingBelt::new(0x100),
|
||||
bind_group_layouts: GraphicsBindGroupLayouts { model: model_bind_group_layout },
|
||||
samplers: GraphicsSamplers { repeat: repeat_sampler },
|
||||
temp_squid_texture_view: squid_texture_view,
|
||||
};
|
||||
|
||||
graphics.generate_model_graphics(&device,modeldatas);
|
||||
|
||||
return graphics;
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::single_match)]
|
||||
fn update(&mut self, device: &wgpu::Device, event: winit::event::WindowEvent) {
|
||||
fn update(&mut self, event: winit::event::WindowEvent) {
|
||||
//nothing atm
|
||||
match event {
|
||||
winit::event::WindowEvent::DroppedFile(path) => {
|
||||
println!("opening file: {:?}", &path);
|
||||
//oh boy! let's load the map!
|
||||
if let Ok(file)=std::fs::File::open(path){
|
||||
let input = std::io::BufReader::new(file);
|
||||
let modeldatas=self.generate_modeldatas_roblox(input);
|
||||
self.generate_model_graphics(device,modeldatas);
|
||||
//also physics
|
||||
}else{
|
||||
println!("Could not open file");
|
||||
}
|
||||
let file=std::fs::File::open(path);
|
||||
let input = std::io::BufReader::new(file);
|
||||
let modeldatas=self.generate_modeldatas_roblox(input);
|
||||
self.generate_model_graphics(modeldatas);
|
||||
//also physics
|
||||
},
|
||||
_=>(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user