eloigil6 commited on
Commit
026e1bb
·
1 Parent(s): c58be5d

Implement day/night cycle and lamp interaction features. Updated main.js to manage the transition between day and night modes, including dynamic lighting adjustments and palette changes. Added a new lamp label in index.html for user interaction, and modified style.css for proper positioning of the label. Enhanced world.js to include outlines for the lamp and its components, improving visual feedback during interactions.

Browse files
.claude/launch.json CHANGED
@@ -3,10 +3,10 @@
3
  "configurations": [
4
  {
5
  "name": "lofinity",
6
- "runtimeExecutable": ".venv/bin/python",
7
- "runtimeArgs": ["app.py"],
8
  "port": 7860,
9
- "autoPort": false
10
  }
11
  ]
12
  }
 
3
  "configurations": [
4
  {
5
  "name": "lofinity",
6
+ "runtimeExecutable": "/bin/sh",
7
+ "runtimeArgs": ["-c", "GRADIO_SERVER_PORT=$PORT exec .venv/bin/python app.py"],
8
  "port": 7860,
9
+ "autoPort": true
10
  }
11
  ]
12
  }
frontend/index.html CHANGED
@@ -28,6 +28,7 @@
28
  <div id="collection-label" class="hover-label">
29
  <span>♪ cassette collection</span>
30
  </div>
 
31
 
32
  <div id="machine-modal" class="hidden">
33
  <button id="modal-close" aria-label="close">×</button>
 
28
  <div id="collection-label" class="hover-label">
29
  <span>♪ cassette collection</span>
30
  </div>
31
+ <div id="lamp-label" class="hover-label"><span>☾ turn on night</span></div>
32
 
33
  <div id="machine-modal" class="hidden">
34
  <button id="modal-close" aria-label="close">×</button>
frontend/main.js CHANGED
@@ -86,7 +86,8 @@ scene.add(new THREE.Mesh(new THREE.SphereGeometry(450, 32, 16), skyMaterial));
86
  // Lights
87
  // ---------------------------------------------------------------------------
88
 
89
- scene.add(new THREE.HemisphereLight(0xcfe8ff, 0xa8b48a, 0.85));
 
90
 
91
  // Clouds (layer 1) get their own bounce light: white from above, cool
92
  // blue-gray from below — no green ground tint.
@@ -114,6 +115,17 @@ scene.add(sun);
114
 
115
  const world = buildWorld(scene);
116
 
 
 
 
 
 
 
 
 
 
 
 
117
  // Freeze transform recomputation for the (almost entirely) static scene;
118
  // only the clouds and the camera move.
