Changes
Co-authored-by: Reifonas <211114984+Reifonas@users.noreply.github.com>
This commit is contained in:
+31
-8
@@ -62,18 +62,41 @@ const Index = () => {
|
|||||||
}
|
}
|
||||||
}, [setModel]);
|
}, [setModel]);
|
||||||
|
|
||||||
const handleLoadDemo = useCallback(async () => {
|
const handleLoadCloud = useCallback(async () => {
|
||||||
setLoadingDemo(true);
|
const url = window.prompt('URL do modelo (GLB · OBJ · STL · IFC):', 'https://');
|
||||||
|
if (!url) return;
|
||||||
|
setLoadingCloud(true);
|
||||||
try {
|
try {
|
||||||
const { blob, fileName, fileSize } = await generateDemoBeamGLB();
|
const fileName = url.split('/').pop()?.split('?')[0] || 'modelo-cloud';
|
||||||
const url = URL.createObjectURL(blob);
|
const ext = getSupportedExtension(fileName);
|
||||||
setModel({ fileName, fileSize, url });
|
if (!ext) {
|
||||||
toast.success('Modelo demo "IPE 200 — 1000mm" carregado!');
|
toast.error('URL deve apontar para .GLB, .OBJ, .STL ou .IFC');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const response = await fetch(url, { mode: 'cors' });
|
||||||
|
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||||
|
const buffer = await response.arrayBuffer();
|
||||||
|
|
||||||
|
let blob: Blob;
|
||||||
|
let outName = fileName;
|
||||||
|
let outSize = buffer.byteLength;
|
||||||
|
if (ext === 'glb') {
|
||||||
|
blob = new Blob([buffer], { type: 'model/gltf-binary' });
|
||||||
|
} else if (ext === 'ifc') {
|
||||||
|
const r = await convertIFCtoGLB(buffer, fileName);
|
||||||
|
blob = r.blob; outName = r.fileName; outSize = r.fileSize;
|
||||||
|
} else {
|
||||||
|
const r = await convertToGLB(buffer, ext, fileName);
|
||||||
|
blob = r.blob; outName = r.fileName; outSize = r.fileSize;
|
||||||
|
}
|
||||||
|
const blobUrl = URL.createObjectURL(blob);
|
||||||
|
setModel({ fileName: outName, fileSize: outSize, url: blobUrl });
|
||||||
|
toast.success(`"${outName}" carregado da nuvem (RAM)`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toast.error('Falha ao gerar modelo demo');
|
toast.error('Falha ao carregar da nuvem (verifique URL/CORS)');
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingDemo(false);
|
setLoadingCloud(false);
|
||||||
}
|
}
|
||||||
}, [setModel]);
|
}, [setModel]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user