From 2cdeb92e9c0d9d6b2854d3a5d78223c2dfc4d9c1 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sat, 8 Nov 2025 22:45:19 -0500 Subject: [PATCH] feat: add embedded GLTF primitives for basic shapes with caching support --- bridge/src/primitives.rs | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 bridge/src/primitives.rs diff --git a/bridge/src/primitives.rs b/bridge/src/primitives.rs new file mode 100644 index 0000000..df016d6 --- /dev/null +++ b/bridge/src/primitives.rs @@ -0,0 +1,41 @@ +use std::path::PathBuf; +use std::fs; + +// Embedded GLTF primitives for basic shapes +pub mod embedded_models { + use super::*; + use std::sync::OnceLock; + + static CACHE_DIR: OnceLock = OnceLock::new(); + + pub fn get_cache_dir() -> &'static PathBuf { + CACHE_DIR.get_or_init(|| { + let dir = dirs::cache_dir() + .unwrap_or_else(|| PathBuf::from("/tmp")) + .join("starworld/primitives"); + let _ = std::fs::create_dir_all(&dir); + dir + }) + } + + pub fn get_cube_model() -> PathBuf { + let path = get_cache_dir().join("cube.glb"); + if !path.exists() { + std::fs::write(&path, CUBE_GLB).expect("Failed to write cube.glb"); + } + path + } + + pub fn get_sphere_model() -> PathBuf { + let path = get_cache_dir().join("sphere.glb"); + if !path.exists() { + std::fs::write(&path, SPHERE_GLB).expect("Failed to write sphere.glb"); + } + path + } + + // Minimal cube GLB (binary GLTF) - this is a placeholder + // TODO: Generate proper GLB data or bundle actual primitive files + const CUBE_GLB: &[u8] = b""; // Will be filled with actual data + const SPHERE_GLB: &[u8] = b""; // Will be filled with actual data +}