entity_id trash

This commit is contained in:
Quaternions 2023-09-01 18:21:57 -07:00
parent b68dfa791d
commit d2fdb5d94b
2 changed files with 7 additions and 3 deletions

View File

@ -9,6 +9,7 @@ const IMAGE_SIZE: u32 = 128;
struct Vertex { struct Vertex {
pos: [f32; 3], pos: [f32; 3],
normal: [f32; 3], normal: [f32; 3],
entity_id: u32,
} }
struct Entity { struct Entity {
@ -162,6 +163,7 @@ fn add_obj(device:&wgpu::Device,entities:& mut Vec<Entity>,source:&[u8]){
for object in data.objects { for object in data.objects {
for group in object.groups { for group in object.groups {
vertices.clear(); vertices.clear();
let entity_id = entities.len() as u32;
for poly in group.polys { for poly in group.polys {
for end_index in 2..poly.0.len() { for end_index in 2..poly.0.len() {
for &index in &[0, end_index - 1, end_index] { for &index in &[0, end_index - 1, end_index] {
@ -170,6 +172,7 @@ fn add_obj(device:&wgpu::Device,entities:& mut Vec<Entity>,source:&[u8]){
vertices.push(Vertex { vertices.push(Vertex {
pos: data.position[position_id], pos: data.position[position_id],
normal: data.normal[normal_id.unwrap()], normal: data.normal[normal_id.unwrap()],
entity_id,
}) })
} }
} }
@ -328,7 +331,7 @@ impl strafe_client::framework::Example for Skybox {
buffers: &[wgpu::VertexBufferLayout { buffers: &[wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress, array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex, step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3], attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3, 2 => Uint32],
}], }],
}, },
fragment: Some(wgpu::FragmentState { fragment: Some(wgpu::FragmentState {

View File

@ -80,10 +80,11 @@ var<uniform> r_EntityTransforms: array<EntityTransform, 7>;
fn vs_entity( fn vs_entity(
@location(0) pos: vec3<f32>, @location(0) pos: vec3<f32>,
@location(1) normal: vec3<f32>, @location(1) normal: vec3<f32>,
@location(2) entity_id: u32,
) -> EntityOutput { ) -> EntityOutput {
var position: vec3<f32> = pos;//r_EntityTransforms[instance_index].matrix3 * pos+r_EntityTransforms[instance_index].translation; var position: vec3<f32> = r_EntityTransforms[entity_id].matrix3 * pos+r_EntityTransforms[entity_id].translation;
var result: EntityOutput; var result: EntityOutput;
result.normal = normal;//r_EntityTransforms[instance_index].matrix3 * normal; result.normal = r_EntityTransforms[entity_id].matrix3 * normal;
result.view = position - r_data.cam_pos.xyz; result.view = position - r_data.cam_pos.xyz;
result.position = r_data.proj * r_data.view * vec4<f32>(position, 1.0); result.position = r_data.proj * r_data.view * vec4<f32>(position, 1.0);
return result; return result;