Spaces:
Sleeping
Sleeping
File size: 1,351 Bytes
c84aa63 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import React, { useRef, useEffect } from 'react'
import * as GaussianSplats3D from '@mkkellogg/gaussian-splats-3d'
export default function SplatViewer({ splatUrl }) {
const containerRef = useRef(null)
useEffect(() => {
if (!containerRef.current) return
let viewer = null
try {
viewer = new GaussianSplats3D.Viewer({
selfDrivenMode: true,
useWebXR: false,
rootElement: containerRef.current,
cameraUp: [0, 1, 0],
initialCameraPosition: [0, 1, 5],
initialCameraLookAt: [0, 0, 0],
sharedMemoryForWorkers: false // CRITICAL FIX: Disables SharedArrayBuffer which breaks on Vercel without strict CORS headers
})
viewer.addSplatScene(splatUrl, {
splatAlphaCrop: 0.1,
})
.then(() => {
viewer.start()
})
.catch((err) => {
console.error("Failed to load splat scene:", err);
});
} catch(err) {
console.error("Viewer initialization failed:", err)
}
return () => {
if (viewer) {
try {
viewer.dispose();
} catch(e) {}
}
if (containerRef.current) {
containerRef.current.innerHTML = '';
}
}
}, [splatUrl])
return (
<div ref={containerRef} className="w-full h-full relative" style={{ minHeight: '500px' }} />
)
}
|