119
  scene.traverse((obj) => {
@@ -155,6 +167,15 @@ const interactables = [
155
  labelOffsetY: 1.15, // above the bench backrest
156
  onClick: () => zoomToBench(),
157
  },
 
 
 
 
 
 
 
 
 
158
  ];
159
 
160
  window.addEventListener("pointermove", (e) => {
@@ -197,6 +218,7 @@ function updateHover() {
197
  if (hoveredItem) {
198
  labelAnchor.copy(hoveredItem.anchor);
199
  labelAnchor.y += hoveredItem.labelOffsetY;
 
200
  labelAnchor.project(camera);
201
  hoveredItem.label.style.left = `${((labelAnchor.x + 1) / 2) * window.innerWidth}px`;
202
  hoveredItem.label.style.top = `${((1 - labelAnchor.y) / 2) * window.innerHeight}px`;
@@ -282,6 +304,83 @@ function setMachineBusy(busy) {
282
  }
283
  }
284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  // ---------------------------------------------------------------------------
286
  // Backend bridge + modal UI
287
  // ---------------------------------------------------------------------------
@@ -425,13 +524,21 @@ function animate(now = 0) {
425
  const transitioning =
426
  intro.phase === "descending" ||
427
  view.mode === "zoom-in" ||
428
- view.mode === "zoom-out";
 
429
  const interval = transitioning ? 1000 / 60 : 1000 / 30;
430
  if (now - lastRender < interval - 1) return;
431
  const dt = Math.min((now - lastRender) / 1000, 0.1);
432
  lastRender = now;
433
  const elapsed = clock.getElapsedTime();
434
 
 
 
 
 
 
 
 
435
  for (const cloud of world.clouds) {
436
  cloud.position.x += cloud.userData.speed * dt;
437
  if (cloud.position.x > 170) cloud.position.x = -170;
 
86
  // Lights
87
  // ---------------------------------------------------------------------------
88
 
89
+ const hemi = new THREE.HemisphereLight(0xcfe8ff, 0xa8b48a, 0.85);
90
+ scene.add(hemi);
91
 
92
  // Clouds (layer 1) get their own bounce light: white from above, cool
93
  // blue-gray from below — no green ground tint.
 
115
 
116
  const world = buildWorld(scene);
117
 
118
+ // Lamp pool light: dark by day, ramps up in night mode. Sits at the bulb
119
+ // (lamp group origin + the bulb's local offset). No shadows — the shadow map
120
+ // is baked once, and this only lights up at night anyway.
121
+ const lampLight = new THREE.PointLight(0xffd9a0, 0, 24, 2);
122
+ lampLight.position.set(
123
+ world.lamp.position.x - 1.85,
124
+ world.lamp.position.y + 8.73,
125
+ world.lamp.position.z,
126
+ );
127
+ scene.add(lampLight);
128
+
129
  // Freeze transform recomputation for the (almost entirely) static scene;
130
  // only the clouds and the camera move.
131
  scene.traverse((obj) => {
 
167
  labelOffsetY: 1.15, // above the bench backrest
168
  onClick: () => zoomToBench(),
169
  },
170
+ {
171
+ object: world.lamp,
172
+ outlines: [world.lamp.userData.outline],
173
+ label: document.getElementById("lamp-label"),
174
+ anchor: world.lamp.position.clone(),
175
+ labelOffsetY: 5.5, // pole mid-height; CSS sits the bubble to its left
176
+ labelOffsetX: -0.3, // left of the bubble
177
+ onClick: () => toggleNight(),
178
+ },
179
  ];
180
 
181
  window.addEventListener("pointermove", (e) => {
 
218
  if (hoveredItem) {
219
  labelAnchor.copy(hoveredItem.anchor);
220
  labelAnchor.y += hoveredItem.labelOffsetY;
221
+ labelAnchor.x += hoveredItem.labelOffsetX || 0;
222
  labelAnchor.project(camera);
223
  hoveredItem.label.style.left = `${((labelAnchor.x + 1) / 2) * window.innerWidth}px`;
224
  hoveredItem.label.style.top = `${((1 - labelAnchor.y) / 2) * window.innerHeight}px`;
 
304
  }
305
  }
306
 
307
+ // ---------------------------------------------------------------------------
308
+ // Day / night: clicking the lamp post eases the sky shader, fog and lights to
309
+ // a moonlit palette and lights the lamp. No camera move — the scene just dims.
310
+ // ---------------------------------------------------------------------------
311
+
312
+ const DAY = {
313
+ skyTop: new THREE.Color(0x1547a8),
314
+ skyHorizon: new THREE.Color(0xbfe3ff),
315
+ fog: new THREE.Color(0xbfe3ff),
316
+ hemiSky: new THREE.Color(0xcfe8ff),
317
+ hemiGround: new THREE.Color(0xa8b48a),
318
+ sun: new THREE.Color(0xfff2dc),
319
+ cloudSky: new THREE.Color(0xf2f8ff),
320
+ cloudGround: new THREE.Color(0xc9d9ec),
321
+ };
322
+ const NIGHT = {
323
+ skyTop: new THREE.Color(0x05060f),
324
+ skyHorizon: new THREE.Color(0x232a4d),
325
+ fog: new THREE.Color(0x141a30),
326
+ hemiSky: new THREE.Color(0x2a3358),
327
+ hemiGround: new THREE.Color(0x1c2422),
328
+ sun: new THREE.Color(0x93a9e6), // a cool, dim "moon"
329
+ cloudSky: new THREE.Color(0x9fb0d8),
330
+ cloudGround: new THREE.Color(0x2b3450),
331
+ };
332
+
333
+ const NIGHT_KEY = "lofinity:night"; // localStorage flag, persists the choice
334
+
335
+ let isNight = false;
336
+ let nightTarget = 0; // 0 = day, 1 = night
337
+ let nightMix = 0; // eased toward nightTarget in the render loop
338
+
339
+ function applyPalette(m) {
340
+ const sky = skyMaterial.uniforms;
341
+ sky.topColor.value.lerpColors(DAY.skyTop, NIGHT.skyTop, m);
342
+ sky.horizonColor.value.lerpColors(DAY.skyHorizon, NIGHT.skyHorizon, m);
343
+ scene.fog.color.lerpColors(DAY.fog, NIGHT.fog, m);
344
+ hemi.color.lerpColors(DAY.hemiSky, NIGHT.hemiSky, m);
345
+ hemi.groundColor.lerpColors(DAY.hemiGround, NIGHT.hemiGround, m);
346
+ hemi.intensity = THREE.MathUtils.lerp(0.85, 0.32, m);
347
+ sun.color.lerpColors(DAY.sun, NIGHT.sun, m);
348
+ sun.intensity = THREE.MathUtils.lerp(1.6, 0.5, m);
349
+ cloudLight.color.lerpColors(DAY.cloudSky, NIGHT.cloudSky, m);
350
+ cloudLight.groundColor.lerpColors(DAY.cloudGround, NIGHT.cloudGround, m);
351
+ cloudLight.intensity = THREE.MathUtils.lerp(0.9, 0.4, m);
352
+ lampLight.intensity = THREE.MathUtils.lerp(0, 2.6, m);
353
+ }
354
+
355
+ function setNightLabel() {
356
+ const span = document.querySelector("#lamp-label span");
357
+ if (span) span.textContent = isNight ? "☀ back to day" : "☾ turn on night";
358
+ }
359
+
360
+ function toggleNight() {
361
+ isNight = !isNight;
362
+ nightTarget = isNight ? 1 : 0;
363
+ setNightLabel();
364
+ try {
365
+ localStorage.setItem(NIGHT_KEY, isNight ? "1" : "0");
366
+ } catch {
367
+ /* storage unavailable (private mode) — keep the choice in-memory only */
368
+ }
369
+ }
370
+
371
+ // restore the persisted day/night choice on load, applied instantly (no fade)
372
+ try {
373
+ if (localStorage.getItem(NIGHT_KEY) === "1") {
374
+ isNight = true;
375
+ nightTarget = 1;
376
+ nightMix = 1;
377
+ applyPalette(1);
378
+ setNightLabel();
379
+ }
380
+ } catch {
381
+ /* unreadable storage — start in day mode */
382
+ }
383
+
384
  // ---------------------------------------------------------------------------
385
  // Backend bridge + modal UI
386
  // ---------------------------------------------------------------------------
 
524
  const transitioning =
525
  intro.phase === "descending" ||
526
  view.mode === "zoom-in" ||
527
+ view.mode === "zoom-out" ||
528
+ nightMix !== nightTarget;
529
  const interval = transitioning ? 1000 / 60 : 1000 / 30;
530
  if (now - lastRender < interval - 1) return;
531
  const dt = Math.min((now - lastRender) / 1000, 0.1);
532
  lastRender = now;
533
  const elapsed = clock.getElapsedTime();
534
 
535
+ // ease the day/night palette toward its target, only while it's moving
536
+ if (nightMix !== nightTarget) {
537
+ nightMix = THREE.MathUtils.damp(nightMix, nightTarget, 3.2, dt);
538
+ if (Math.abs(nightMix - nightTarget) < 0.001) nightMix = nightTarget;
539
+ applyPalette(nightMix);
540
+ }
541
+
542
  for (const cloud of world.clouds) {
543
  cloud.position.x += cloud.userData.speed * dt;
544
  if (cloud.position.x > 170) cloud.position.x = -170;
frontend/style.css CHANGED
@@ -103,6 +103,20 @@ body {
103
  opacity: 1;
104
  }
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  .hover-label span {
107
  position: relative;
108
  display: inline-block;
 
103
  opacity: 1;
104
  }
105
 
106
+ /* the lamp label sits to the LEFT of the pole (which runs up the right edge),
107
+ vertically centred on the anchor, with its tail pointing right at the post */
108
+ #lamp-label {
109
+ transform: translate(calc(-100% - 14px), -50%);
110
+ }
111
+
112
+ #lamp-label span::after {
113
+ left: auto;
114
+ right: -5px;
115
+ bottom: auto;
116
+ top: 50%;
117
+ transform: translateY(-50%) rotate(45deg);
118
+ }
119
+
120
  .hover-label span {
121
  position: relative;
122
  display: inline-block;
frontend/world.js CHANGED
@@ -608,7 +608,34 @@ function buildLamp() {
608
  bulb.position.set(-1.85, 8.73, 0);
609
  g.add(bulb);
610
 
611
- return shadows(g);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
612
  }
613
 
614
  // --- trees ------------------------------------------------------------------
 
608
  bulb.position.set(-1.85, 8.73, 0);
609
  g.add(bulb);
610
 
611
+ shadows(g);
612
+
613
+ // Hover outline: inflated back-face hulls tracing the base, pole, arm and
614
+ // head (same trick as buildVending). Built after shadows() so they never cast.
615
+ const outline = new THREE.Group();
616
+ const outlineMaterial = new THREE.MeshBasicMaterial({
617
+ color: 0xffd84a,
618
+ side: THREE.BackSide,
619
+ });
620
+ const base_ = cyl(0.3, 0.38, 0.6, 10, outlineMaterial);
621
+ base_.position.y = 0.25;
622
+ const pole_ = cyl(0.16, 0.2, 8.15, 10, outlineMaterial);
623
+ pole_.position.y = 4.25;
624
+ const arm_ = cyl(0.13, 0.13, 2.1, 8, outlineMaterial);
625
+ arm_.position.set(-0.85, 8.5, 0);
626
+ arm_.rotation.z = 1.15;
627
+ const head_ = box(1.16, 0.4, 0.58, outlineMaterial);
628
+ head_.position.set(-1.85, 8.84, 0);
629
+ for (const part of [base_, pole_, arm_, head_]) {
630
+ part.castShadow = false;
631
+ part.receiveShadow = false;
632
+ outline.add(part);
633
+ }
634
+ outline.visible = false;
635
+ g.add(outline);
636
+ g.userData.outline = outline;
637
+
638
+ return g;
639
  }
640
 
641
  // --- trees ------------------------------------------------------------------