This commit is contained in:
1 parent
f29712d158
commit
3e053a81ab
123 files changed
+31930
-1404
No files matched your search
@@ -8,6 +8,7 @@ use egui_phosphor_icons::icons;
|
||||
|
||||
use super::sources::gltf::gltf_base_color_texture_path;
|
||||
use super::studio::{model_file_exists, ThumbnailStudio};
|
||||
use super::ThumbnailJobSource;
|
||||
use crate::assets::{
|
||||
asset_cache_key, asset_server_path, EditorAsset, EditorAssetKind, EditorAssets,
|
||||
};
|
||||
@@ -114,6 +115,97 @@ impl AssetThumbnailCache {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request_mesh_subasset(
|
||||
&mut self,
|
||||
key: String,
|
||||
model_path: String,
|
||||
mesh_label: String,
|
||||
material_label: Option<String>,
|
||||
studio: &mut ThumbnailStudio,
|
||||
) {
|
||||
if matches!(
|
||||
self.state(&key),
|
||||
Some(ThumbnailState::Ready | ThumbnailState::Pending)
|
||||
) || self.failed.contains_key(&key)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if !model_file_exists(&model_path) {
|
||||
self.mark_studio_failed(&key, "file not found", false);
|
||||
return;
|
||||
}
|
||||
if studio.enqueue_source(
|
||||
key.clone(),
|
||||
ThumbnailJobSource::MeshSubAsset {
|
||||
model_path,
|
||||
mesh_label,
|
||||
material_label,
|
||||
},
|
||||
) {
|
||||
self.studio_pending.insert(key);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request_source_material(
|
||||
&mut self,
|
||||
key: String,
|
||||
model_path: String,
|
||||
material_label: String,
|
||||
studio: &mut ThumbnailStudio,
|
||||
) {
|
||||
if matches!(
|
||||
self.state(&key),
|
||||
Some(ThumbnailState::Ready | ThumbnailState::Pending)
|
||||
) || self.failed.contains_key(&key)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if !model_file_exists(&model_path) {
|
||||
self.mark_studio_failed(&key, "file not found", false);
|
||||
return;
|
||||
}
|
||||
if studio.enqueue_source(
|
||||
key.clone(),
|
||||
ThumbnailJobSource::SourceMaterial {
|
||||
model_path,
|
||||
material_label,
|
||||
},
|
||||
) {
|
||||
self.studio_pending.insert(key);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn request_material_asset(
|
||||
&mut self,
|
||||
key: String,
|
||||
path: String,
|
||||
studio: &mut ThumbnailStudio,
|
||||
) {
|
||||
if matches!(
|
||||
self.state(&key),
|
||||
Some(ThumbnailState::Ready | ThumbnailState::Pending)
|
||||
) || self.failed.contains_key(&key)
|
||||
{
|
||||
return;
|
||||
}
|
||||
let material = match shared::MaterialAsset::load_from_path(&path) {
|
||||
Ok(asset) => asset,
|
||||
Err(error) => {
|
||||
self.mark_studio_failed(&key, &error, true);
|
||||
return;
|
||||
}
|
||||
};
|
||||
if studio.enqueue_source(
|
||||
key.clone(),
|
||||
ThumbnailJobSource::MaterialAsset {
|
||||
label: material.label.clone(),
|
||||
material: material.material,
|
||||
},
|
||||
) {
|
||||
self.studio_pending.insert(key);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn complete_studio_thumbnail(
|
||||
&mut self,
|
||||
key: &str,
|
||||
@@ -297,6 +389,18 @@ pub struct ThumbnailCacheSnapshot {
|
||||
}
|
||||
|
||||
impl ThumbnailCacheSnapshot {
|
||||
pub fn texture_for_key(&self, key: &str) -> Option<egui::TextureId> {
|
||||
self.texture_ids.get(key).copied()
|
||||
}
|
||||
|
||||
pub fn is_pending_key(&self, key: &str) -> bool {
|
||||
self.pending_keys.iter().any(|pending| pending == key)
|
||||
}
|
||||
|
||||
pub fn is_failed_key(&self, key: &str) -> bool {
|
||||
self.failed_keys.iter().any(|failed| failed == key)
|
||||
}
|
||||
|
||||
pub fn texture_for(&self, asset: &EditorAsset) -> Option<egui::TextureId> {
|
||||
self.texture_ids.get(&asset_cache_key(asset)).copied()
|
||||
}
|
||||
@@ -331,7 +435,7 @@ pub fn prefetch_folder_thumbnails(world: &mut World, folder: &str) {
|
||||
.filter(|asset| {
|
||||
matches!(
|
||||
asset.kind,
|
||||
EditorAssetKind::Texture | EditorAssetKind::Model
|
||||
EditorAssetKind::Texture | EditorAssetKind::Model | EditorAssetKind::Material
|
||||
)
|
||||
})
|
||||
.filter_map(|asset| {
|
||||
@@ -352,6 +456,9 @@ pub fn prefetch_folder_thumbnails(world: &mut World, folder: &str) {
|
||||
EditorAssetKind::Model => {
|
||||
cache.request_model(key, path, &asset_server, &mut studio)
|
||||
}
|
||||
EditorAssetKind::Material => {
|
||||
cache.request_material_asset(key, path, &mut studio)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user