Skip to content

Commit fb1dda1

Browse files
committed
2 parents 129150b + 5b2852c commit fb1dda1

7 files changed

Lines changed: 150 additions & 136 deletions

File tree

src/pages/home/.ipynb_checkpoints/Home-checkpoint.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import { main } from "./js/main.js";
55
import { useMouseMoving } from "../../hooks/useMouseMoving.js";
66

77
export default function Home() {
8-
const lvlNum = 4;
98
const canvasRef = useRef<HTMLCanvasElement | null>(null);
109
const zoomOutRef = useRef<(() => void) | null>(null);
11-
10+
const getLevelRef = useRef<(() => number) | null>(null);
1211
const [isVisible, setIsVisible] = useState(false);
1312
const [mountKey, setMountKey] = useState(0);
1413
const isMouseMoving = useMouseMoving(2500);
@@ -26,8 +25,9 @@ export default function Home() {
2625

2726
useEffect(() => {
2827
if (!canvasRef.current) return;
29-
const { zoomOut } = main(canvasRef.current, handleOpen);
28+
const { zoomOut, getLevel } = main(canvasRef.current, handleOpen);
3029
zoomOutRef.current = zoomOut;
30+
getLevelRef.current = getLevel;
3131
}, []);
3232

3333
return (
@@ -39,21 +39,24 @@ export default function Home() {
3939
}}
4040
>
4141
<div className={styles["header-brand"]}>
42-
<h1>glorpython</h1>
42+
<img src="/logo.png" alt="" />
4343
</div>
4444
</header>
4545
<section className="relative w-full h-screen">
46-
{isVisible && (
47-
48-
<div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-[90vw] h-[90vh] z-50">
49-
<LevelComponent
50-
key={mountKey}
51-
onClose={() => handleClose()}
52-
lvl={lvlNum}
53-
/>
54-
</div>
55-
56-
)}
46+
<div
47+
className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-[90vw] z-50"
48+
style={{
49+
maxHeight: isVisible ? "100vh" : "0",
50+
overflow: "hidden",
51+
transition: "max-height 0.3s ease",
52+
}}
53+
>
54+
<LevelComponent
55+
key={mountKey}
56+
onClose={() => handleClose()}
57+
lvl={getLevelRef.current ? getLevelRef.current() : 0}
58+
/>
59+
</div>
5760
<canvas ref={canvasRef} className={styles.solarsystem}></canvas>
5861
</section>
5962
</div>

src/pages/home/.ipynb_checkpoints/solarsystem-checkpoint.js

Lines changed: 47 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ timport * as THREE from "three";
33
const ZOOM_DIST = 5; // how close the camera gets (in planet radii + offset)
44
const TWEEN_SPEED = 0.07; // lerp factor for camera movement
55

6-
export function main(canvas) {
7-
6+
export function main(canvas, onPlanetFocus) {
7+
const loader = new THREE.TextureLoader();
88
const renderer = new THREE.WebGLRenderer({ antialias: true, canvas });
99
renderer.setPixelRatio(window.devicePixelRatio);
1010
renderer.toneMapping = THREE.ACESFilmicToneMapping;
1111
renderer.toneMappingExposure = 2.0;
1212

13+
const createRepeatingTexture = (path, repeatX = 2, repeatY = 1) => {
14+
const tex = loader.load(path);
15+
tex.wrapS = THREE.RepeatWrapping;
16+
tex.wrapT = THREE.RepeatWrapping;
17+
tex.repeat.set(repeatX, repeatY);
18+
return tex;
19+
};
20+
1321
const fov = 45;
1422
const aspect = canvas.clientWidth / canvas.clientHeight;
1523
const near = 0.1;
@@ -37,20 +45,19 @@ export function main(canvas) {
3745
// Sun
3846
const sunGeo = new THREE.SphereGeometry(4.5, 64, 64);
3947
const sunMat = new THREE.MeshStandardMaterial({
40-
color: 0xe8ffff,
41-
emissive: 0x88ffee,
42-
emissiveIntensity: 3.2,
43-
roughness: 0.0,
44-
metalness: 0.0
48+
map: createRepeatingTexture('/textures/glorptest.png', 3, 3),
49+
emissiveMap: loader.load('/textures/suntexture.webp'), // same tex drives the glow
50+
emissive: 0x91ffaf,
51+
emissiveIntensity: 0.1,
4552
});
4653
const sun = new THREE.Mesh(sunGeo, sunMat);
4754
scene.add(sun);
4855

4956
// Planets
5057
const planetData = [
51-
{ radius: 1.1, orbitR: 14, speed: 0.8, tilt: 0.2, color: 0xff6644, emissive: 0x441100 },
52-
{ radius: 1.5, orbitR: 24, speed: 0.45, tilt: 0.35, color: 0x44aaff, emissive: 0x001133 },
53-
{ radius: 1.2, orbitR: 36, speed: 0.25, tilt: 0.15, color: 0x88dd55, emissive: 0x112200 },
58+
{ radius: 1.1, orbitR: 14, speed: 0.8, tilt: 0.2, color: 0xff6644, emissive: 0x441100, texture: '/textures/texture1.webp'},
59+
{ radius: 1.5, orbitR: 24, speed: 0.45, tilt: 0.35, color: 0x44aaff, emissive: 0x001133, texture: '/textures/texture2.webp' },
60+
{ radius: 1.2, orbitR: 36, speed: 0.25, tilt: 0.15, color: 0x88dd55, emissive: 0x112200, texture: '/textures/texture3.webp'},
5461
];
5562

5663
const planets = planetData.flatMap(d => {
@@ -74,9 +81,7 @@ export function main(canvas) {
7481
return [0, 1, 2].map(i => {
7582
const geo = new THREE.SphereGeometry(d.radius, 36, 36);
7683
const mat = new THREE.MeshStandardMaterial({
77-
color: d.color,
78-
emissive: d.emissive,
79-
emissiveIntensity: 1.0,
84+
map: loader.load(d.texture),
8085
roughness: 0.65,
8186
metalness: 0.05
8287
});
@@ -128,11 +133,23 @@ export function main(canvas) {
128133
const raycaster = new THREE.Raycaster();
129134
const pointer = new THREE.Vector2();
130135

131-
let paused = false; // are planets frozen?
132-
let focusedPlanet = null; // the planet object we zoomed into
133-
let cameraTarget = null; // THREE.Vector3 we're tweening toward
134-
let lookAtTarget = null; // THREE.Vector3 we're looking at
136+
let paused = false;
137+
let focusedPlanet = null;
138+
let cameraTarget = null;
139+
let lookAtTarget = null;
135140
let tweening = false;
141+
let popupFired = false;
142+
143+
// Zoom out — resets focus and starts the camera tween back to the initial position.
144+
// Called both by canvas clicks on empty space and externally (e.g. the ✕ button).
145+
function zoomOut() {
146+
console.log("Hi");
147+
focusedPlanet = null;
148+
paused = false;
149+
tweening = true;
150+
cameraTarget = initPos.clone();
151+
lookAtTarget = new THREE.Vector3(0, 0, 0);
152+
}
136153

137154
canvas.addEventListener('click', e => {
138155
const rect = canvas.getBoundingClientRect();
@@ -144,20 +161,16 @@ export function main(canvas) {
144161
const hits = raycaster.intersectObjects(meshes);
145162

146163
if (hits.length > 0) {
147-
// Clicked a planet — focus it
148164
const hit = hits[0];
149165
focusedPlanet = planets.find(p => p.mesh === hit.object);
150-
paused = true;
151-
tweening = true;
166+
paused = true;
167+
tweening = true;
168+
popupFired = false;
152169
} else {
153-
// Clicked empty space — release
154-
focusedPlanet = null;
155-
paused = false;
156-
tweening = true;
157-
cameraTarget = initPos.clone();
158-
lookAtTarget = new THREE.Vector3(0, 0, 0);
170+
zoomOut();
159171
}
160172
});
173+
161174
// ─────────────────────────────────────────────────────────────────────
162175

163176
function resizeRendererToDisplaySize(renderer) {
@@ -172,7 +185,6 @@ export function main(canvas) {
172185

173186
function render() {
174187

175-
// Advance planet orbits (only when not paused)
176188
planets.forEach(p => {
177189
if (!paused) {
178190
p.angle += p.speed * 0.008;
@@ -187,47 +199,30 @@ export function main(canvas) {
187199

188200
sun.rotation.y += 0.003;
189201

190-
191-
192-
193-
194-
195-
196-
// Update the camera target each frame while focused
197-
// (so the camera tracks the planet even mid-tween if it still moves slightly)
198202
if (focusedPlanet) {
199203
const pPos = focusedPlanet.mesh.position;
200-
// Position the camera slightly behind & above the planet relative to the origin
201204
const dir = pPos.clone().normalize();
202205
cameraTarget = pPos.clone().add(dir.multiplyScalar(focusedPlanet.radius + ZOOM_DIST));
203206
cameraTarget.y += focusedPlanet.radius * 0.8;
204207
lookAtTarget = pPos.clone();
205208
}
206209

207-
// Tween camera
208210
if (tweening && cameraTarget && lookAtTarget) {
209211
camera.position.lerp(cameraTarget, TWEEN_SPEED);
210212
currentLookAt.lerp(lookAtTarget, TWEEN_SPEED);
211213
camera.lookAt(currentLookAt);
212214

213-
// Stop tweening once close enough
214215
if (camera.position.distanceTo(cameraTarget) < 0.05) {
215216
tweening = false;
216217

217-
218-
219-
220-
221-
// POP UP HERE
222-
223-
224-
225-
226-
227-
218+
if (focusedPlanet && !popupFired) {
219+
popupFired = true;
220+
if (typeof onPlanetFocus === 'function') {
221+
onPlanetFocus();
222+
}
223+
}
228224
}
229225
} else if (!paused) {
230-
// Normal parallax behaviour
231226
currentOffset.x += (targetOffset.x - currentOffset.x) * 0.13;
232227
currentOffset.y += (targetOffset.y - currentOffset.y) * 0.13;
233228

@@ -240,11 +235,6 @@ export function main(canvas) {
240235
camera.lookAt(currentLookAt);
241236
}
242237

243-
244-
245-
246-
247-
248238
if (resizeRendererToDisplaySize(renderer)) {
249239
camera.aspect = canvas.clientWidth / canvas.clientHeight;
250240
camera.updateProjectionMatrix();
@@ -255,4 +245,6 @@ export function main(canvas) {
255245
}
256246

257247
requestAnimationFrame(render);
248+
249+
return { zoomOut };
258250
}

src/pages/home/Home.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,24 @@ export default function Home() {
3939
}}
4040
>
4141
<div className={styles["header-brand"]}>
42-
<h1>glorpython</h1>
42+
<img src="/logo.png" alt="" />
4343
</div>
4444
</header>
4545
<section className="relative w-full h-screen">
46-
{isVisible && (
47-
48-
<div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-[90vw] h-[90vh] z-50">
49-
<LevelComponent
50-
// key={mountKey}
51-
selectedLevel={getLevelRef.current ? getLevelRef.current() : 0}
52-
onClose={() => handleClose()}
53-
/>
54-
</div>
55-
56-
)}
46+
<div
47+
className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-[90vw] z-50"
48+
style={{
49+
maxHeight: isVisible ? "100vh" : "0",
50+
overflow: "hidden",
51+
transition: "max-height 0.3s ease",
52+
}}
53+
>
54+
<LevelComponent
55+
key={mountKey}
56+
onClose={() => handleClose()}
57+
selectedLevel={getLevelRef.current ? getLevelRef.current() : 0}
58+
/>
59+
</div>
5760
<canvas ref={canvasRef} className={styles.solarsystem}></canvas>
5861
</section>
5962
</div>

src/pages/home/js/.ipynb_checkpoints/main-checkpoint.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export function main( canvas, onPlanetFocus ) {
2323
const currentLookAt = new THREE.Vector3(0, 0, 0);
2424
const origin = new THREE.Vector3(0, 0, 0);
2525

26+
function getLevel() {
27+
if (!focus.focusedPlanet) return 0;
28+
return focus.focusedPlanet.level;
29+
}
2630

2731
// --- Render loop ---
2832

@@ -37,7 +41,7 @@ export function main( canvas, onPlanetFocus ) {
3741
renderer.render(scene, camera);
3842
requestAnimationFrame(render);
3943

40-
44+
4145

4246
// --- Done! (the rest is defining these functions) ---
4347

@@ -85,14 +89,14 @@ export function main( canvas, onPlanetFocus ) {
8589
function updateFocusTarget() {
8690

8791
if (!focus.focusedPlanet) return;
88-
92+
8993
const planetPosition = focus.focusedPlanet.mesh.position;
9094
const planetDirection = planetPosition.clone().normalize();
9195

9296
focus.cameraTarget = planetPosition.clone().add(planetDirection.multiplyScalar(focus.focusedPlanet.radius + ZOOM_DIST));
9397
focus.cameraTarget.y += focus.focusedPlanet.radius * 0.8;
9498
focus.lookAtTarget = planetPosition.clone();
95-
99+
96100
}
97101

98102
function updateCameraTween () {
@@ -156,6 +160,6 @@ export function main( canvas, onPlanetFocus ) {
156160

157161
}
158162

159-
return { zoomOut };
163+
return { zoomOut, getLevel };
160164

161165
}

0 commit comments

Comments
 (0)