import { useGLTF } from "@react-three/drei"; import { resolveContentUrl } from "../content/contentManager"; import type { AvatarIdentity } from "./CharacterModel"; import { availableAvatarManifestUrls, getAvatarEntry, loadAvatarManifest, } from "./characterManifest"; const requestedModels = new Set(); /** * Starts GLTF parsing before the 3D game scene mounts. Drei shares this cache * with CharacterModel, so matchmaking can present the real WoW rigs on the * first frame instead of briefly showing procedural loading substitutes. */ export async function preloadAvatarModels( identities: readonly (AvatarIdentity | null | undefined)[], ): Promise { if (!availableAvatarManifestUrls().length) return; const manifest = await loadAvatarManifest(); for (const identity of identities) { if (!identity) continue; const entry = getAvatarEntry(manifest, identity.raceId, identity.gender); if (!entry || requestedModels.has(entry.model)) continue; requestedModels.add(entry.model); useGLTF.preload(resolveContentUrl(entry.model)); } }