From 309d8281caaedffdcc55d020690467d246577098 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 26 May 2026 21:21:25 +0800 Subject: [PATCH] fix: prefer high quality world splats --- lib/worldlabs/splat-utils.ts | 83 ++++-------------------------------- 1 file changed, 8 insertions(+), 75 deletions(-) diff --git a/lib/worldlabs/splat-utils.ts b/lib/worldlabs/splat-utils.ts index 65fcd5a70..cc1201f09 100644 --- a/lib/worldlabs/splat-utils.ts +++ b/lib/worldlabs/splat-utils.ts @@ -59,74 +59,13 @@ export function pickBestWorldLabsSplatUrl( return pickBestWorldLabsSplatEntry(spzUrls)?.[1] || null; } -// World Labs exports multiple SPZ tiers (for example 100k / 500k / full). -// For embedded previews we bias hard toward the lightweight tier so users see -// the world quickly, then can switch to imagery / mesh for detail if needed. -const INLINE_WORLDLABS_SPLAT_TARGET_SCORE = 100_000; - -function pickClosestResolutionEntry( - entries: Array<[string, string]>, - targetScore: number -) { - if (!entries.length) return null; - - const scoredEntries = entries - .map((entry) => ({ - entry, - score: parseResolutionScore(entry[0]), - })) - .filter( - (item) => - Number.isFinite(item.score) && - item.score > 0 && - item.score !== Number.MAX_SAFE_INTEGER - ); - - if (!scoredEntries.length) { - return entries[0] || null; - } - - return scoredEntries - .slice() - .sort((left, right) => { - const distanceDelta = - Math.abs(left.score - targetScore) - Math.abs(right.score - targetScore); - if (distanceDelta !== 0) return distanceDelta; - return left.score - right.score; - })[0]?.entry || null; -} - -function getResolutionDistance(entry: [string, string], targetScore: number) { - const score = parseResolutionScore(entry[0]); - if ( - !Number.isFinite(score) || - score <= 0 || - score === Number.MAX_SAFE_INTEGER - ) { - return Number.MAX_SAFE_INTEGER; - } - return Math.abs(score - targetScore); -} - function compareInlineSplatEntries( left: [string, string], right: [string, string] ) { - const leftDistance = getResolutionDistance( - left, - INLINE_WORLDLABS_SPLAT_TARGET_SCORE - ); - const rightDistance = getResolutionDistance( - right, - INLINE_WORLDLABS_SPLAT_TARGET_SCORE - ); - if (leftDistance !== rightDistance) return leftDistance - rightDistance; - - const leftScore = parseResolutionScore(left[0]); - const rightScore = parseResolutionScore(right[0]); - if (leftScore !== rightScore) return leftScore - rightScore; - - return left[0].localeCompare(right[0], "en"); + // World Labs exposes multiple SPZ tiers; the canvas should show the highest + // quality available first and keep lower tiers only as load fallbacks. + return compareSplatEntries(left, right); } const KNOWN_ARCHIVED_ASSET_HOSTS = [ @@ -204,17 +143,11 @@ export function pickPreferredInlineWorldLabsSplatEntry( spzUrls?: Record | null ) { const archivedEntries = getArchivedWorldLabsSplatEntries(spzUrls); - if (archivedEntries.length > 0) { - return pickClosestResolutionEntry( - archivedEntries, - INLINE_WORLDLABS_SPLAT_TARGET_SCORE - ); - } - - return pickClosestResolutionEntry( - getSortedWorldLabsSplatEntries(spzUrls), - INLINE_WORLDLABS_SPLAT_TARGET_SCORE - ); + const sourceEntries = + archivedEntries.length > 0 + ? archivedEntries + : getSortedWorldLabsSplatEntries(spzUrls); + return sourceEntries.slice().sort(compareInlineSplatEntries)[0] || null; } export function pickPreferredInlineWorldLabsSplatUrl(