Add vending machine interaction features. Introduced a floating label for the vending machine in index.html, implemented hover effects and click handling in main.js, and styled the label in style.css. Enhanced world.js to include a visual outline for the vending machine during hover.
Browse files- frontend/index.html +1 -0
- frontend/main.js +56 -0
- frontend/style.css +68 -0
- frontend/world.js +33 -1
frontend/index.html
CHANGED
|
@@ -21,6 +21,7 @@
|
|
| 21 |
<h1 id="title">LoFinity</h1>
|
| 22 |
<p id="subtitle">♪ chill beats, freshly vended</p>
|
| 23 |
</div>
|
|
|
|
| 24 |
<canvas id="scene"></canvas>
|
| 25 |
<script type="module" src="/static/main.js"></script>
|
| 26 |
</body>
|
|
|
|
| 21 |
<h1 id="title">LoFinity</h1>
|
| 22 |
<p id="subtitle">♪ chill beats, freshly vended</p>
|
| 23 |
</div>
|
| 24 |
+
<div id="vending-label"><span>♪ vend a vibe</span></div>
|
| 25 |
<canvas id="scene"></canvas>
|
| 26 |
<script type="module" src="/static/main.js"></script>
|
| 27 |
</body>
|
frontend/main.js
CHANGED
|
@@ -105,6 +105,61 @@ scene.add(sun);
|
|
| 105 |
|
| 106 |
const world = buildWorld(scene);
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
// ---------------------------------------------------------------------------
|
| 109 |
// Intro: hold on the sky, then ease the gaze down to the scene
|
| 110 |
// ---------------------------------------------------------------------------
|
|
@@ -188,6 +243,7 @@ function animate() {
|
|
| 188 |
}
|
| 189 |
|
| 190 |
camera.lookAt(lookTarget);
|
|
|
|
| 191 |
renderer.render(scene, camera);
|
| 192 |
}
|
| 193 |
animate();
|
|
|
|
| 105 |
|
| 106 |
const world = buildWorld(scene);
|
| 107 |
|
| 108 |
+
// ---------------------------------------------------------------------------
|
| 109 |
+
// Vending machine interaction: hover outline + floating label, click hook
|
| 110 |
+
// ---------------------------------------------------------------------------
|
| 111 |
+
|
| 112 |
+
const raycaster = new THREE.Raycaster();
|
| 113 |
+
const pointerNDC = new THREE.Vector2(-2, -2); // offscreen until first move
|
| 114 |
+
let pointerActive = false;
|
| 115 |
+
let vendingHovered = false;
|
| 116 |
+
|
| 117 |
+
const vendingLabel = document.getElementById("vending-label");
|
| 118 |
+
const labelAnchor = new THREE.Vector3();
|
| 119 |
+
const LABEL_OFFSET_Y = 5.6; // above the machine top
|
| 120 |
+
|
| 121 |
+
window.addEventListener("pointermove", (e) => {
|
| 122 |
+
pointerNDC.set(
|
| 123 |
+
(e.clientX / window.innerWidth) * 2 - 1,
|
| 124 |
+
-(e.clientY / window.innerHeight) * 2 + 1
|
| 125 |
+
);
|
| 126 |
+
pointerActive = true;
|
| 127 |
+
});
|
| 128 |
+
document.addEventListener("pointerleave", () => {
|
| 129 |
+
pointerActive = false;
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
function setVendingHover(hovered) {
|
| 133 |
+
if (hovered === vendingHovered) return;
|
| 134 |
+
vendingHovered = hovered;
|
| 135 |
+
world.vending.userData.outline.visible = hovered;
|
| 136 |
+
vendingLabel.classList.toggle("visible", hovered);
|
| 137 |
+
canvas.style.cursor = hovered ? "pointer" : "";
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
function updateVendingHover() {
|
| 141 |
+
if (intro.phase !== "idle" || !pointerActive) {
|
| 142 |
+
setVendingHover(false);
|
| 143 |
+
return;
|
| 144 |
+
}
|
| 145 |
+
raycaster.setFromCamera(pointerNDC, camera);
|
| 146 |
+
setVendingHover(raycaster.intersectObject(world.vending, true).length > 0);
|
| 147 |
+
|
| 148 |
+
if (vendingHovered) {
|
| 149 |
+
labelAnchor.copy(world.vending.position);
|
| 150 |
+
labelAnchor.y += LABEL_OFFSET_Y;
|
| 151 |
+
labelAnchor.project(camera);
|
| 152 |
+
vendingLabel.style.left = `${((labelAnchor.x + 1) / 2) * window.innerWidth}px`;
|
| 153 |
+
vendingLabel.style.top = `${((1 - labelAnchor.y) / 2) * window.innerHeight}px`;
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
canvas.addEventListener("click", () => {
|
| 158 |
+
if (!vendingHovered) return;
|
| 159 |
+
// Stage 3 continues here: camera zoom + prompt/coin modal
|
| 160 |
+
console.log("[LoFinity] vending machine clicked");
|
| 161 |
+
});
|
| 162 |
+
|
| 163 |
// ---------------------------------------------------------------------------
|
| 164 |
// Intro: hold on the sky, then ease the gaze down to the scene
|
| 165 |
// ---------------------------------------------------------------------------
|
|
|
|
| 243 |
}
|
| 244 |
|
| 245 |
camera.lookAt(lookTarget);
|
| 246 |
+
updateVendingHover();
|
| 247 |
renderer.render(scene, camera);
|
| 248 |
}
|
| 249 |
animate();
|
frontend/style.css
CHANGED
|
@@ -85,3 +85,71 @@ body {
|
|
| 85 |
transform: translateY(-12px);
|
| 86 |
}
|
| 87 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
transform: translateY(-12px);
|
| 86 |
}
|
| 87 |
}
|
| 88 |
+
|
| 89 |
+
#vending-label {
|
| 90 |
+
position: fixed;
|
| 91 |
+
left: 0;
|
| 92 |
+
top: 0;
|
| 93 |
+
transform: translate(-50%, -118%);
|
| 94 |
+
pointer-events: none;
|
| 95 |
+
z-index: 8;
|
| 96 |
+
opacity: 0;
|
| 97 |
+
transition: opacity 0.18s ease;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
#vending-label.visible {
|
| 101 |
+
opacity: 1;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
#vending-label span {
|
| 105 |
+
position: relative;
|
| 106 |
+
display: inline-block;
|
| 107 |
+
font-family: "Baloo 2", sans-serif;
|
| 108 |
+
font-weight: 800;
|
| 109 |
+
font-size: clamp(1rem, 1.8vw, 1.3rem);
|
| 110 |
+
color: #3a2c14;
|
| 111 |
+
background: #ffd84a;
|
| 112 |
+
padding: 0.4em 1.1em;
|
| 113 |
+
border-radius: 999px;
|
| 114 |
+
box-shadow: 0 6px 20px rgba(18, 44, 96, 0.28);
|
| 115 |
+
white-space: nowrap;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
#vending-label span::after {
|
| 119 |
+
content: "";
|
| 120 |
+
position: absolute;
|
| 121 |
+
left: 50%;
|
| 122 |
+
bottom: -5px;
|
| 123 |
+
width: 12px;
|
| 124 |
+
height: 12px;
|
| 125 |
+
background: #ffd84a;
|
| 126 |
+
border-radius: 2px;
|
| 127 |
+
transform: translateX(-50%) rotate(45deg);
|
| 128 |
+
z-index: -1;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
#vending-label.visible span {
|
| 132 |
+
animation:
|
| 133 |
+
label-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both,
|
| 134 |
+
label-bob 2s ease-in-out 0.45s infinite alternate;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
@keyframes label-pop {
|
| 138 |
+
from {
|
| 139 |
+
opacity: 0;
|
| 140 |
+
transform: scale(0.55) translateY(12px);
|
| 141 |
+
}
|
| 142 |
+
to {
|
| 143 |
+
opacity: 1;
|
| 144 |
+
transform: scale(1) translateY(0);
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
@keyframes label-bob {
|
| 149 |
+
from {
|
| 150 |
+
transform: translateY(0) rotate(-1.2deg);
|
| 151 |
+
}
|
| 152 |
+
to {
|
| 153 |
+
transform: translateY(-7px) rotate(1.2deg);
|
| 154 |
+
}
|
| 155 |
+
}
|
frontend/world.js
CHANGED
|
@@ -343,7 +343,39 @@ function buildVendingMachine() {
|
|
| 343 |
handle.position.set(0.45, 2.9, 1.0);
|
| 344 |
g.add(handle);
|
| 345 |
|
| 346 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
}
|
| 348 |
|
| 349 |
// --- bench ------------------------------------------------------------------
|
|
|
|
| 343 |
handle.position.set(0.45, 2.9, 1.0);
|
| 344 |
g.add(handle);
|
| 345 |
|
| 346 |
+
shadows(g);
|
| 347 |
+
|
| 348 |
+
// Hover outline: inflated back-face hull for the sides/top, plus a thin
|
| 349 |
+
// base plate peeking around the footprint — the hull's bottom rim would
|
| 350 |
+
// otherwise be buried in the sidewalk.
|
| 351 |
+
const outline = new THREE.Group();
|
| 352 |
+
const outlineMaterial = new THREE.MeshBasicMaterial({
|
| 353 |
+
color: 0xffd84a,
|
| 354 |
+
side: THREE.BackSide,
|
| 355 |
+
});
|
| 356 |
+
const hull = box(2.6, 4.4, 1.9, outlineMaterial);
|
| 357 |
+
hull.scale.setScalar(1.07);
|
| 358 |
+
hull.position.y = 2.2;
|
| 359 |
+
hull.castShadow = false;
|
| 360 |
+
outline.add(hull);
|
| 361 |
+
|
| 362 |
+
// the top trim cap is wider than the body — give it its own hull so the
|
| 363 |
+
// outline follows the stepped silhouette
|
| 364 |
+
const capHull = box(2.88, 0.36, 2.18, outlineMaterial);
|
| 365 |
+
capHull.position.y = 4.42;
|
| 366 |
+
capHull.castShadow = false;
|
| 367 |
+
outline.add(capHull);
|
| 368 |
+
|
| 369 |
+
const plate = box(2.92, 0.09, 2.16, new THREE.MeshBasicMaterial({ color: 0xffd84a }));
|
| 370 |
+
plate.position.y = 0.055;
|
| 371 |
+
plate.castShadow = false;
|
| 372 |
+
outline.add(plate);
|
| 373 |
+
|
| 374 |
+
outline.visible = false;
|
| 375 |
+
g.add(outline);
|
| 376 |
+
g.userData.outline = outline;
|
| 377 |
+
|
| 378 |
+
return g;
|
| 379 |
}
|
| 380 |
|
| 381 |
// --- bench ------------------------------------------------------------------
|