add initial components and utility functions for simulation and builder modules

This commit is contained in:
2025-03-25 14:00:03 +05:30
parent 61b3c4ee2c
commit 2303682a15
164 changed files with 13967 additions and 52 deletions

View File

@@ -1,45 +0,0 @@
const DB_NAME = 'GLTFStorage';
const STORE_NAME = 'models';
const DB_VERSION = 1;
export function initializeDB(): Promise<IDBDatabase> {
return new Promise((resolve, reject) => {
const request = indexedDB.open(DB_NAME, DB_VERSION);
request.onupgradeneeded = () => {
const db = request.result;
if (!db.objectStoreNames.contains(STORE_NAME)) {
db.createObjectStore(STORE_NAME);
}
};
request.onsuccess = () => resolve(request.result);
request.onerror = () => reject(request.error);
});
}
export async function storeGLTF(key: string, file: Blob): Promise<void> {
const db = await initializeDB();
return new Promise((resolve, reject) => {
const transaction = db.transaction(STORE_NAME, 'readwrite');
const store = transaction.objectStore(STORE_NAME);
const request = store.put(file, key);
request.onsuccess = () => resolve();
request.onerror = () => reject(request.error);
});
}
export async function retrieveGLTF(key: string): Promise<Blob | undefined> {
const db = await initializeDB();
return new Promise((resolve, reject) => {
const transaction = db.transaction(STORE_NAME, 'readonly');
const store = transaction.objectStore(STORE_NAME);
const request = store.get(key);
request.onsuccess = () => resolve(request.result as Blob | undefined);
request.onerror = () => reject(request.error);
});
}