wip: begin refactor of model loading system
This commit is contained in:
1 parent
a315cbc543
commit
406b0f9174
17 files changed
+248
-307
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use crate::assets::loaders::material::mat_loader::MaterialInfo;
|
||||
use crate::assets::loaders::mat_loader::MaterialLoadInfo;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct MaterialRegistry {
|
||||
@@ -36,11 +36,11 @@ pub struct Material {
|
||||
pub base_color_texture: Option<String>,
|
||||
}
|
||||
|
||||
impl From<MaterialInfo> for Material {
|
||||
impl From<MaterialLoadInfo> for Material {
|
||||
/// Converts loader output into a storable `Material`. `MaterialInfo::roughness_map` has no
|
||||
/// equivalent here yet - glTF packs it with the metallic map, and there's no texture loading
|
||||
/// in place to make use of either.
|
||||
fn from(info: MaterialInfo) -> Self {
|
||||
fn from(info: MaterialLoadInfo) -> Self {
|
||||
Self {
|
||||
base_color: info.uniforms.base_color,
|
||||
metallic: info.uniforms.metalness_factor,
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
use crate::assets::loaders::mesh_loader::MeshInfo;
|
||||
use crate::assets::loaders::mesh_loader::MeshLoadInfo;
|
||||
use crate::gpu::vertex3::Vertex3;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -84,7 +84,7 @@ impl MeshRegistry {
|
||||
/// material has actually been registered under that id yet.
|
||||
fn append_mesh(
|
||||
mesh_id: &str,
|
||||
info: MeshInfo,
|
||||
info: MeshLoadInfo,
|
||||
verts: &mut Vec<Vertex3>,
|
||||
indices: &mut Vec<u32>,
|
||||
) -> MeshHandle {
|
||||
@@ -136,7 +136,7 @@ impl MeshRegistry {
|
||||
/// This is far less efficient than batching a whole scene through [`Self::load_scene`], since
|
||||
/// every call reallocates and re-uploads the full vertex/index buffers - fine for loading a
|
||||
/// handful of models up front, not for anything performance-sensitive.
|
||||
pub fn register_mesh(&mut self, mesh_id: String, info: MeshInfo) {
|
||||
pub fn register_mesh(&mut self, mesh_id: String, info: MeshLoadInfo) {
|
||||
let handle = Self::append_mesh(
|
||||
&mesh_id,
|
||||
info,
|
||||
|
||||
@@ -4,3 +4,4 @@ pub mod material;
|
||||
pub mod mesh;
|
||||
pub mod render_batch;
|
||||
pub mod scene;
|
||||
pub mod texture;
|
||||
@@ -0,0 +1,33 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use vulkano::image::view::ImageView;
|
||||
use vulkano::image::sampler::Sampler;
|
||||
|
||||
/// A texture handle that contains the texture's [`ImageView`] and [`Sampler`].
|
||||
pub struct TextureHandle {
|
||||
/// The texture's [`ImageView`].
|
||||
pub image_view: Arc<ImageView>,
|
||||
/// The [`Sampler`] associated with the image. This may be a shared sampler,
|
||||
/// as they do not contain image-specific information.
|
||||
pub sampler: Arc<Sampler>
|
||||
}
|
||||
|
||||
pub struct TextureRegistry {
|
||||
textures: HashMap<String, TextureHandle>,
|
||||
}
|
||||
|
||||
impl TextureRegistry {
|
||||
pub fn new() -> Self {
|
||||
TextureRegistry {
|
||||
textures: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register(&mut self, id: String, texture: TextureHandle) {
|
||||
self.textures.insert(id, texture);
|
||||
}
|
||||
|
||||
pub fn get(&self, id: &str) -> Option<&TextureHandle> {
|
||||
self.textures.get(id)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user