|
|
@ -1,8 +1,11 @@
|
|
|
|
use std::rc::Rc;
|
|
|
|
use std::rc::Rc;
|
|
|
|
|
|
|
|
|
|
|
|
use bytemuck::__core::mem;
|
|
|
|
use bytemuck::__core::mem;
|
|
|
|
|
|
|
|
use bytemuck::__core::num::NonZeroU32;
|
|
|
|
|
|
|
|
use cgmath::{Decomposed, Deg, InnerSpace, Quaternion, Rotation3, SquareMatrix};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::light::Light;
|
|
|
|
use crate::light::Light;
|
|
|
|
use crate::render::EntityUniforms;
|
|
|
|
use crate::render::EntityUniforms;
|
|
|
|
use bytemuck::__core::num::NonZeroU32;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
@ -17,10 +20,12 @@ struct Entity {
|
|
|
|
mx_world: cgmath::Matrix4<f32>,
|
|
|
|
mx_world: cgmath::Matrix4<f32>,
|
|
|
|
rotation_speed: f32,
|
|
|
|
rotation_speed: f32,
|
|
|
|
color: wgpu::Color,
|
|
|
|
color: wgpu::Color,
|
|
|
|
vertex_buf: Rc<wgpu::Buffer>, // Could probably tie this along with index & count to some resource handle in the renderer
|
|
|
|
vertex_buf: Rc<wgpu::Buffer>,
|
|
|
|
|
|
|
|
// Could probably tie this along with index & count to some resource handle in the renderer
|
|
|
|
index_buf: Rc<wgpu::Buffer>,
|
|
|
|
index_buf: Rc<wgpu::Buffer>,
|
|
|
|
index_count: usize,
|
|
|
|
index_count: usize,
|
|
|
|
bind_group: wgpu::BindGroup, // This is a little weird to have in the entity isn't it?
|
|
|
|
bind_group: wgpu::BindGroup,
|
|
|
|
|
|
|
|
// This is a little weird to have in the entity isn't it?
|
|
|
|
uniform_buf: wgpu::Buffer,
|
|
|
|
uniform_buf: wgpu::Buffer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -81,29 +86,26 @@ impl Runtime {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut entities = vec![{
|
|
|
|
let mut entities = Vec::default();
|
|
|
|
use cgmath::SquareMatrix;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
|
|
entities.push(Entity {
|
|
|
|
|
|
|
|
mx_world: cgmath::Matrix4::identity(),
|
|
|
|
|
|
|
|
rotation_speed: 0.0,
|
|
|
|
|
|
|
|
color: wgpu::Color::WHITE,
|
|
|
|
|
|
|
|
vertex_buf: Rc::new(plane_vertex_buf),
|
|
|
|
|
|
|
|
index_buf: Rc::new(plane_index_buf),
|
|
|
|
|
|
|
|
index_count: plane_index_data.len(),
|
|
|
|
|
|
|
|
bind_group: device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
|
|
layout: &local_bind_group_layout,
|
|
|
|
layout: &local_bind_group_layout,
|
|
|
|
entries: &[wgpu::BindGroupEntry {
|
|
|
|
entries: &[wgpu::BindGroupEntry {
|
|
|
|
binding: 0,
|
|
|
|
binding: 0,
|
|
|
|
resource: wgpu::BindingResource::Buffer(plane_uniform_buf.slice(..)),
|
|
|
|
resource: wgpu::BindingResource::Buffer(plane_uniform_buf.slice(..)),
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
label: None,
|
|
|
|
label: None,
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
|
|
|
uniform_buf: plane_uniform_buf,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Entity {
|
|
|
|
|
|
|
|
mx_world: cgmath::Matrix4::identity(),
|
|
|
|
|
|
|
|
rotation_speed: 0.0,
|
|
|
|
|
|
|
|
color: wgpu::Color::WHITE,
|
|
|
|
|
|
|
|
vertex_buf: Rc::new(plane_vertex_buf),
|
|
|
|
|
|
|
|
index_buf: Rc::new(plane_index_buf),
|
|
|
|
|
|
|
|
index_count: plane_index_data.len(),
|
|
|
|
|
|
|
|
bind_group,
|
|
|
|
|
|
|
|
uniform_buf: plane_uniform_buf,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct CubeDesc {
|
|
|
|
struct CubeDesc {
|
|
|
|
offset: cgmath::Vector3<f32>,
|
|
|
|
offset: cgmath::Vector3<f32>,
|
|
|
@ -123,8 +125,6 @@ impl Runtime {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for cube in &cube_descs {
|
|
|
|
for cube in &cube_descs {
|
|
|
|
use cgmath::{Decomposed, Deg, InnerSpace, Quaternion, Rotation3};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let transform = Decomposed {
|
|
|
|
let transform = Decomposed {
|
|
|
|
disp: cube.offset.clone(),
|
|
|
|
disp: cube.offset.clone(),
|
|
|
|
rot: Quaternion::from_axis_angle(cube.offset.normalize(), Deg(cube.angle)),
|
|
|
|
rot: Quaternion::from_axis_angle(cube.offset.normalize(), Deg(cube.angle)),
|
|
|
@ -155,9 +155,9 @@ impl Runtime {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create other resources
|
|
|
|
// Create other resources
|
|
|
|
|
|
|
|
|
|
|
|
// This is just metadata we hold for the lights. We can hold onto this
|
|
|
|
// This is just metadata we hold for the lights. We can hold onto this
|
|
|
|
let lights = vec![
|
|
|
|
let lights = vec![
|
|
|
|
Light {
|
|
|
|
Light {
|
|
|
|
pos: cgmath::Point3::new(7.0, -5.0, 10.0),
|
|
|
|
pos: cgmath::Point3::new(7.0, -5.0, 10.0),
|
|
|
|