Files
goal-planner/frontend/components/3d/HeroAnimation.tsx
T
2026-11-02 15:52:53 +08:00

44 lines
1.5 KiB
TypeScript

import React, { useState, useRef } from 'react';
import { Canvas, useFrame } from '@react-three/fiber';
import { Points, PointMaterial } from '@react-three/drei';
import * as random from 'maath/random';
import type { Points as PointsType } from 'three';
const Starfield: React.FC = () => {
const ref = useRef<PointsType>(null);
const [sphere] = useState(() => random.inSphere(new Float32Array(5000), { radius: 1.5 }));
useFrame((state, delta) => {
if (ref.current) {
ref.current.rotation.x -= delta / 10;
ref.current.rotation.y -= delta / 15;
}
});
return (
// FIX: Replaced <group> with a rotation property on the <Points> component.
// This resolves the "Property 'group' does not exist on type 'JSX.IntrinsicElements'" error
// by avoiding the problematic element while keeping the same visual transformation.
<Points ref={ref} positions={sphere} stride={3} frustumCulled={false} rotation={[0, 0, Math.PI / 4]}>
<PointMaterial
transparent
color="#22c55e"
size={0.005}
sizeAttenuation={true}
depthWrite={false}
/>
</Points>
);
};
const HeroAnimation: React.FC = () => {
return (
<Canvas camera={{ position: [0, 0, 1] }}>
<React.Suspense fallback={null}>
<Starfield />
</React.Suspense>
</Canvas>
);
};
export default HeroAnimation;