Before we can draw the model, we need to be able to draw an individual mesh. Let's create a trait called `DrawModel`, and implement it for `RenderPass`.
```rust
pub trait DrawModel<'a, 'b>
where
'b: 'a,
{
fn draw_mesh(&mut self, mesh: &'b Mesh);
pub trait DrawModel<'a> {
fn draw_mesh(&mut self, mesh: &'a Mesh);
fn draw_mesh_instanced(
&mut self,
mesh: &'b Mesh,
mesh: &'a Mesh,
instances: Range<u32>,
);
}
impl<'a, 'b> DrawModel<'a, 'b> for wgpu::RenderPass<'a>
impl<'a, 'b> DrawModel<'b> for wgpu::RenderPass<'a>
where
'b: 'a,
{
@ -369,7 +366,7 @@ let instances = (0..NUM_INSTANCES_PER_ROW).flat_map(|z| {
@ -464,21 +458,18 @@ With all that in place we should get the following.
Right now we are specifying the mesh and the material directly. This is useful if we want to draw a mesh with a different material. We're also not rendering other parts of the model (if we had some). Let's create a method for `DrawModel` that will draw all the parts of the model with their respective materials.
Now we could manually implement the draw code for the light in `render()`, but to keep with the pattern we developed, let's create a new trait called `DrawLight`.
```rust
pub trait DrawLight<'a, 'b>
where
'b: 'a,
{
pub trait DrawLight<'a> {
fn draw_light_mesh(
&mut self,
mesh: &'b Mesh,
uniforms: &'b wgpu::BindGroup,
light: &'b wgpu::BindGroup,
mesh: &'a Mesh,
uniforms: &'a wgpu::BindGroup,
light: &'a wgpu::BindGroup,
);
fn draw_light_mesh_instanced(
&mut self,
mesh: &'b Mesh,
mesh: &'a Mesh,
instances: Range<u32>,
uniforms: &'b wgpu::BindGroup,
light: &'b wgpu::BindGroup,
) where
'b: 'a;
uniforms: &'a wgpu::BindGroup,
light: &'a wgpu::BindGroup,
);
fn draw_light_model(
&mut self,
model: &'b Model,
uniforms: &'b wgpu::BindGroup,
light: &'b wgpu::BindGroup,
model: &'a Model,
uniforms: &'a wgpu::BindGroup,
light: &'a wgpu::BindGroup,
);
fn draw_light_model_instanced(
&mut self,
model: &'b Model,
model: &'a Model,
instances: Range<u32>,
uniforms: &'b wgpu::BindGroup,
light: &'b wgpu::BindGroup,
uniforms: &'a wgpu::BindGroup,
light: &'a wgpu::BindGroup,
);
}
impl<'a, 'b> DrawLight<'a, 'b> for wgpu::RenderPass<'a>
impl<'a, 'b> DrawLight<'b> for wgpu::RenderPass<'a>