fix: prefer high quality world splats
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-05-26 21:21:25 +08:00
parent 022eee7b95
commit 309d8281ca

View File

@ -59,74 +59,13 @@ export function pickBestWorldLabsSplatUrl(
return pickBestWorldLabsSplatEntry(spzUrls)?.[1] || null; 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( function compareInlineSplatEntries(
left: [string, string], left: [string, string],
right: [string, string] right: [string, string]
) { ) {
const leftDistance = getResolutionDistance( // World Labs exposes multiple SPZ tiers; the canvas should show the highest
left, // quality available first and keep lower tiers only as load fallbacks.
INLINE_WORLDLABS_SPLAT_TARGET_SCORE return compareSplatEntries(left, right);
);
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");
} }
const KNOWN_ARCHIVED_ASSET_HOSTS = [ const KNOWN_ARCHIVED_ASSET_HOSTS = [
@ -204,17 +143,11 @@ export function pickPreferredInlineWorldLabsSplatEntry(
spzUrls?: Record<string, string> | null spzUrls?: Record<string, string> | null
) { ) {
const archivedEntries = getArchivedWorldLabsSplatEntries(spzUrls); const archivedEntries = getArchivedWorldLabsSplatEntries(spzUrls);
if (archivedEntries.length > 0) { const sourceEntries =
return pickClosestResolutionEntry( archivedEntries.length > 0
archivedEntries, ? archivedEntries
INLINE_WORLDLABS_SPLAT_TARGET_SCORE : getSortedWorldLabsSplatEntries(spzUrls);
); return sourceEntries.slice().sort(compareInlineSplatEntries)[0] || null;
}
return pickClosestResolutionEntry(
getSortedWorldLabsSplatEntries(spzUrls),
INLINE_WORLDLABS_SPLAT_TARGET_SCORE
);
} }
export function pickPreferredInlineWorldLabsSplatUrl( export function pickPreferredInlineWorldLabsSplatUrl(