🐛 Fix model loading on github pages

This commit is contained in:
Rune Harlyk
2025-10-20 20:17:57 +02:00
parent 72a288145d
commit b14f005b22
2 changed files with 18 additions and 7 deletions
+4 -3
View File
@@ -28,14 +28,15 @@ export const cacheModelFiles = async () => {
const files = uzip.parse(await data.arrayBuffer())
for (const [path, data] of Object.entries(files) as [path: string, data: Uint8Array][]) {
const url = new URL(path, window.location.href)
fileService?.saveFile(url.toString(), data)
const normalizedPath = path.startsWith('/') ? path : '/' + path
const resolvedUrl = resolve(normalizedPath as any)
fileService?.saveFile(resolvedUrl, data)
fileService?.saveFile(normalizedPath, data)
}
}
export const loadModel = async (url: string): Promise<Result<[URDFRobot, string[]], string>> => {
const urdfLoader = new URDFLoader()
urdfLoader.workingPath = resolve('/')
let xml =
url.endsWith('.xacro') ? await loadXacro(url) : await fetch(url).then(res => res.text())