CarbonO2 commited on
Commit
fff4904
·
verified ·
1 Parent(s): 2227959

Upload components/Planet.jsx with huggingface_hub

Browse files
Files changed (1) hide show
  1. components/Planet.jsx +69 -0
components/Planet.jsx ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from 'react';
2
+ import { useFrame } from '@react-three/fiber';
3
+ import * as THREE from 'three';
4
+
5
+ const Planet = ({
6
+ name,
7
+ size,
8
+ distance,
9
+ speed,
10
+ color,
11
+ texture,
12
+ onClick,
13
+ hasRings = false
14
+ }) => {
15
+ const planetRef = React.useRef();
16
+ const pivotRef = React.useRef();
17
+
18
+ useFrame((state) => {
19
+ if (pivotRef.current) {
20
+ pivotRef.current.rotation.y += speed * 0.005;
21
+ }
22
+
23
+ if (planetRef.current) {
24
+ planetRef.current.rotation.y += 0.01;
25
+ }
26
+ });
27
+
28
+ return (
29
+ <group ref={pivotRef}>
30
+ {/* Orbit path */}
31
+ <mesh rotation={[-Math.PI / 2, 0, 0]} onClick={onClick}>
32
+ <ringGeometry args={[distance - 0.1, distance + 0.1, 64]} />
33
+ <meshBasicMaterial color="#FFFFFF" transparent opacity={0.1} />
34
+ </mesh>
35
+
36
+ {/* Planet */}
37
+ <mesh
38
+ ref={planetRef}
39
+ position={[distance, 0, 0]}
40
+ onClick={onClick}
41
+ onPointerOver={() => document.body.style.cursor = 'pointer'}
42
+ onPointerOut={() => document.body.style.cursor = 'auto'}
43
+ >
44
+ <sphereGeometry args={[size, 32, 32]} />
45
+ <meshStandardMaterial
46
+ color={color}
47
+ roughness={0.7}
48
+ metalness={0.1}
49
+ map={texture ? new THREE.TextureLoader().load(texture) : null}
50
+ />
51
+
52
+ {/* Rings for Saturn */}
53
+ {hasRings && (
54
+ <mesh rotation={[-Math.PI / 2.5, 0, 0]}>
55
+ <ringGeometry args={[size * 1.4, size * 2.2, 64]} />
56
+ <meshStandardMaterial
57
+ color="#CDBA86"
58
+ transparent
59
+ opacity={0.8}
60
+ side={THREE.DoubleSide}
61
+ />
62
+ </mesh>
63
+ )}
64
+ </mesh>
65
+ </group>
66
+ );
67
+ };
68
+
69
+ export default Planet;