fix editor map reliability

This commit is contained in:
Tom Boullay
2026-04-28 11:06:09 +02:00
parent b5f2b7c990
commit ddde5e33f3
7 changed files with 146 additions and 56 deletions
+12 -21
View File
@@ -22,28 +22,19 @@ async function createSceneData(mapNodes: MapNode[]): Promise<SceneData> {
async function loadMapModelUrls(
mapNodes: MapNode[],
): Promise<Map<string, string>> {
const models = new Map<string, string>();
const uniqueModelNames = [...new Set(mapNodes.map((node) => node.name))];
const modelEntries = await Promise.all(
uniqueModelNames.map(async (modelName) => {
const modelUrl = `/models/${modelName}/${MODEL_FILE_NAME}`;
for (const modelName of uniqueModelNames) {
const modelUrl = `/models/${modelName}/${MODEL_FILE_NAME}`;
const modelResponse = await fetch(modelUrl);
if (!modelResponse.ok) continue;
const text = await modelResponse.text();
if (isGltfContent(text)) {
models.set(modelName, modelUrl);
}
}
return models;
}
function isGltfContent(text: string): boolean {
return (
text.includes('"glTF"') ||
text.includes('"scene"') ||
text.includes('"nodes"')
try {
const response = await fetch(modelUrl, { method: "HEAD" });
return response.ok ? ([modelName, modelUrl] as const) : null;
} catch {
return null;
}
}),
);
return new Map(modelEntries.filter((entry) => entry !== null));
}