Compare commits

...

4 Commits

Author SHA1 Message Date
a803ada0e4 zeroes2 inline maybe 2023-09-22 19:42:15 -07:00
eafcbae677 add model.rs 2023-09-22 19:42:15 -07:00
2e786b090f no need for hardcoded image size 2023-09-22 15:20:41 -07:00
70e8f7a0ad delete stupid lib file 2023-09-22 15:19:44 -07:00
4 changed files with 68 additions and 67 deletions

@ -1,5 +0,0 @@
pub mod framework;
pub mod body;
pub mod zeroes;
pub mod instruction;
pub mod load_roblox;

@ -1,39 +1,19 @@
use bytemuck::{Pod, Zeroable};
use std::{borrow::Cow, time::Instant};
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
use model::{Vertex,ModelData,ModelInstance};
const IMAGE_SIZE: u32 = 128;
#[derive(Clone, Copy, Pod, Zeroable)]
#[repr(C)]
struct Vertex {
pos: [f32; 3],
texture: [f32; 2],
normal: [f32; 3],
color: [f32; 4],
}
mod body;
mod model;
mod zeroes;
mod framework;
mod instruction;
mod load_roblox;
struct Entity {
index_count: u32,
index_buf: wgpu::Buffer,
}
struct ModelInstance {
transform: glam::Mat4,
color: glam::Vec4,
}
struct ModelData {
instances: Vec<ModelInstance>,
vertices: Vec<Vertex>,
entities: Vec<Vec<u16>>,
}
impl ModelData {
const COLOR_FLOATS_WHITE: [f32;4] = [1.0,1.0,1.0,1.0];
const COLOR_VEC4_WHITE: glam::Vec4 = glam::vec4(1.0,1.0,1.0,1.0);
}
struct ModelGraphics {
instances: Vec<ModelInstance>,
vertex_buf: wgpu::Buffer,
@ -143,7 +123,7 @@ pub struct GraphicsPipelines {
pub struct GraphicsData {
start_time: std::time::Instant,
camera: Camera,
physics: strafe_client::body::PhysicsState,
physics: body::PhysicsState,
pipelines: GraphicsPipelines,
bind_groups: GraphicsBindGroups,
bind_group_layouts: GraphicsBindGroupLayouts,
@ -183,7 +163,7 @@ impl GraphicsData {
fn generate_modeldatas_roblox<R: std::io::Read>(&self,input:R) -> Vec<ModelData>{
let mut modeldatas=generate_modeldatas(self.handy_unit_cube.clone(),ModelData::COLOR_FLOATS_WHITE);
match strafe_client::load_roblox::get_objects(input, "BasePart") {
match load_roblox::get_objects(input, "BasePart") {
Ok(objects)=>{
for object in objects.iter() {
if let (
@ -229,7 +209,7 @@ impl GraphicsData {
fn generate_model_physics(&mut self,modeldatas:&Vec<ModelData>){
self.physics.models.append(&mut modeldatas.iter().map(|m|
//make aabb and run vertices to get realistic bounds
m.instances.iter().map(|t|strafe_client::body::ModelPhysics::new(t.transform))
m.instances.iter().map(|t|body::ModelPhysics::new(t.transform))
).flatten().collect());
println!("Physics Objects: {}",self.physics.models.len());
}
@ -345,7 +325,7 @@ fn generate_modeldatas(data:obj::ObjData,color:[f32;4]) -> Vec<ModelData>{
modeldatas
}
impl strafe_client::framework::Example for GraphicsData {
impl framework::Example for GraphicsData {
fn optional_features() -> wgpu::Features {
wgpu::Features::TEXTURE_COMPRESSION_ASTC
| wgpu::Features::TEXTURE_COMPRESSION_ETC2
@ -578,8 +558,8 @@ impl strafe_client::framework::Example for GraphicsData {
yaw: 0.0,
controls:0,
};
let physics = strafe_client::body::PhysicsState {
body: strafe_client::body::Body::with_pva(glam::vec3(0.0,50.0,0.0),glam::vec3(0.0,0.0,0.0),glam::vec3(0.0,-100.0,0.0)),
let physics = body::PhysicsState {
body: body::Body::with_pva(glam::vec3(0.0,50.0,0.0),glam::vec3(0.0,0.0,0.0),glam::vec3(0.0,-100.0,0.0)),
time: 0,
tick: 0,
strafe_tick_num: 100,//100t
@ -594,7 +574,7 @@ impl strafe_client::framework::Example for GraphicsData {
walkspeed: 18.0,
contacts: std::collections::HashSet::new(),
models: Vec::new(),
walk: strafe_client::body::WalkState::new(),
walk: body::WalkState::new(),
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
};
@ -619,26 +599,6 @@ impl strafe_client::framework::Example for GraphicsData {
wgpu::TextureFormat::Bgra8UnormSrgb
};
let size = wgpu::Extent3d {
width: IMAGE_SIZE,
height: IMAGE_SIZE,
depth_or_array_layers: 6,
};
let layer_size = wgpu::Extent3d {
depth_or_array_layers: 1,
..size
};
let max_mips = layer_size.max_mips(wgpu::TextureDimension::D2);
log::debug!(
"Copying {:?} skybox images of size {}, {}, 6 with {} mips to gpu",
skybox_format,
IMAGE_SIZE,
IMAGE_SIZE,
max_mips,
);
let bytes = match skybox_format {
wgpu::TextureFormat::Astc {
block: AstcBlock::B4x4,
@ -652,6 +612,26 @@ impl strafe_client::framework::Example for GraphicsData {
let skybox_image = ddsfile::Dds::read(&mut std::io::Cursor::new(bytes)).unwrap();
let size = wgpu::Extent3d {
width: skybox_image.get_width(),
height: skybox_image.get_height(),
depth_or_array_layers: 6,
};
let layer_size = wgpu::Extent3d {
depth_or_array_layers: 1,
..size
};
let max_mips = layer_size.max_mips(wgpu::TextureDimension::D2);
log::debug!(
"Copying {:?} skybox images of size {}, {}, 6 with {} mips to gpu",
skybox_format,
size.width,
size.height,
max_mips,
);
let skybox_texture = device.create_texture_with_data(
queue,
&wgpu::TextureDescriptor {
@ -933,7 +913,7 @@ impl strafe_client::framework::Example for GraphicsData {
view: &wgpu::TextureView,
device: &wgpu::Device,
queue: &wgpu::Queue,
_spawner: &strafe_client::framework::Spawner,
_spawner: &framework::Spawner,
) {
let camera_mat=glam::Mat3::from_rotation_y(self.camera.yaw);
let control_dir=camera_mat*get_control_dir(self.camera.controls&(CONTROL_MOVELEFT|CONTROL_MOVERIGHT|CONTROL_MOVEFORWARD|CONTROL_MOVEBACK)).normalize_or_zero();
@ -946,16 +926,16 @@ impl strafe_client::framework::Example for GraphicsData {
let walk_target_velocity=self.physics.walkspeed*control_dir;
//autohop (already pressing spacebar; the signal to begin trying to jump is different)
if self.physics.grounded&&walk_target_velocity!=self.physics.walk.target_velocity {
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{
time,
instruction:strafe_client::body::PhysicsInstruction::SetWalkTargetVelocity(walk_target_velocity)
instruction:body::PhysicsInstruction::SetWalkTargetVelocity(walk_target_velocity)
});
}
if control_dir!=self.physics.temp_control_dir {
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{
time,
instruction:strafe_client::body::PhysicsInstruction::SetControlDir(control_dir)
instruction:body::PhysicsInstruction::SetControlDir(control_dir)
});
}
@ -963,9 +943,9 @@ impl strafe_client::framework::Example for GraphicsData {
//autohop (already pressing spacebar; the signal to begin trying to jump is different)
if self.physics.grounded&&self.physics.jump_trying {
//scroll will be implemented with InputInstruction::Jump(true) but it blocks setting self.jump_trying=true
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{
time,
instruction:strafe_client::body::PhysicsInstruction::Jump
instruction:body::PhysicsInstruction::Jump
});
}
@ -1049,7 +1029,7 @@ impl strafe_client::framework::Example for GraphicsData {
}
fn main() {
strafe_client::framework::run::<GraphicsData>(
framework::run::<GraphicsData>(
format!("Strafe Client v{}",
env!("CARGO_PKG_VERSION")
).as_str()

25
src/model.rs Normal file

@ -0,0 +1,25 @@
use bytemuck::{Pod, Zeroable};
#[derive(Clone, Copy, Pod, Zeroable)]
#[repr(C)]
pub struct Vertex {
pub pos: [f32; 3],
pub texture: [f32; 2],
pub normal: [f32; 3],
pub color: [f32; 4],
}
pub struct ModelInstance {
pub transform: glam::Mat4,
pub color: glam::Vec4,
}
pub struct ModelData {
pub instances: Vec<ModelInstance>,
pub vertices: Vec<Vertex>,
pub entities: Vec<Vec<u16>>,
}
impl ModelData {
pub const COLOR_FLOATS_WHITE: [f32;4] = [1.0,1.0,1.0,1.0];
pub const COLOR_VEC4_WHITE: glam::Vec4 = glam::vec4(1.0,1.0,1.0,1.0);
}

@ -1,4 +1,5 @@
//find roots of polynomials
#[inline]
pub fn zeroes2(a0:f32,a1:f32,a2:f32) -> Vec<f32>{
if a2==0f32{
return zeroes1(a0, a1);