LOTS of skinned meshes
This commit is contained in:
parent
aaa5ea4be0
commit
1208be73bd
|
@ -341,6 +341,7 @@ pub struct MeshAlloc {
|
||||||
|
|
||||||
/// A handle to an allocated mesh.
|
/// A handle to an allocated mesh.
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct MeshHandle(usize);
|
pub struct MeshHandle(usize);
|
||||||
|
|
||||||
/// A reusable set of [AttrIds][AttrId], for use with querying compatible meshes.
|
/// A reusable set of [AttrIds][AttrId], for use with querying compatible meshes.
|
||||||
|
|
|
@ -66,6 +66,11 @@ struct MeshGroupCommands {
|
||||||
meshes: Vec<MeshCommand>,
|
meshes: Vec<MeshCommand>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct MeshInstance {
|
||||||
|
pub transform: glam::Mat4,
|
||||||
|
pub mesh: MeshHandle,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct FrameData {
|
pub struct FrameData {
|
||||||
skinned_vertices: GpuVec<Vertex>,
|
skinned_vertices: GpuVec<Vertex>,
|
||||||
skinning_uniforms: GpuVec<SkinningUniform>,
|
skinning_uniforms: GpuVec<SkinningUniform>,
|
||||||
|
@ -87,6 +92,7 @@ pub struct MeshPass {
|
||||||
depth_pipeline: wgpu::RenderPipeline,
|
depth_pipeline: wgpu::RenderPipeline,
|
||||||
opaque_pipeline: wgpu::RenderPipeline,
|
opaque_pipeline: wgpu::RenderPipeline,
|
||||||
target_info: ViewportInfo,
|
target_info: ViewportInfo,
|
||||||
|
instances: Vec<MeshInstance>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MeshPass {
|
impl MeshPass {
|
||||||
|
@ -146,6 +152,21 @@ impl MeshPass {
|
||||||
example_mesh.attributes.push(example_indices);
|
example_mesh.attributes.push(example_indices);
|
||||||
let example_mesh = mesh_pool.load(example_mesh).unwrap();
|
let example_mesh = mesh_pool.load(example_mesh).unwrap();
|
||||||
|
|
||||||
|
let mut instances = Vec::new();
|
||||||
|
let r = 10;
|
||||||
|
for x in -r..r {
|
||||||
|
for y in -r..r {
|
||||||
|
for z in -r..r {
|
||||||
|
let translation = glam::Vec3::new(x as f32, y as f32, z as f32);
|
||||||
|
let transform = glam::Mat4::from_translation(translation);
|
||||||
|
instances.push(MeshInstance {
|
||||||
|
transform,
|
||||||
|
mesh: example_mesh.clone(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let render_pipeline_layout =
|
let render_pipeline_layout =
|
||||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||||
label: Some("MeshPass Pipeline Layout"),
|
label: Some("MeshPass Pipeline Layout"),
|
||||||
|
@ -282,6 +303,7 @@ impl MeshPass {
|
||||||
depth_pipeline,
|
depth_pipeline,
|
||||||
opaque_pipeline,
|
opaque_pipeline,
|
||||||
target_info,
|
target_info,
|
||||||
|
instances,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,11 +341,9 @@ impl RenderPass for MeshPass {
|
||||||
data.groups.clear();
|
data.groups.clear();
|
||||||
data.skinning_uniforms.clear();
|
data.skinning_uniforms.clear();
|
||||||
|
|
||||||
let meshes = &[&self.example_mesh, &self.example_mesh];
|
|
||||||
|
|
||||||
let mesh_bindings = self
|
let mesh_bindings = self
|
||||||
.mesh_pool
|
.mesh_pool
|
||||||
.iter_meshes(self.mesh_layout_id, meshes.iter(), |v| v)
|
.iter_meshes(self.mesh_layout_id, self.instances.iter(), |i| &i.mesh)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut skinned_cursor = 0;
|
let mut skinned_cursor = 0;
|
||||||
|
@ -380,7 +400,7 @@ impl RenderPass for MeshPass {
|
||||||
bind_group,
|
bind_group,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (_mesh, infos) in instances {
|
for (mesh, infos) in instances {
|
||||||
let vertices = infos.iter().find(|i| i.0 == self.vertex_attr_id).unwrap().1;
|
let vertices = infos.iter().find(|i| i.0 == self.vertex_attr_id).unwrap().1;
|
||||||
let indices = infos.iter().find(|i| i.0 == self.index_attr_id).unwrap().1;
|
let indices = infos.iter().find(|i| i.0 == self.index_attr_id).unwrap().1;
|
||||||
|
|
||||||
|
@ -394,12 +414,7 @@ impl RenderPass for MeshPass {
|
||||||
});
|
});
|
||||||
|
|
||||||
data.skinning_uniforms.push(SkinningUniform {
|
data.skinning_uniforms.push(SkinningUniform {
|
||||||
transform: [
|
transform: mesh.transform.to_cols_array_2d(),
|
||||||
[1., 0., 0., 0.],
|
|
||||||
[0., 1., 0., 0.],
|
|
||||||
[0., 0., 1., 0.],
|
|
||||||
[0., 0., 0., 1.],
|
|
||||||
],
|
|
||||||
src_offset: vertices.offset as u32,
|
src_offset: vertices.offset as u32,
|
||||||
dst_offset: skinned_cursor as u32,
|
dst_offset: skinned_cursor as u32,
|
||||||
count: vertices.count as u32,
|
count: vertices.count as u32,
|
||||||
|
|
Loading…
Reference in New Issue