From 93764ff2cb2ab3228be5efcc9615641d7086ca3c Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 13 May 2026 03:37:42 +0200 Subject: [PATCH] auto-git: [add] src/spline-corridor/bundled-spline-corridor-model-loader.ts --- .../bundled-spline-corridor-model-loader.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/spline-corridor/bundled-spline-corridor-model-loader.ts diff --git a/src/spline-corridor/bundled-spline-corridor-model-loader.ts b/src/spline-corridor/bundled-spline-corridor-model-loader.ts new file mode 100644 index 00000000..e790246a --- /dev/null +++ b/src/spline-corridor/bundled-spline-corridor-model-loader.ts @@ -0,0 +1,35 @@ +import { Group } from "three"; + +import { createConfiguredGltfLoader } from "../assets/gltf-model-import"; + +const bundledSplineCorridorTemplatePromises = new Map>(); + +function getErrorDetail(error: unknown): string { + return error instanceof Error && error.message.trim().length > 0 + ? error.message.trim() + : "Unknown error."; +} + +export function loadBundledSplineCorridorModelTemplate( + bundledPath: string +): Promise { + const cachedTemplatePromise = + bundledSplineCorridorTemplatePromises.get(bundledPath); + + if (cachedTemplatePromise !== undefined) { + return cachedTemplatePromise; + } + + const templatePromise = createConfiguredGltfLoader() + .loadAsync(bundledPath) + .then((gltf) => gltf.scene) + .catch((error: unknown) => { + bundledSplineCorridorTemplatePromises.delete(bundledPath); + throw new Error( + `Bundled spline corridor model failed to load from ${bundledPath}: ${getErrorDetail(error)}` + ); + }); + + bundledSplineCorridorTemplatePromises.set(bundledPath, templatePromise); + return templatePromise; +}