import { useRef, useMemo, useState, useEffect } from 'react';
import { Canvas, useFrame } from '@react-three/fiber';
import { OrbitControls, Stars, useTexture } from '@react-three/drei';
import * as THREE from 'three';
function GaussianPoints({ worldData, isLoading }) {
const pointsRef = useRef();
const [hovered, setHovered] = useState(false);
const { positions, colors, sizes } = useMemo(() => {
if (isLoading || !worldData) {
return { positions: new Float32Array(0), colors: new Float32Array(0), sizes: new Float32Array(0) };
}
const count = worldData.pointCount || 50000;
const positions = new Float32Array(count * 3);
const colors = new Float32Array(count * 3);
const sizes = new Float32Array(count);
const colorPalette = worldData.colorPalette || [[0.4, 0.6, 0.9], [0.2, 0.8, 0.4], [0.9, 0.3, 0.5]];
for (let i = 0; i < count; i++) {
const i3 = i * 3;
// Spherical distribution for 360 capture feel
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
const r = 2 + Math.random() * 3;
positions[i3] = r * Math.sin(phi) * Math.cos(theta);
positions[i3 + 1] = r * Math.sin(phi) * Math.sin(theta);
positions[i3 + 2] = r * Math.cos(phi);
const color = colorPalette[Math.floor(Math.random() * colorPalette.length)];
colors[i3] = color[0] + (Math.random() - 0.5) * 0.2;
colors[i3 + 1] = color[1] + (Math.random() - 0.5) * 0.2;
colors[i3 + 2] = color[2] + (Math.random() - 0.5) * 0.2;
sizes[i] = Math.random() * 0.05 + 0.01;
}
return { positions, colors, sizes };
}, [worldData, isLoading]);
useFrame((state) => {
if (pointsRef.current) {
pointsRef.current.rotation.y += 0.001;
pointsRef.current.rotation.x = Math.sin(state.clock.elapsedTime * 0.1) * 0.1;
}
});
if (isLoading) return null;
return (
Loading Gaussian Splats...
Processing 360° capture data
Controls
Left Click: Rotate
Right Click: Pan
Scroll: Zoom