Prompt specification
Build or customize the Three.js 3D scene "Community recipe archive table" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Community recipe archive table
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/community-recipe-archive-table-x0052
Scene Description Prompt:
A low-poly recipe archive where ingredient tokens open matching book pages and highlight kitchen objects. Three.js from cdnjs, one HTML file.
Working Three.js Starter (community-recipe-archive-table-x0052):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#eee7da">
<title>Savor — A Low-Poly Recipe Archive</title>
<style>
:root {
--paper: #f8f2e7;
--paper-deep: #eee5d6;
--canvas: #d8d1c3;
--ink: #292722;
--muted: #777064;
--line: rgba(41, 39, 34, 0.14);
--red: #ce5944;
--olive: #69785a;
--gold: #d2a94f;
--shadow: 0 24px 60px rgba(48, 40, 27, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--paper-deep);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
height: 100dvh;
min-height: 660px;
overflow: hidden;
}
.topbar {
height: 74px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 25px;
background: rgba(248, 242, 231, 0.96);
border-bottom: 1px solid var(--line);
position: relative;
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 35px;
height: 35px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 3px;
transform: rotate(-7deg);
}
.brand-mark span {
display: block;
background: var(--red);
border-radius: 2px 7px 2px 7px;
}
.brand-mark span:nth-child(2) {
background: var(--olive);
border-radius: 7px 2px 7px 2px;
}
.brand-mark span:nth-child(3) {
background: var(--gold);
border-radius: 7px 2px 7px 2px;
}
.brand-mark span:nth-child(4) {
background: var(--ink);
border-radius: 2px 7px 2px 7px;
}
.brand-name {
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
letter-spacing: 0.08em;
line-height: 1;
}
.brand-subtitle {
margin-top: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.topbar-center {
position: absolute;
left: 50%;
transform: translateX(-50%);
color: var(--muted);
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.topbar-right {
display: flex;
align-items: center;
gap: 18px;
font-size: 11px;
color: var(--muted);
}
.archive-count {
display: flex;
align-items: center;
gap: 7px;
}
.archive-count::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--olive);
box-shadow: 0 0 0 4px rgba(105, 120, 90, 0.12);
}
.season-pill {
padding: 8px 12px;
border: 1px solid var(--line);
border-radius: 99px;
background: rgba(255, 255, 255, 0.35);
}
.main {
height: calc(100% - 74px);
display: grid;
grid-template-columns: 320px minmax(0, 1fr);
}
.archive {
min-height: 0;
padding: 24px 20px 18px;
background:
linear-gradient(rgba(248, 242, 231, 0.94), rgba(248, 242, 231, 0.94)),
repeating-linear-gradient(0deg, transparent 0 25px, rgba(0, 0, 0, 0.03) 26px);
border-right: 1px solid var(--line);
display: flex;
flex-direction: column;
z-index: 10;
}
.archive-heading {
display: flex;
align-items: end;
justify-content: space-between;
margin-bottom: 17px;
}
.eyebrow {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.archive-heading h1 {
margin: 5px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 500;
}
.archive-number {
font-family: Georgia, "Times New Roman", serif;
color: #b1a797;
font-size: 30px;
line-height: 1;
}
.search-wrap {
position: relative;
margin-bottom: 17px;
}
.search-wrap svg {
position: absolute;
width: 15px;
height: 15px;
left: 13px;
top: 50%;
transform: translateY(-50%);
color: var(--muted);
pointer-events: none;
}
#search {
width: 100%;
height: 42px;
padding: 0 13px 0 38px;
color: var(--ink);
background: rgba(255, 255, 255, 0.42);
border: 1px solid var(--line);
border-radius: 10px;
outline: none;
font-size: 12px;
transition: 160ms ease;
}
#search:focus {
background: rgba(255, 255, 255, 0.78);
border-color: rgba(206, 89, 68, 0.45);
box-shadow: 0 0 0 3px rgba(206, 89, 68, 0.08);
}
.recipe-list {
min-height: 0;
overflow: auto;
padding-right: 4px;
scrollbar-width: thin;
scrollbar-color: #c6bbaa transparent;
}
.recipe-card {
width: 100%;
display: grid;
grid-template-columns: 38px 1fr;
gap: 11px;
align-items: start;
text-align: left;
padding: 14px 10px;
margin: 0 0 5px;
border: 1px solid transparent;
border-radius: 10px;
background: transparent;
cursor: pointer;
transition: 160ms ease;
}
.recipe-card:hover {
background: rgba(255, 255, 255, 0.38);
}
.recipe-card.active {
background: rgba(255, 255, 255, 0.62);
border-color: rgba(41, 39, 34, 0.09);
box-shadow: 0 8px 20px rgba(54, 44, 30, 0.05);
}
.recipe-number {
color: #a69b8a;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
padding-top: 2px;
}
.recipe-card.active .recipe-number {
color: var(--red);
}
.recipe-card h3 {
margin: 0 0 6px;
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
font-weight: 600;
line-height: 1.18;
}
.recipe-meta {
display: flex;
gap: 8px;
align-items: center;
color: var(--muted);
font-size: 10px;
}
.ingredient-dots {
display: flex;
gap: 4px;
margin-top: 9px;
}
.ingredient-dots i {
display: block;
width: 8px;
height: 8px;
border-radius: 50% 45% 50% 45%;
transform: rotate(-20deg);
}
.archive-footer {
display: flex;
justify-content: space-between;
align-items: center;
padding: 14px 5px 0;
margin-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.workspace {
min-width: 0;
min-height: 0;
display: grid;
grid-template-rows: minmax(250px, 1fr) auto;
overflow: hidden;
background:
radial-gradient(circle at 35% 22%, rgba(255, 255, 255, 0.54), transparent 34%),
linear-gradient(145deg, #d9d3c7, #c9c1b3);
position: relative;
}
.scene-panel {
position: relative;
min-height: 250px;
overflow: hidden;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.scene-header {
position: absolute;
top: 20px;
left: 26px;
z-index: 4;
pointer-events: none;
}
.scene-header h2 {
margin: 5px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(19px, 2vw, 27px);
font-weight: 500;
}
.scene-kicker {
display: flex;
align-items: center;
gap: 8px;
}
.scene-kicker::before {
content: "";
width: 18px;
height: 1px;
background: var(--red);
}
.scene-tools {
position: absolute;
z-index: 5;
top: 19px;
right: 22px;
display: flex;
gap: 8px;
}
.tool-button {
width: 35px;
height: 35px;
border: 1px solid rgba(41, 39, 34, 0.13);
border-radius: 50%;
background: rgba(248, 242, 231, 0.65);
backdrop-filter: blur(8px);
cursor: pointer;
display: grid;
place-items: center;
transition: 160ms ease;
}
.tool-button:hover {
background: var(--paper);
transform: translateY(-1px);
}
.tool-button svg {
width: 14px;
height: 14px;
}
.object-labels {
position: absolute;
inset: 0;
pointer-events: none;
z-index: 3;
}
.object-label {
position: absolute;
transform: translate(-50%, -50%);
pointer-events: auto;
border: 0;
border-radius: 99px;
background: rgba(248, 242, 231, 0.83);
color: var(--ink);
box-shadow: 0 5px 15px rgba(45, 38, 26, 0.12);
padding: 0;
height: 23px;
min-width: 23px;
display: flex;
align-items: center;
gap: 0;
cursor: pointer;
font-size: 9px;
font-weight: 800;
transition: 180ms ease;
}
.object-label .label-number {
width: 23px;
text-align: center;
}
.object-label .label-name {
max-width: 0;
opacity: 0;
overflow: hidden;
white-space: nowrap;
transition: 180ms ease;
}
.object-label:hover,
.object-label.selected {
background: var(--paper);
color: var(--red);
}
.object-label:hover .label-name,
.object-label.selected .label-name {
max-width: 90px;
opacity: 1;
padding-right: 10px;
}
.scene-hint {
position: absolute;
left: 25px;
bottom: 13px;
z-index: 4;
display: flex;
align-items: center;
gap: 9px;
color: rgba(41, 39, 34, 0.58);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.mouse-icon {
width: 13px;
height: 19px;
border: 1px solid currentColor;
border-radius: 7px;
position: relative;
}
.mouse-icon::after {
content: "";
position: absolute;
top: 3px;
left: 5px;
width: 1px;
height: 4px;
background: currentColor;
}
.highlight-status {
position: absolute;
right: 24px;
bottom: 13px;
z-index: 4;
color: rgba(41, 39, 34, 0.58);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.highlight-status strong {
color: var(--red);
font-weight: 800;
}
.book-shell {
position: relative;
z-index: 8;
padding: 0 30px 24px;
}
.book {
width: min(920px, 100%);
min-height: 315px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr 1fr;
position: relative;
background: #fbf7ee;
border-radius: 5px 15px 15px 5px;
box-shadow: var(--shadow), 0 2px 0 rgba(255, 255, 255, 0.6) inset;
transform: perspective(1400px) rotateX(1.2deg);
transform-origin: bottom center;
}
.book::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
background: rgba(61, 52, 40, 0.17);
box-shadow: -8px 0 16px rgba(62, 49, 32, 0.05),
8px 0 16px rgba(62, 49, 32, 0.05);
z-index: 3;
pointer-events: none;
}
.page {
min-width: 0;
padding: 23px 28px 20px;
position: relative;
}
.page:first-child {
border-radius: 5px 0 0 15px;
background:
linear-gradient(90deg, rgba(89, 65, 38, 0.035), transparent 13%),
#fbf7ee;
}
.page:last-child {
border-radius: 0 15px 15px 0;
background:
linear-gradient(-90deg, rgba(89, 65, 38, 0.035), transparent 13%),
#fbf7ee;
overflow: hidden;
}
.page:last-child::after {
content: "";
position: absolute;
right: -30px;
bottom: -42px;
width: 110px;
height: 110px;
border: 1px solid rgba(206, 89, 68, 0.14);
border-radius: 50%;
box-shadow: 0 0 0 14px rgba(206, 89, 68, 0.035),
0 0 0 29px rgba(206, 89, 68, 0.025);
pointer-events: none;
}
.page-topline {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding-bottom: 10px;
border-bottom: 1px solid var(--line);
}
.folio {
color: #aaa092;
font-family: Georgia, "Times New Roman", serif;
font-style: italic;
font-size: 10px;
}
.recipe-title {
margin: 14px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(22px, 2.5vw, 31px);
line-height: 1.02;
font-weight: 500;
letter-spacing: -0.025em;
}
.recipe-description {
margin: 0;
max-width: 45ch;
color: #6f675c;
font-family: Georgia, "Times New Roman", serif;
font-size: 12px;
line-height: 1.45;
}
.recipe-stats {
display: flex;
gap: 16px;
margin-top: 11px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.recipe-stats span {
display: flex;
align-items: center;
gap: 5px;
}
.recipe-stats span::before {
content: "";
width: 4px;
height: 4px;
border-radius: 50%;
background: var(--red);
}
.ingredients-label {
margin: 14px 0 8px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.ingredient-tokens {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.ingredient-token {
--token-color: var(--red);
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(41, 39, 34, 0.13);
border-radius: 99px;
background: rgba(255, 255, 255, 0.46);
font-size: 10px;
cursor: pointer;
transition: 150ms ease;
}
.ingredient-token::before {
content: "";
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50% 44% 52% 45%;
background: var(--token-color);
transform: rotate(-18deg);
box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.09);
}
.ingredient-token:hover,
.ingredient-token.active {
color: #fff;
background: var(--ink);
border-color: var(--ink);
transform: translateY(-1px);
}
.ingredient-token.active::before {
box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.14), 0 0 0 2px rgba(255, 255, 255, 0.2);
}
.ingredient-page.page-in {
animation: page-in 360ms cubic-bezier(0.22, 0.72, 0.25, 1);
}
@keyframes page-in {
0% {
opacity: 0.2;
transform: translateX(12px) rotateY(-4deg);
}
100% {
opacity: 1;
transform: translateX(0) rotateY(0);
}
}
.ingredient-heading {
display: grid;
grid-template-columns: 53px 1fr;
gap: 14px;
align-items: center;
margin-top: 16px;
}
.ingredient-mark {
width: 53px;
height: 53px;
display: grid;
place-items: center;
border-radius: 50% 43% 48% 45%;
background: var(--ingredient-color);
transform: rotate(-8deg);
box-shadow: inset -9px -8px 0 rgba(0, 0, 0, 0.08),
0 7px 13px rgba(60, 47, 28, 0.12);
}
.ingredient-mark::after {
content: "";
width: 12px;
height: 7px;
border-radius: 100% 0 100% 0;
background: rgba(255, 255, 255, 0.48);
transform: rotate(-25deg) translate(5px, -9px);
}
.ingredient-heading h2 {
margin: 3px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 28px;
font-weight: 500;
line-height: 1;
}
.ingredient-copy {
margin: 15px 0 13px;
color: #6d655a;
font-family: Georgia, "Times New Roman", serif;
font-size: 12px;
line-height: 1.5;
}
.ingredient-facts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 0 0 12px;
}
.fact {
padding: 9px 10px;
background: rgba(112, 90, 60, 0.055);
border: 1px solid rgba(41, 39, 34, 0.08);
border-radius: 7px;
}
.fact dt {
color: #9c9284;
font-size: 7px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.fact dd {
margin: 4px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 11px;
}
.pantry-note {
margin: 0;
padding: 10px 12px;
border-left: 2px solid var(--ingredient-color);
background: rgba(255, 255, 255, 0.34);
color: #625a50;
font-family: Georgia, "Times New Roman", serif;
font-size: 11px;
font-style: italic;
line-height: 1.4;
}
.page-controls {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 13px;
position: relative;
z-index: 2;
}
.page-arrow {
width: 27px;
height: 27px;
border: 1px solid var(--line);
border-radius: 50%;
background: transparent;
cursor: pointer;
display: grid;
place-items: center;
transition: 150ms ease;
}
.page-arrow:hover {
background: var(--ink);
color: var(--paper);
}
.amount-label {
color: #918779;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.loading {
position: absolute;
inset: 0;
display: grid;
place-items: center;
z-index: 15;
background: #d8d1c3;
color: var(--muted);
font-family: Georgia, "Times New Roman", serif;
font-size: 13px;
font-style: italic;
transition: opacity 400ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 980px) {
.main {
grid-template-columns: 275px minmax(0, 1fr);
}
.archive {
padding-inline: 14px;
}
.page {
padding-inline: 21px;
}
.book-shell {
padding-inline: 18px;
}
}
@media (max-width: 760px) {
.app {
height: auto;
min-height: 100dvh;
overflow: visible;
}
.topbar {
position: sticky;
top: 0;
height: 66px;
padding-inline: 16px;
}
.topbar-center,
.season-pill {
display: none;
}
.main {
height: auto;
display: block;
}
.archive {
padding: 17px 14px 13px;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.archive-heading {
margin-bottom: 10px;
}
.archive-heading h1 {
font-size: 23px;
}
.search-wrap {
margin-bottom: 11px;
}
.recipe-list {
display: flex;
gap: 8px;
overflow-x: auto;
overflow-y: hidden;
padding-bottom: 4px;
}
.recipe-card {
flex: 0 0 220px;
margin: 0;
background: rgba(255, 255, 255, 0.28);
}
.archive-footer {
display: none;
}
.workspace {
display: block;
overflow: visible;
}
.scene-panel {
height: 360px;
}
.book-shell {
padding: 0 10px 20px;
}
.book {
transform: none;
}
.page {
padding: 19px 17px;
}
.recipe-title {
font-size: 23px;
}
.ingredient-heading h2 {
font-size: 23px;
}
.highlight-status {
display: none;
}
}
@media (max-width: 480px) {
.brand-subtitle {
display: none;
}
.scene-panel {
height: 320px;
}
.scene-header {
left: 16px;
top: 15px;
}
.scene-tools {
top: 14px;
right: 14px;
}
.book {
grid-template-columns: 1fr;
}
.book::before {
display: none;
}
.page:first-child,
.page:last-child {
border-radius: 8px;
}
.page:last-child {
border-top: 1px solid var(--line);
}
.ingredient-heading {
margin-top: 12px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span><span></span>
</div>
<div>
<div class="brand-name">SAVOR</div>
<div class="brand-subtitle">A seasonal recipe archive</div>
</div>
</div>
<div class="topbar-center">Kitchen notes · volume one</div>
<div class="topbar-right">
<span class="archive-count">06 recipes indexed</span>
<span class="season-pill">Late summer</span>
</div>
</header>
<div class="main">
<aside class="archive">
<div class="archive-heading">
<div>
<div class="eyebrow">The pantry index</div>
<h1>Recipe archive</h1>
</div>
<div class="archive-number" id="visible-count">06</div>
</div>
<div class="search-wrap">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<circle cx="11" cy="11" r="7" stroke="currentColor" stroke-width="1.8"/>
<path d="m16.2 16.2 4 4" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
</svg>
<input id="search" type="search" placeholder="Search recipes or ingredients…" aria-label="Search recipes">
</div>
<div class="recipe-list" id="recipe-list"></div>
<div class="archive-footer">
<span>Archive № 01</span>
<span>Made by hand</span>
</div>
</aside>
<main class="workspace">
<section class="scene-panel" aria-label="Interactive low-poly kitchen">
<div id="scene"></div>
<div class="scene-header">
<div class="scene-kicker eyebrow">The test kitchen</div>
<h2>Objects in the pantry</h2>
</div>
<div class="scene-tools">
<button class="tool-button" id="reset-view" title="Reset camera" aria-label="Reset camera">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M4 10a8 8 0 1 1 1.8 7" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
<path d="M4 4v6h6" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
<div class="object-labels" id="object-labels"></div>
<div class="scene-hint">
<span class="mouse-icon"></span>
<span>Drag to orbit · Scroll to zoom</span>
</div>
<div class="highlight-status">
Kitchen match: <strong id="highlight-name">Tomato</strong>
</div>
<div class="loading" id="loading">Setting the pantry…</div>
</section>
<section class="book-shell" aria-label="Open recipe book">
<div class="book">
<article class="page recipe-page" id="recipe-page"></article>
<article class="page ingredient-page" id="ingredient-page"></article>
</div>
</section>
</main>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const ingredients = {
tomato: {
name: "Tomato",
chapter: "The red harvest",
color: "#d75a43",
description: "Sun-warmed and faintly acidic, a good tomato should smell of leaves and soil before it ever reaches the pan.",
origin: "Field-grown",
season: "August — September",
note: "Salt the cut side and wait five minutes. The juice that gathers makes a remarkably crisp, dressed tomato.",
number: "01"
},
basil: {
name: "Basil",
chapter: "The green whisper",
color: "#6e8058",
description: "Peppery, floral, and tender. Basil carries the unmistakable fragrance of warm weather and fast meals.",
origin: "Tender herb",
season: "June — October",
note: "Tear the leaves instead of chopping them. Bruised basil bruises more of its aromatic oils into the dish.",
number: "02"
},
garlic: {
name: "Garlic",
chapter: "The aromatic root",
color: "#d7c7aa",
description: "Raw garlic is sharp and sweet; cooked slowly it becomes round, mellow, and deeply savory.",
origin: "Cured bulb",
season: "Stored year-round",
note: "Slice the cloves thinly. They turn silky and nutty in warm oil long before the rest of the dish is ready.",
number: "03"
},
bread: {
name: "Sourdough",
chapter: "The slow loaf",
color: "#b77a43",
description: "Tangy, open-crumbed, and better the day after baking. Its sturdy crust is made for holding generous toppings.",
origin: "Naturally leavened",
season: "Bake year-round",
note: "Toast a thick slice until the edges are deeply colored. The result is a crisp bed for soft summer produce.",
number: "04"
},
butter: {
name: "Butter",
chapter: "The golden dairy",
color: "#e2b94f",
description: "A simple ingredient with a wide range of personalities, from soft and creamy to brown and nutty.",
origin: "Cultured cream",
season: "Churned year-round",
note: "Watch the milk solids rather than the clock. The butter is ready when the foam subsides and the solids smell toasted.",
number: "05"
},
egg: {
name: "Egg",
chapter: "The binding beginning",
color: "#e8d5ae",
description: "Rich, mild, and endlessly useful. Eggs give structure to a pastry and velvet to a sauce.",
origin: "Free-range hen",
season: "Collected year-round",
note: "Bring eggs to room temperature before folding them into batter. A warmer egg emulsifies more smoothly.",
number: "06"
},
flour: {
name: "Flour",
chapter: "The quiet foundation",
color: "#d7b783",
description: "A fine, powdery building block with endless uses, from tender cakes to crisp-edged morning buns.",
origin: "Stone-ground wheat",
season: "Milled year-round",
note: "Sift only when the recipe asks. A little remaining wheatiness gives rustic bread and pastry a deeper character.",
number: "07"
},
lemon: {
name: "Lemon",
chapter: "The bright keeper",
color: "#dfc744",
description: "Sharp, fragrant, and cleansing. Lemon lifts heavy dishes and makes simple ingredients taste newly awake.",
origin: "Citrus grove",
season: "Winter — Spring",
note: "Zest before juicing. The aromatic oils in the skin carry more character than the juice alone.",
number: "08"
}
};
const recipes = [
{
id: "tomato-toast",
number: "01",
title: "Tomato & Basil Toast",
subtitle: "A late-summer lunch on thick sourdough.",
description: "Warm bread rubbed with garlic, piled with ripe tomatoes, and finished with basil and the best oil you have.",
time: "25 min",
level: "Easy",
ingredients: [
{ id: "bread", amount: "2 thick slices" },
{ id: "tomato", amount: "2 ripe tomatoes" },
{ id: "basil", amount: "1 small handful" },
{ id: "garlic", amount: "1 clove" }
]
},
{
id: "brown-butter-bun",
number: "02",
title: "Brown Butter Morning Bun",
subtitle: "A flaky spiral with toasted butter and citrus.",
description: "Laminated pastry, rolled around brown butter and orange sugar, then baked until the edges caramelize.",
time: "3 hr",
level: "Project",
ingredients: [
{ id: "butter", amount: "115 g" },
{ id: "flour", amount: "300 g" },
{ id: "egg", amount: "1 large egg" },
{ id: "lemon", amount: "1 lemon zest" }
]
},
{
id: "lemon-ricotta-cake",
number: "03",
title: "Lemon Ricotta Cake",
subtitle: "A pale, tender cake scented with citrus.",
description: "Whipped ricotta gives this simple cake a cloud-like crumb, while lemon keeps every bite bright.",
time: "65 min",
level: "Relaxed",
ingredients: [
{ id: "lemon", amount: "2 lemons" },
{ id: "egg", amount: "4 large eggs" },
{ id: "flour", amount: "180 g" }
]
},
{
id: "white-bean-broth",
number: "04",
title: "Garlic White Bean Broth",
subtitle: "A small supper with a savory depth.",
description: "Creamy beans, slowly cooked garlic, and ripe tomatoes make a broth that feels far more elaborate than it is.",
time: "40 min",
level: "Easy",
ingredients: [
{ id: "garlic", amount: "5 cloves" },
{ id: "tomato", amount: "2 ripe tomatoes" },
{ id: "basil", amount: "8 leaves" }
]
},
{
id: "garden-egg-puffs",
number: "05",
title: "Garden Egg Puffs",
subtitle: "Flaky pastry, soft egg, and sharp herbs.",
description: "Tiny parcels of scrambled egg and herbs baked until the pastry is crisp and the filling remains tender.",
time: "45 min",
level: "Weekend",
ingredients: [
{ id: "egg", amount: "3 large eggs" },
{ id: "basil", amount: "1 handful" },
{ id: "flour", amount: "220 g" }
]
},
{
id: "lemon-garlic-pasta",
number: "06",
title: "Lemon Garlic Pasta",
subtitle: "A pantry dinner in less than half an hour.",
description: "Silky garlic, lemon, and pasta water make a quick sauce that tastes as though it simmered all afternoon.",
time: "20 min",
level: "Quick",
ingredients: [
{ id: "garlic", amount: "4 cloves" },
{ id: "lemon", amount: "1 lemon" },
{ id: "flour", amount: "200 g" }
]
}
];
const state = {
recipeId: recipes[0].id,
ingredientId: recipes[0].ingredients[0].id
};
const recipeList = document.querySelector("#recipe-list");
const recipePage = document.querySelector("#recipe-page");
const ingredientPage = document.querySelector("#ingredient-page");
const search = document.querySelector("#search");
const visibleCount = document.querySelector("#visible-count");
const highlightName = document.querySelector("#highlight-name");
function renderArchive() {
const query = search.value.trim().toLowerCase();
const filtered = recipes.filter((recipe) => {
const ingredientNames = recipe.ingredients
.map((item) => ingredients[item.id].name)
.join(" ");
return `${recipe.title} ${recipe.description} ${ingredientNames}`
.toLowerCase()
.includes(query);
});
visibleCount.textContent = String(filtered.length).padStart(2, "0");
recipeList.innerHTML = filtered.map((recipe) => `
<button class="recipe-card ${recipe.id === state.recipeId ? "active" : ""}"
data-recipe="${recipe.id}">
<span class="recipe-number">${recipe.number}</span>
<span>
<h3>${recipe.title}</h3>
<span class="recipe-meta">
<span>${recipe.time}</span>
<span>·</span>
<span>${recipe.level}</span>
</span>
<span class="ingredient-dots" aria-hidden="true">
${recipe.ingredients
.map((item) => `<i style="background:${ingredients[item.id].color}"></i>`)
.join("")}
</span>
</span>
</button>
`).join("");
}
function renderRecipePage() {
const recipe = recipes.find((item) => item.id === state.recipeId);
recipePage.innerHTML = `
<div class="page-topline">
<span class="eyebrow">Recipe folio № ${recipe.number}</span>
<span class="folio">from the kitchen notebook</span>
</div>
<h2 class="recipe-title">${recipe.title}</h2>
<p class="recipe-description">${recipe.description}</p>
<div class="recipe-stats">
<span>${recipe.time}</span>
<span>${recipe.level}</span>
<span>Serves 2—4</span>
</div>
<div class="ingredients-label">Ingredients · select to open a page</div>
<div class="ingredient-tokens">
${recipe.ingredients.map((item) => `
<button class="ingredient-token ${item.id === state.ingredientId ? "active" : ""}"
data-ingredient="${item.id}"
style="--token-color:${ingredients[item.id].color}"
aria-pressed="${item.id === state.ingredientId}">
${ingredients[item.id].name}
</button>
`).join("")}
</div>
`;
}
function renderIngredientPage(animate = false) {
const recipe = recipes.find((item) => item.id === state.recipeId);
const item = recipe.ingredients.find((entry) => entry.id === state.ingredientId);
const ingredient = ingredients[state.ingredientId];
const index = recipe.ingredients.findIndex((entry) => entry.id === state.ingredientId);
ingredientPage.style.setProperty("--ingredient-color", ingredient.color);
ingredientPage.innerHTML = `
<div class="page-topline">
<span class="eyebrow">Ingredient folio ${ingredient.number}</span>
<span class="folio">${ingredient.chapter}</span>
</div>
<div class="ingredient-heading">
<div class="ingredient-mark" aria-hidden="true"></div>
<div>
<div class="eyebrow">Pantry reference</div>
<h2>${ingredient.name}</h2>
</div>
</div>
<p class="ingredient-copy">${ingredient.description}</p>
<dl class="ingredient-facts">
<div class="fact">
<dt>Source</dt>
<dd>${ingredient.origin}</dd>
</div>
<div class="fact">
<dt>At its best</dt>
<dd>${ingredient.season}</dd>
</div>
</dl>
<blockquote class="pantry-note">${ingredient.note}</blockquote>
<div class="page-controls">
<button class="page-arrow" data-direction="-1" aria-label="Previous ingredient">←</button>
<span class="amount-label">In this recipe · ${item.amount}</span>
<button class="page-arrow" data-direction="1" aria-label="Next ingredient">→</button>
</div>
`;
if (animate) {
ingredientPage.classList.remove("page-in");
void ingredientPage.offsetWidth;
ingredientPage.classList.add("page-in");
}
}
function openRecipe(recipeId, ingredientId = null) {
const recipe = recipes.find((item) => item.id === recipeId);
if (!recipe) return;
state.recipeId = recipeId;
state.ingredientId = ingredientId || recipe.ingredients[0].id;
renderArchive();
renderRecipePage();
renderIngredientPage(true);
highlightIngredient(state.ingredientId);
}
function selectIngredient(ingredientId) {
const recipe = recipes.find((item) => item.id === state.recipeId);
if (!recipe.ingredients.some((item) => item.id === ingredientId)) return;
state.ingredientId = ingredientId;
document.querySelectorAll(".ingredient-token").forEach((token) => {
const active = token.dataset.ingredient === ingredientId;
token.classList.toggle("active", active);
token.setAttribute("aria-pressed", String(active));
});
renderIngredientPage(true);
highlightIngredient(ingredientId);
}
recipeList.addEventListener("click", (event) => {
const card = event.target.closest("[data-recipe]");
if (card) openRecipe(card.dataset.recipe);
});
recipePage.addEventListener("click", (event) => {
const token = event.target.closest("[data-ingredient]");
if (token) selectIngredient(token.dataset.ingredient);
});
ingredientPage.addEventListener("click", (event) => {
const button = event.target.closest("[data-direction]");
if (!button) return;
const recipe = recipes.find((item) => item.id === state.recipeId);
const currentIndex = recipe.ingredients.findIndex((item) => item.id === state.ingredientId);
const direction = Number(button.dataset.direction);
const nextIndex =
(currentIndex + direction + recipe.ingredients.length) % recipe.ingredients.length;
selectIngredient(recipe.ingredients[nextIndex].id);
});
search.addEventListener("input", renderArchive);
renderArchive();
renderRecipePage();
renderIngredientPage();
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const labelsHost = document.querySelector("#object-labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#d8d1c3");
scene.fog = new THREE.Fog("#d8d1c3", 12, 22);
const camera = new THREE.PerspectiveCamera(37, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight("#fff3d9", "#6d7569", 2.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff1d4", 3.2);
sun.position.set(4.5, 7.5, 5.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -7;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9c7c3", 1.25);
fill.position.set(-5, 3, 2);
scene.add(fill);
const warmPoint = new THREE.PointLight("#ffd5a0", 11, 10, 2);
warmPoint.position.set(-4, 3.5, 1);
scene.add(warmPoint);
const materials = [];
function standardMaterial(color, options = {}) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.8,
metalness: 0,
flatShading: true,
...options
});
materials.push(material);
return material;
}
function addMesh(group, geometry, material, position = [0, 0, 0], scale = [1, 1, 1]) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.scale.set(...scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
const counterMaterial = standardMaterial("#b89062", { roughness: 0.9 });
const counterEdgeMaterial = standardMaterial("#8c6949");
const boardMaterial = standardMaterial("#c59a68");
const boardEdgeMaterial = standardMaterial("#9a7047");
const wallMaterial = standardMaterial("#d2cbbb", { roughness: 1 });
const counter = new THREE.Group();
addMesh(counter, new THREE.BoxGeometry(9.2, 0.34, 6.2), counterEdgeMaterial, [0, -1.13, 0]);
addMesh(counter, new THREE.BoxGeometry(9.25, 0.12, 6.25), counterMaterial, [0, -0.91, 0]);
scene.add(counter);
const backsplash = addMesh(
scene,
new THREE.BoxGeometry(9.5, 4.8, 0.18),
wallMaterial,
[0, 0.45, -3.25]
);
backsplash.castShadow = false;
const shelf = addMesh(
scene,
new THREE.BoxGeometry(7.2, 0.12, 0.7),
standardMaterial("#a9845d"),
[-0.4, 1.25, -2.82]
);
shelf.castShadow = true;
const board = new THREE.Group();
addMesh(board, new THREE.CylinderGeometry(2.35, 2.42, 0.13, 14), boardEdgeMaterial, [0, -0.77, 0.25]);
addMesh(board, new THREE.CylinderGeometry(2.29, 2.29, 0.08, 14), boardMaterial, [0, -0.68, 0.25]);
scene.add(board);
const ingredientObjects = new Map();
const pickMeshes = [];
const objectLabels = [];
function registerIngredient(id, group, anchor, radius = 0.8) {
group.userData.ingredientId = id;
group.userData.anchor = anchor;
group.userData.radius = radius;
const meshes = [];
group.traverse((child) => {
if (!child.isMesh) return;
child.userData.ingredientId = id;
meshes.push(child);
pickMeshes.push(child);
});
ingredientObjects.set(id, { group, meshes });
const label = document.createElement("button");
label.className = "object-label";
label.type = "button";
label.setAttribute("aria-label", `Open ${ingredients[id].name} page`);
label.innerHTML = `
<span class="label-number">${ingredients[id].number}</span>
<span class="label-name">${ingredients[id].name}</span>
`;
label.addEventListener("click", () => selectIngredient(id));
labelsHost.appendChild(label);
objectLabels.push({ id, element: label, anchor: anchor.clone() });
}
// Tomato
{
const group = new THREE.Group();
group.position.set(-2.25, -0.62, 0.85);
const tomatoMaterial = standardMaterial("#d6533e", { roughness: 0.62 });
const greenMaterial = standardMaterial("#61734d");
addMesh(group, new THREE.IcosahedronGeometry(0.56, 2), tomatoMaterial, [0, 0.52, 0]);
addMesh(group, new THREE.CylinderGeometry(0.035, 0.05, 0.18, 5), greenMaterial, [0, 1.08, 0]);
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const leaf = addMesh(
group,
new THREE.ConeGeometry(0.13, 0.34, 4),
greenMaterial,
[Math.cos(angle) * 0.16, 1.02, Math.sin(angle) * 0.16]
);
leaf.rotation.z = Math.PI / 2.5;
leaf.rotation.y = -angle;
}
scene.add(group);
registerIngredient("tomato", group, new THREE.Vector3(0, 1.3, 0), 0.85);
}
// Basil
{
const group = new THREE.Group();
group.position.set(-0.55, -0.62, 1.25);
const stemMaterial = standardMaterial("#526541");
const leafMaterial = standardMaterial("#71885a", { roughness: 0.9 });
for (let i = 0; i < 5; i++) {
const x = (i - 2) * 0.13;
const height = 0.75 + (i % 2) * 0.22;
const stem = addMesh(
group,
new THREE.CylinderGeometry(0.018, 0.027, height, 5),
stemMaterial,
[x, height / 2, (i % 2) * 0.06]
);
stem.rotation.z = (i - 2) * 0.07;
for (let j = 0; j < 2; j++) {
const leaf = addMesh(
group,
new THREE.IcosahedronGeometry(0.29, 1),
leafMaterial,
[x + (j ? 0.18 : -0.18), height * (0.52 + j * 0.2), 0],
[0.75, 1.35, 0.22]
);
leaf.rotation.z = j ? -0.58 : 0.58;
leaf.rotation.y = j * 0.7;
}
}
scene.add(group);
registerIngredient("basil", group, new THREE.Vector3(0, 1.18, 0), 0.78);
}
// Garlic
{
const group = new THREE.Group();
group.position.set(0.3, -0.61, -0.35);
const garlicMaterial = standardMaterial("#ddd0b8", { roughness: 0.95 });
const stemMaterial = standardMaterial("#a68d64");
const bulb = addMesh(
group,
new THREE.IcosahedronGeometry(0.47, 1),
garlicMaterial,
[0, 0.38, 0],
[0.95, 1.08, 0.95]
);
bulb.rotation.y = 0.35;
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const clove = addMesh(
group,
new THREE.IcosahedronGeometry(0.23, 1),
garlicMaterial,
[Math.cos(angle) * 0.22, 0.33, Math.sin(angle) * 0.22],
[0.75, 1.35, 0.75]
);
clove.rotation.y = -angle;
}
addMesh(group, new THREE.CylinderGeometry(0.035, 0.06, 0.2, 6), stemMaterial, [0, 0.8, 0]);
scene.add(group);
registerIngredient("garlic", group, new THREE.Vector3(0, 1.02, 0), 0.7);
}
// Sourdough
{
const group = new THREE.Group();
group.position.set(1.65, -0.61, 1.05);
const crustMaterial = standardMaterial("#b8753c", { roughness: 0.95 });
const crumbMaterial = standardMaterial("#d5aa71");
addMesh(
group,
new THREE.SphereGeometry(0.52, 10, 6),
crustMaterial,
[0, 0.4, 0],
[1.35, 0.78, 0.95]
);
const cut = addMesh(
group,
new THREE.SphereGeometry(0.46, 10, 6),
crumbMaterial,
[0.22, 0.46, 0.18],
[0.75, 0.72, 0.78]
);
cut.rotation.z = -0.4;
scene.add(group);
registerIngredient("bread", group, new THREE.Vector3(0, 0.95, 0), 0.86);
}
// Butter
{
const group = new THREE.Group();
group.position.set(3.05, -0.62, 0.15);
const butterMaterial = standardMaterial("#e5b943", { roughness: 0.68 });
const wrapperMaterial = standardMaterial("#eee5cc");
addMesh(group, new THREE.BoxGeometry(0.92, 0.43, 0.62), butterMaterial, [0, 0.27, 0]);
addMesh(group, new THREE.BoxGeometry(0.98, 0.12, 0.66), wrapperMaterial, [0, 0.11, 0]);
addMesh(group, new THREE.BoxGeometry(0.22, 0.16, 0.68), wrapperMaterial, [0, 0.27, 0]);
addMesh(group, new THREE.BoxGeometry(0.98, 0.43, 0.12), wrapperMaterial, [0, 0.27, 0.33]);
scene.add(group);
registerIngredient("butter", group, new THREE.Vector3(0, 0.78, 0), 0.72);
}
// Egg and bowl
{
const group = new THREE.Group();
group.position.set(0.95, -0.62, -1.35);
const bowlMaterial = standardMaterial("#8ea2a0", { roughness: 0.72 });
const eggMaterial = standardMaterial("#ead9b7", { roughness: 0.62 });
addMesh(group, new THREE.CylinderGeometry(0.57, 0.38, 0.27, 12, 1, true), bowlMaterial, [0, 0.17, 0]);
addMesh(group, new THREE.CylinderGeometry(0.38, 0.38, 0.04, 12), bowlMaterial, [0, 0.04, 0]);
const egg1 = addMesh(group, new THREE.IcosahedronGeometry(0.28, 2), eggMaterial, [-0.13, 0.39, 0]);
egg1.scale.set(0.82, 1.2, 0.82);
egg1.rotation.z = -0.28;
const egg2 = addMesh(group, new THREE.IcosahedronGeometry(0.27, 2), eggMaterial, [0.17, 0.36, 0.06]);
egg2.scale.set(0.82, 1.18, 0.82);
egg2.rotation.z = 0.38;
scene.add(group);
registerIngredient("egg", group, new THREE.Vector3(0, 0.95, 0), 0.78);
}
// Flour sack
{
const group = new THREE.Group();
group.position.set(-2.65, -0.62, -1.35);
const sackMaterial = standardMaterial("#d7ba86", { roughness: 1 });
const tieMaterial = standardMaterial("#9c7552");
const labelMaterial = standardMaterial("#eee2c9");
addMesh(group, new THREE.CylinderGeometry(0.42, 0.59, 1.02, 8), sackMaterial, [0, 0.53, 0]);
addMesh(group, new THREE.CylinderGeometry(0.18, 0.3, 0.28, 7), sackMaterial, [0, 1.1, 0]);
addMesh(group, new THREE.TorusGeometry(0.22, 0.035, 5, 10), tieMaterial, [0, 1.0, 0]);
addMesh(group, new THREE.BoxGeometry(0.5, 0.34, 0.035), labelMaterial, [0, 0.55, 0.56]);
const mark = addMesh(group, new THREE.BoxGeometry(0.22, 0.055, 0.02), tieMaterial, [0, 0.57, 0.59]);
mark.rotation.z = -0.08;
scene.add(group);
registerIngredient("flour", group, new THREE.Vector3(0, 1.5, 0), 0.8);
}
// Lemon
{
const group = new THREE.Group();
group.position.set(2.85, -0.61, -1.45);
const lemonMaterial = standardMaterial("#dbc43e", { roughness: 0.75 });
const leafMaterial = standardMaterial("#66794f");
addMesh(group, new THREE.IcosahedronGeometry(0.47, 1), lemonMaterial, [0, 0.42, 0], [1.25, 0.9, 0.85]);
addMesh(group, new THREE.ConeGeometry(0.06, 0.16, 5), lemonMaterial, [-0.52, 0.42, 0]);
addMesh(group, new THREE.ConeGeometry(0.06, 0.16, 5), lemonMaterial, [0.52, 0.42, 0]);
const leaf = addMesh(group, new THREE.IcosahedronGeometry(0.19, 1), leafMaterial, [0.08, 0.76, 0]);
leaf.scale.set(0.65, 1.3, 0.18);
leaf.rotation.z = -0.6;
scene.add(group);
registerIngredient("lemon", group, new THREE.Vector3(0, 0.94, 0), 0.75);
}
// Decorative jars on the shelf
{
const jarGroup = new THREE.Group();
const jarMaterial = standardMaterial("#87998c");
const lidMaterial = standardMaterial("#745c44");
for (let i = 0; i < 4; i++) {
const x = -2.5 + i * 0.72;
const height = 0.45 + (i % 2) * 0.16;
addMesh(
jarGroup,
new THREE.CylinderGeometry(0.18, 0.22, height, 8),
jarMaterial,
[x, 1.34 + height / 2, -2.8]
);
addMesh(
jarGroup,
new THREE.CylinderGeometry(0.2, 0.2, 0.07, 8),
lidMaterial,
[x, 1.37 + height, -2.8]
);
}
scene.add(jarGroup);
}
const highlightRing = new THREE.Mesh(
new THREE.TorusGeometry(0.8, 0.026, 6, 48),
new THREE.MeshBasicMaterial({
color: "#ce5944",
transparent: true,
opacity: 0.85,
depthWrite: false
})
);
highlightRing.rotation.x = Math.PI / 2;
highlightRing.position.y = -0.53;
scene.add(highlightRing);
let selectedIngredientId = null;
function highlightIngredient(id) {
selectedIngredientId = id;
const ingredient = ingredients[id];
highlightName.textContent = ingredient.name;
highlightRing.material.color.set(ingredient.color);
for (const object of ingredientObjects.values()) {
for (const mesh of object.meshes) {
mesh.material.emissive.set(ingredient.color);
}
}
for (const label of objectLabels) {
label.element.classList.toggle("selected", label.id === id);
}
}
highlightIngredient(state.ingredientId);
// -------------------------------------------------------------------------
// Direct camera controls: orbit by dragging, zoom with wheel.
// -------------------------------------------------------------------------
const target = new THREE.Vector3(0, -0.05, 0);
const spherical = new THREE.Spherical(10.2, 1.08, 0.42);
const initialSpherical = spherical.clone();
let pointerDown = false;
let pointerMoved = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.68, 1.42);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 7.3, 13.5);
spherical.makeSafe();
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
function resetCamera() {
spherical.copy(initialSpherical);
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.004;
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerDown = false;
if (!pointerMoved) {
const rect = renderer.domElement.getBoundingClientRect();
const pointer = new THREE.Vector2(
((event.clientX - rect.left) / rect.width) * 2 - 1,
-((event.clientY - rect.top) / rect.height) * 2 + 1
);
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(pickMeshes, false)[0];
if (hit?.object.userData.ingredientId) {
selectIngredient(hit.object.userData.ingredientId);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius += event.deltaY * 0.007;
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.querySelector("#reset-view").addEventListener("click", resetCamera);
const resizeObserver = new ResizeObserver(() => {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
updateCamera();
});
resizeObserver.observe(sceneHost);
const projected = new THREE.Vector3();
function updateLabels() {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
for (const label of objectLabels) {
const object = ingredientObjects.get(label.id);
projected.copy(label.anchor);
object.group.localToWorld(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.display = visible ? "flex" : "none";
if (visible) {
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const selected = ingredientObjects.get(selectedIngredientId);
for (const [id, object] of ingredientObjects) {
const color = ingredients[id].color;
const targetIntensity =
id === selectedIngredientId
? 0.36 + Math.sin(elapsed * 3.2) * 0.09
: 0;
for (const mesh of object.meshes) {
mesh.material.emissiveIntensity +=
(targetIntensity - mesh.material.emissiveIntensity) * 0.1;
}
}
if (selected) {
highlightRing.position.x = selected.group.position.x;
highlightRing.position.z = selected.group.position.z;
const baseScale = selected.group.userData.radius / 0.8;
const pulse = baseScale * (1 + Math.sin(elapsed * 2.5) * 0.035);
highlightRing.scale.setScalar(pulse);
highlightRing.material.opacity = 0.65 + Math.sin(elapsed * 2.5) * 0.17;
}
updateLabels();
renderer.render(scene, camera);
}
updateCamera();
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```