[groq] Preload and cache Three.js assets (#99) #197
25
app.js
25
app.js
@@ -3,6 +3,7 @@ import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|||||||
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
|
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
|
||||||
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
|
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
|
||||||
import { BokehPass } from 'three/addons/postprocessing/BokehPass.js';
|
import { BokehPass } from 'three/addons/postprocessing/BokehPass.js';
|
||||||
|
import { LoadingManager } from 'three';
|
||||||
|
|
||||||
// === COLOR PALETTE ===
|
// === COLOR PALETTE ===
|
||||||
const NEXUS = {
|
const NEXUS = {
|
||||||
@@ -16,6 +17,26 @@ const NEXUS = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// === ASSET LOADER ===
|
||||||
|
const loadedAssets = new Map();
|
||||||
|
|
||||||
|
const loadingManager = new THREE.LoadingManager(() => {
|
||||||
|
document.getElementById('loading-bar').style.width = '100%';
|
||||||
|
document.getElementById('loading').style.display = 'none';
|
||||||
|
animate();
|
||||||
|
});
|
||||||
|
|
||||||
|
loadingManager.onProgress = (url, itemsLoaded, itemsTotal) => {
|
||||||
|
const progress = (itemsLoaded / itemsTotal) * 100;
|
||||||
|
document.getElementById('loading-bar').style.width = `${progress}%`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Simulate loading a texture for demonstration
|
||||||
|
const textureLoader = new THREE.TextureLoader(loadingManager);
|
||||||
|
textureLoader.load('placeholder-texture.jpg', (texture) => {
|
||||||
|
loadedAssets.set('placeholder-texture', texture);
|
||||||
|
});
|
||||||
|
|
||||||
// === SCENE SETUP ===
|
// === SCENE SETUP ===
|
||||||
const scene = new THREE.Scene();
|
const scene = new THREE.Scene();
|
||||||
scene.background = new THREE.Color(NEXUS.colors.bg);
|
scene.background = new THREE.Color(NEXUS.colors.bg);
|
||||||
@@ -327,6 +348,7 @@ const clock = new THREE.Clock();
|
|||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
function animate() {
|
function animate() {
|
||||||
|
// Only start animation after assets are loaded
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
const elapsed = clock.getElapsedTime();
|
const elapsed = clock.getElapsedTime();
|
||||||
|
|
||||||
@@ -591,6 +613,9 @@ async function initCommitBanners() {
|
|||||||
{ hash: 'm0n1o2p', message: 'feat: overview mode bird\'s-eye view' },
|
{ hash: 'm0n1o2p', message: 'feat: overview mode bird\'s-eye view' },
|
||||||
{ hash: 'q3r4s5t', message: 'feat: star field and constellation lines' },
|
{ hash: 'q3r4s5t', message: 'feat: star field and constellation lines' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Load commit banners after assets are ready
|
||||||
|
initCommitBanners();
|
||||||
}
|
}
|
||||||
|
|
||||||
const spreadX = [-7, -3.5, 0, 3.5, 7];
|
const spreadX = [-7, -3.5, 0, 3.5, 7];
|
||||||
|
|||||||
@@ -49,5 +49,8 @@
|
|||||||
<div id="sovereignty-msg">⚡ SOVEREIGNTY ⚡</div>
|
<div id="sovereignty-msg">⚡ SOVEREIGNTY ⚡</div>
|
||||||
|
|
||||||
<script type="module" src="app.js"></script>
|
<script type="module" src="app.js"></script>
|
||||||
|
<div id="loading" style="position: fixed; top: 0; left: 0; right: 0; height: 4px; background: #222; z-index: 1000;">
|
||||||
|
<div id="loading-bar" style="height: 100%; background: var(--color-accent); width: 0;"></div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user