Add initial iter_meshes()
This commit is contained in:
parent
c6a3ee6b19
commit
776af2acb0
|
@ -80,4 +80,13 @@ impl MeshGroup {
|
|||
|
||||
Ok((handle, copies))
|
||||
}
|
||||
|
||||
/// Gets a [MeshHandle's][MeshHandle] [MeshAlloc].
|
||||
pub fn get_alloc(&self, handle: &MeshHandle) -> Option<&MeshAlloc> {
|
||||
if handle.group != self.id {
|
||||
None
|
||||
} else {
|
||||
self.meshes.get(handle.sub)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,4 +142,37 @@ impl MeshPool {
|
|||
self.staging.queue_copies(copies);
|
||||
Ok(handle)
|
||||
}
|
||||
|
||||
pub fn iter_meshes<T: HasMeshHandle>(
|
||||
&self,
|
||||
meshes: impl IntoIterator<Item = T>,
|
||||
) -> Vec<(&MeshGroup, Vec<(&MeshAlloc, T)>)> {
|
||||
let group_num = self.groups.len();
|
||||
let mut by_group = Vec::with_capacity(group_num);
|
||||
for index in 0..group_num {
|
||||
let group = self.groups.get(index);
|
||||
let meshes = Vec::new();
|
||||
by_group.push((group, meshes));
|
||||
}
|
||||
|
||||
for mesh in meshes {
|
||||
let handle = mesh.get_mesh_handle();
|
||||
let (group, meshes) = match by_group.get_mut(handle.group) {
|
||||
Some((Some(group), meshes)) => (group, meshes),
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
let alloc = match group.get_alloc(handle) {
|
||||
Some(alloc) => alloc,
|
||||
None => continue, // TODO err out on invalid handle?
|
||||
};
|
||||
|
||||
meshes.push((alloc, mesh));
|
||||
}
|
||||
|
||||
by_group
|
||||
.into_iter()
|
||||
.filter_map(|(group, meshes)| group.map(|group| (group, meshes)))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue