archetype_asset
Fast, modular asset system with spatial preloading for Rust game engines.
Features
- ๐ฎ GPU Abstraction - Generic over GPU backends (Vulkan, Mock for testing)
- โก Async Runtime Abstraction - Works with Tokio, async-std, or custom runtimes
- ๐ฆ Smart Caching - LRU cache with memory management and metrics
- ๐บ๏ธ Spatial Preloading - Unique! Position-based asset prediction
- ๐ LOD System - Level-of-detail mesh simplification
- ๐ฌ GLTF/GLB Loading - Full PBR material and scene hierarchy support
Quick Start
use ;
use load_glb_file;
// Create GPU and cache
let gpu = new;
let cache = new; // 100MB cache
// Load a GLB model directly
let model = load_glb_file?;
println!;
// Or use the cache for automatic caching (recommended)
let cached_model = cache.get_or_load_model?;
Feature Flags
| Feature | Description | Default |
|---|---|---|
gpu-mock |
Mock GPU for testing | โ |
gpu-vulkan |
Vulkan GPU backend | โ |
runtime-mock |
Mock async runtime | โ |
runtime-tokio |
Tokio async runtime | โ |
lod |
LOD mesh simplification | โ |
spatial-preload |
Spatial preloading | โ |
metrics |
Performance metrics | โ |
Enable Vulkan + Tokio
[]
= { = "0.1.2", = ["gpu-vulkan", "runtime-tokio"] }
API Overview
GPU Abstraction
use ;
// Any GPU backend implements GpuDevice
let gpu = new;
let buffer = gpu.allocate_buffer?;
gpu.upload_buffer_data?;
Async Runtime Abstraction
use ;
let spawner = blocking;
spawner.spawn;
Asset Cache
use ;
let cache = new;
// Load with caching (returns Arc<LoadedModel>)
let model = cache.get_or_load_model?;
// Check memory usage
println!;
// Performance metrics
let hit_rate = cache.metrics.cache_hit_rate;
Model Loading
use ;
// Load from bytes
let loader = new;
let model = loader.load_glb?;
// Access mesh data
for mesh in &model.meshes
Spatial Preloading (Unique!)
use ;
use Vec3;
// Predict assets based on player position
let predictor = new; // 100 unit radius
let needed_assets = predictor.predict_assets;
LOD System
use ;
// Generate 4 LOD levels
let simplifier = new;
let lod_levels = generate_lod_levels;
let thresholds = default_thresholds;
let lod_model = new;
// Select LOD based on screen size
let mesh_to_render = lod_model.get_lod;
Texture Loading
use TextureLoader;
// Synchronous loading
let loader = new;
let texture = loader.load_file_sync?;
println!;
Performance
Benchmarks on typical hardware:
| Operation | Time |
|---|---|
| Cache hit check | 5.4 ns |
| Cache memory check | 0.5 ns |
| Cache creation | 291 ns |
| Mesh data allocation | 138 ns |
| Memory pool creation | 1.5 ยตs |
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Author
Saptak Santra