Skip to content

Commit b7bfd28

Browse files
committed
πŸ›΅πŸ― ↝ [SSP-41]: Asteroid Generator is working now
1 parent 8678f4e commit b7bfd28

File tree

7 files changed

+190
-22
lines changed

7 files changed

+190
-22
lines changed

β€Žcomponents/Data/Generator/Astronomers/DailyMinorPlanet/asteroid-viewer.tsxβ€Ž

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
import { Canvas } from "@react-three/fiber"
2-
import { Stars, OrbitControls } from "@react-three/drei";
1+
"use client";
2+
3+
import { Canvas } from "@react-three/fiber";
4+
import { OrbitControls } from "@react-three/drei";
35
import { Slider } from "@/components/ui/slider";
46
import { useState } from "react";
57
import { Asteroid } from "./Asteroid";
6-
import { Effects } from "./effects";
8+
import { Background } from "./background";
9+
10+
interface AsteroidGeneratorProps {
11+
classificationConfig?: any;
12+
classificationId: string;
13+
};
714

8-
export default function AsteroidViewer() {
15+
export default function AsteroidViewer({ classificationConfig, classificationId }: AsteroidGeneratorProps) {
916
const [metallic, setMetallic] = useState(0.5)
1017

1118
return (
1219
<div className="w-full h-screen bg-black">
1320
<Canvas camera={{ position: [0, 0, 4] }}>
14-
<color attach="background" args={["black"]} />
15-
<Stars radius={100} depth={50} count={5000} factor={4} saturation={0} fade speed={1} />
21+
<Background />
1622
<Asteroid metallic={metallic} />
1723
<OrbitControls enableZoom={false} autoRotate autoRotateSpeed={1} />
18-
<Effects />
1924
</Canvas>
2025
<div className="absolute bottom-8 left-1/2 -translate-x-1/2 w-64 bg-black/50 p-4 rounded-lg">
21-
<label className="text-white text-sm mb-2 block">Material Type</label>
26+
<label htmlFor="material-slider" className="text-white text-sm mb-2 block">Material Type</label>
2227
<Slider
28+
id="material-slider"
2329
value={[metallic]}
2430
onValueChange={([value]) => setMetallic(value)}
2531
max={1}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { useRef, useMemo } from "react"
2+
import * as THREE from "three"
3+
import { useFrame } from "@react-three/fiber"
4+
5+
const vertexShader = `
6+
varying vec2 vUv;
7+
void main() {
8+
vUv = uv;
9+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
10+
}
11+
`
12+
13+
const fragmentShader = `
14+
uniform float time;
15+
varying vec2 vUv;
16+
17+
float random(vec2 st) {
18+
return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123);
19+
}
20+
21+
void main() {
22+
vec2 uv = vUv;
23+
24+
// Create a noisy background
25+
float noise = random(uv + time * 0.1);
26+
vec3 color = vec3(noise * 0.15);
27+
28+
// Add stars
29+
float star = step(0.998, random(uv));
30+
color += star;
31+
32+
gl_FragColor = vec4(color, 1.0);
33+
}
34+
`
35+
36+
export function Background() {
37+
const shaderRef = useRef<THREE.ShaderMaterial>(null)
38+
39+
const uniforms = useMemo(
40+
() => ({
41+
time: { value: 0 },
42+
}),
43+
[]
44+
)
45+
46+
useFrame((state) => {
47+
if (shaderRef.current) {
48+
shaderRef.current.uniforms.time.value = state.clock.elapsedTime
49+
}
50+
})
51+
52+
return (
53+
<mesh>
54+
<planeGeometry args={[2, 2]} />
55+
<shaderMaterial
56+
ref={shaderRef}
57+
vertexShader={vertexShader}
58+
fragmentShader={fragmentShader}
59+
uniforms={uniforms}
60+
/>
61+
</mesh>
62+
);
63+
};
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"use client";
2+
3+
import React, { useEffect, useState } from "react";
4+
import { PostCardSingleWithGenerator } from "@/content/Posts/PostWithGen";
5+
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
6+
7+
interface Classification {
8+
id: number;
9+
created_at: string;
10+
content: string | null;
11+
author: string | null;
12+
anomaly: number | null;
13+
media: any | null;
14+
classificationtype: string | null;
15+
classificationConfiguration: any | null;
16+
};
17+
18+
export default function DMPGenerator() {
19+
const supabase = useSupabaseClient();
20+
const session = useSession();
21+
22+
const [classifications, setClassifications] = useState<any[]>([]);
23+
const [loading, setLoading] = useState<boolean>(true);
24+
const [error, setError] = useState<string | null>(null);
25+
26+
const fetchClassifications = async () => {
27+
if (!session?.user) {
28+
setError("User session not found.");
29+
setLoading(false);
30+
return;
31+
};
32+
33+
setLoading(true);
34+
setError(null);
35+
try {
36+
const { data, error } = await supabase
37+
.from('classifications')
38+
.select('*')
39+
.eq("author", session.user.id)
40+
.eq('classificationtype', 'telescope-minorPlanet')
41+
.order('created_at', { ascending: false }) as { data: Classification[]; error: any };
42+
43+
if (error) throw error;
44+
45+
const processedData = data.map((classification) => {
46+
const media = classification.media;
47+
let images: string[] = [];
48+
49+
if (Array.isArray(media) && media.length === 2 && typeof media[1] === "string") {
50+
images.push(media[1]);
51+
} else if (media && media.uploadUrl) {
52+
images.push(media.uploadUrl);
53+
};
54+
55+
const votes = classification.classificationConfiguration?.votes || 0;
56+
57+
return { ...classification, images, votes };
58+
});
59+
60+
setClassifications(processedData);
61+
} catch (error) {
62+
console.error("Error fetching classifications:", error);
63+
setError("Failed to load classifications.");
64+
} finally {
65+
setLoading(false);
66+
};
67+
};
68+
69+
useEffect(() => {
70+
fetchClassifications();
71+
}, [session]);
72+
73+
return (
74+
<div className="space-y-8">
75+
{loading ? (
76+
<p>Loading classifications</p>
77+
) : error ? (
78+
<p>{error}</p>
79+
) : (
80+
classifications.map((classification) => (
81+
<PostCardSingleWithGenerator
82+
key={classification.id}
83+
classificationId={classification.id}
84+
title={classification.title}
85+
author={classification.author}
86+
content={classification.content}
87+
votes={classification.votes || 0}
88+
category={classification.category}
89+
tags={classification.tags || []}
90+
images={classification.images || []}
91+
anomalyId={classification.anomaly}
92+
classificationConfig={classification.classificationConfiguration}
93+
classificationType={classification.classificationtype}
94+
/>
95+
))
96+
)}
97+
</div>
98+
);
99+
};

β€Žcomponents/Structures/Missions/Astronomers/DailyMinorPlanet/DailyMinorPlanet.tsxβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { BarChartBigIcon, GlassWater, Guitar, PenBoxIcon, RadioIcon, SpeechIcon,
44
import MissionShell from "../../BasePlate";
55
import { DailyMinorPlanet } from "@/components/Projects/Telescopes/DailyMinorPlanet";
66
import VoteDMPClassifications from "./DMPVote";
7+
import DMPGenerator from "./AsteroidMaker";
78

89
const DailyMinorPlanetMissions = () => {
910
const supabase = useSupabaseClient();
@@ -73,7 +74,7 @@ const DailyMinorPlanetMissions = () => {
7374
icon: Guitar,
7475
points: 2,
7576
completedCount: 0,
76-
// internalComponent: () => <div></div>,
77+
internalComponent: () => <div><DMPGenerator /></div>,
7778
color: 'text-green-300',
7879
shadow: true,
7980
action: () => {},

β€Žcontent/Posts/PostWithGen.tsxβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { CommentCard } from "../Comments/CommentSingle";
1111

1212
import CloudSignal from "@/components/Structures/Missions/Meteorologists/Cloudspotting/CloudSignal";
1313
import PlanetGenerator from "@/components/Data/Generator/Astronomers/PlanetHunters/PlanetGenerator";
14+
import AsteroidViewer from "@/components/Data/Generator/Astronomers/DailyMinorPlanet/asteroid-viewer";
1415

1516
interface CommentProps {
1617
id: number;
@@ -95,6 +96,11 @@ export function PostCardSingleWithGenerator({
9596
classificationConfig={classificationConfig}
9697
author={author}
9798
/>;
99+
case "telescope-minorPlanet":
100+
return <AsteroidViewer
101+
classificationId={String(classificationId)}
102+
classificationConfig={classificationConfig}
103+
/>;
98104
default:
99105
return (
100106
<div>

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"@radix-ui/react-toggle": "^1.1.0",
3333
"@react-three/drei": "^9.120.4",
3434
"@react-three/fiber": "^8.17.10",
35-
"@react-three/postprocessing": "^2.16.3",
35+
"@react-three/postprocessing": "^2.16.5",
3636
"@supabase/auth-helpers-nextjs": "^0.10.0",
3737
"@supabase/auth-helpers-react": "^0.5.0",
3838
"@supabase/auth-ui-react": "^0.4.7",

β€Žyarn.lockβ€Ž

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,20 +1843,13 @@
18431843
dependencies:
18441844
"@radix-ui/react-compose-refs" "1.1.0"
18451845

1846-
"@radix-ui/react-slot@1.1.1":
1846+
"@radix-ui/react-slot@1.1.1", "@radix-ui/react-slot@^1.1.1":
18471847
version "1.1.1"
18481848
resolved "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.1.1.tgz"
18491849
integrity sha512-RApLLOcINYJA+dMVbOju7MYv1Mb2EBp2nH4HdDzXTSyaR5optlm6Otrz1euW3HbdOR8UmmFK06TD+A9frYWv+g==
18501850
dependencies:
18511851
"@radix-ui/react-compose-refs" "1.1.1"
18521852

1853-
"@radix-ui/react-slot@^1.1.1":
1854-
version "1.1.1"
1855-
resolved "https://registry.yarnpkg.com/@radix-ui/react-slot/-/react-slot-1.1.1.tgz#ab9a0ffae4027db7dc2af503c223c978706affc3"
1856-
integrity sha512-RApLLOcINYJA+dMVbOju7MYv1Mb2EBp2nH4HdDzXTSyaR5optlm6Otrz1euW3HbdOR8UmmFK06TD+A9frYWv+g==
1857-
dependencies:
1858-
"@radix-ui/react-compose-refs" "1.1.1"
1859-
18601853
"@radix-ui/react-switch@^1.1.1":
18611854
version "1.1.1"
18621855
resolved "https://registry.npmjs.org/@radix-ui/react-switch/-/react-switch-1.1.1.tgz"
@@ -2193,10 +2186,10 @@
21932186
suspend-react "^0.1.3"
21942187
zustand "^3.7.1"
21952188

2196-
"@react-three/postprocessing@^2.16.3":
2197-
version "2.16.3"
2198-
resolved "https://registry.yarnpkg.com/@react-three/postprocessing/-/postprocessing-2.16.3.tgz#91bad6a541db7573f3100f1c7edf67d22c66413e"
2199-
integrity sha512-ftodXpUsy0/mzn0KqyV7MBau71dD9C5UOFnB3kHhCLNoxjKYQWZa9do0olJTSkl3owYXRfNHcLriK1Xn8wxZJw==
2189+
"@react-three/postprocessing@^2.16.5":
2190+
version "2.16.5"
2191+
resolved "https://registry.yarnpkg.com/@react-three/postprocessing/-/postprocessing-2.16.5.tgz#861db992b8781e54f97b79dee48f84942817cdf5"
2192+
integrity sha512-LcZy25bSz1g9n/QgSRUfgESXnAUDDDeQBI6FJ9DZsxCBukbgxjT9BHexVIu9JJ3G8SkRi8I68Ii+zytP51D9dg==
22002193
dependencies:
22012194
buffer "^6.0.3"
22022195
maath "^0.6.0"

0 commit comments

Comments
Β (0)