From e190636544f6ee814542591e83dd81a0b0d21f2e Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Wed, 17 Dec 2025 18:00:11 +0100 Subject: [PATCH] feat(assets): load 3d models as well --- app/components/LoadingScreen.vue | 7 ++ app/components/NDS.vue | 66 +++++++---------- app/composables/useAssets.ts.in | 32 +++++++++ app/pages/index.vue | 5 +- app/pages/test.vue | 8 --- .../{image-assets.ts => asset-generator.ts} | 71 ++++++++++++------- nuxt.config.ts | 2 +- 7 files changed, 113 insertions(+), 78 deletions(-) create mode 100644 app/components/LoadingScreen.vue delete mode 100644 app/pages/test.vue rename modules/{image-assets.ts => asset-generator.ts} (55%) diff --git a/app/components/LoadingScreen.vue b/app/components/LoadingScreen.vue new file mode 100644 index 0000000..29f719b --- /dev/null +++ b/app/components/LoadingScreen.vue @@ -0,0 +1,7 @@ + + + diff --git a/app/components/NDS.vue b/app/components/NDS.vue index 690a56b..6dc6165 100644 --- a/app/components/NDS.vue +++ b/app/components/NDS.vue @@ -1,5 +1,4 @@ diff --git a/app/composables/useAssets.ts.in b/app/composables/useAssets.ts.in index 15c3ec6..d52cc7a 100644 --- a/app/composables/useAssets.ts.in +++ b/app/composables/useAssets.ts.in @@ -1,4 +1,8 @@ +import * as THREE from "three"; +import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js"; + const imageCache = new Map(); +const modelCache = new Map(); const loaded = ref(0); const total = ref({{TOTAL}}); @@ -22,6 +26,34 @@ const createImage = (path: string) => { return img; }; +const createModel = (path: string) => { + const cached = modelCache.get(path); + if (cached) { + return cached; + } + + const model = new THREE.Group(); + modelCache.set(path, model); + + new GLTFLoader().load( + path, + (gltf) => { + for (const child of [...gltf.scene.children]) { + model.add(child); + } + + loaded.value += 1; + }, + undefined, + (error) => { + console.error(`Error loading model ${path}:`, error); + loaded.value += 1; + } + ); + + return model; +}; + const assets = {{ASSETS}}; export const useAssets = () => { diff --git a/app/pages/index.vue b/app/pages/index.vue index ffc3f7a..4e3a2fe 100644 --- a/app/pages/index.vue +++ b/app/pages/index.vue @@ -3,6 +3,8 @@ import type { Screen as NDSScreen } from "#components"; type ScreenInstance = InstanceType; +const { isReady } = useAssets(); + const route = useRoute(); const screen = computed(() => route.query.screen as string | undefined); @@ -14,7 +16,8 @@ const bottomScreenCanvas = computed(() => bottomScreen.value?.canvas ?? null);