File size: 1,738 Bytes
fff4904
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React from 'react';
import { useFrame } from '@react-three/fiber';
import * as THREE from 'three';

const Planet = ({ 
  name, 
  size, 
  distance, 
  speed, 
  color, 
  texture, 
  onClick,
  hasRings = false 
}) => {
  const planetRef = React.useRef();
  const pivotRef = React.useRef();
  
  useFrame((state) => {
    if (pivotRef.current) {
      pivotRef.current.rotation.y += speed * 0.005;
    }
    
    if (planetRef.current) {
      planetRef.current.rotation.y += 0.01;
    }
  });
  
  return (
    <group ref={pivotRef}>
      {/* Orbit path */}
      <mesh rotation={[-Math.PI / 2, 0, 0]} onClick={onClick}>
        <ringGeometry args={[distance - 0.1, distance + 0.1, 64]} />
        <meshBasicMaterial color="#FFFFFF" transparent opacity={0.1} />
      </mesh>
      
      {/* Planet */}
      <mesh 
        ref={planetRef}
        position={[distance, 0, 0]}
        onClick={onClick}
        onPointerOver={() => document.body.style.cursor = 'pointer'}
        onPointerOut={() => document.body.style.cursor = 'auto'}
      >
        <sphereGeometry args={[size, 32, 32]} />
        <meshStandardMaterial 
          color={color}
          roughness={0.7}
          metalness={0.1}
          map={texture ? new THREE.TextureLoader().load(texture) : null}
        />
        
        {/* Rings for Saturn */}
        {hasRings && (
          <mesh rotation={[-Math.PI / 2.5, 0, 0]}>
            <ringGeometry args={[size * 1.4, size * 2.2, 64]} />
            <meshStandardMaterial 
              color="#CDBA86" 
              transparent 
              opacity={0.8} 
              side={THREE.DoubleSide}
            />
          </mesh>
        )}
      </mesh>
    </group>
  );
};

export default Planet;